diff --git a/misc/UWP/Window_UWP.cpp b/misc/UWP/Window_UWP.cpp index ba942199e..6fe90de4f 100644 --- a/misc/UWP/Window_UWP.cpp +++ b/misc/UWP/Window_UWP.cpp @@ -215,7 +215,7 @@ void Window_AllocFramebuffer(struct Bitmap* bmp, int width, int height) { bmp->height = height; if (!Gfx.Created) Gfx_Create(); - fb_tex = Gfx_CreateTexture(bmp, TEXTURE_FLAG_NONPOW2, false); + fb_tex = Gfx_AllocTexture(bmp, bmp->width, TEXTURE_FLAG_NONPOW2, false); AllocateVB(); Game.Width = Window_Main.Width; diff --git a/src/Graphics.h b/src/Graphics.h index 08fe488e3..db24953ff 100644 --- a/src/Graphics.h +++ b/src/Graphics.h @@ -121,6 +121,8 @@ cc_bool Gfx_CheckTextureSize(int width, int height, cc_uint8 flags); use mipmapping may be either a per-texture or global state depending on the backend */ CC_API GfxResourceID Gfx_CreateTexture(struct Bitmap* bmp, cc_uint8 flags, cc_bool mipmaps); GfxResourceID Gfx_CreateTexture2(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, cc_bool mipmaps); +/* NOTE: Should not be used directly, use Gfx_CreateTexture or Gfx_CreateTexture2 instead */ +GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, cc_bool mipmaps); /* Updates a region of the given texture. (and mipmapped regions if mipmaps) */ CC_API void Gfx_UpdateTexturePart(GfxResourceID texId, int x, int y, struct Bitmap* part, cc_bool mipmaps); /* Updates a region of the given texture. (and mipmapped regions if mipmaps) */ diff --git a/src/Graphics_3DS.c b/src/Graphics_3DS.c index 7424de81c..e72cd1b84 100644 --- a/src/Graphics_3DS.c +++ b/src/Graphics_3DS.c @@ -418,7 +418,7 @@ static void ToMortonTexture(C3D_Tex* tex, int originX, int originY, } -static GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, cc_bool mipmaps) { +GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, cc_bool mipmaps) { struct GPUTexture* tex = GPUTexture_Alloc(); bool success = CreateNativeTexture(&tex->texture, bmp->width, bmp->height); if (!success) return NULL; diff --git a/src/Graphics_D3D11.c b/src/Graphics_D3D11.c index c87203e29..a263dbd05 100644 --- a/src/Graphics_D3D11.c +++ b/src/Graphics_D3D11.c @@ -186,7 +186,6 @@ void Gfx_Create(void) { Gfx.Created = true; Gfx.BackendType = CC_GFX_BACKEND_D3D11; - Gfx.SupportsNonPowTwoTextures = true; customMipmapsLevels = true; Gfx_RestoreState(); } @@ -284,7 +283,7 @@ static void D3D11_DoMipmaps(ID3D11Resource* texture, int x, int y, struct Bitmap if (prev != bmp->scan0) Mem_Free(prev); } -static GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, cc_bool mipmaps) { +GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, cc_bool mipmaps) { ID3D11Texture2D* tex = NULL; ID3D11ShaderResourceView* view = NULL; HRESULT hr; diff --git a/src/Graphics_D3D9.c b/src/Graphics_D3D9.c index ff492acb6..cb65e2e9d 100644 --- a/src/Graphics_D3D9.c +++ b/src/Graphics_D3D9.c @@ -328,7 +328,7 @@ static IDirect3DTexture9* DoCreateTexture(struct Bitmap* bmp, int levels, int po return tex; } -static GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, cc_bool mipmaps) { +GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, cc_bool mipmaps) { IDirect3DTexture9* tex; IDirect3DTexture9* sys; cc_result res; diff --git a/src/Graphics_Dreamcast.c b/src/Graphics_Dreamcast.c index e31b84ff0..abb76d89c 100644 --- a/src/Graphics_Dreamcast.c +++ b/src/Graphics_Dreamcast.c @@ -541,7 +541,7 @@ static TextureObject* FindFreeTexture(void) { return NULL; } -static GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, cc_bool mipmaps) { +GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, cc_bool mipmaps) { TextureObject* tex = FindFreeTexture(); if (!tex) return NULL; diff --git a/src/Graphics_GCWii.c b/src/Graphics_GCWii.c index 688687025..f708963cb 100644 --- a/src/Graphics_GCWii.c +++ b/src/Graphics_GCWii.c @@ -145,7 +145,7 @@ static void ReorderPixels(CCTexture* tex, struct Bitmap* bmp, } } -static GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, cc_bool mipmaps) { +GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, cc_bool mipmaps) { int size = bmp->width * bmp->height * 4; CCTexture* tex = (CCTexture*)memalign(32, 32 + size); if (!tex) return NULL; diff --git a/src/Graphics_N64.c b/src/Graphics_N64.c index f4c994b20..3bed453bc 100644 --- a/src/Graphics_N64.c +++ b/src/Graphics_N64.c @@ -133,7 +133,7 @@ typedef struct CCTexture { #define To16BitPixel(src) \ ((src & 0x80) >> 7) | ((src & 0xF800) >> 10) | ((src & 0xF80000) >> 13) | ((src & 0xF8000000) >> 16); -static GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, cc_bool mipmaps) { +GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, cc_bool mipmaps) { cc_bool bit16 = flags & TEXTURE_FLAG_LOWRES; // rows are actually 8 byte aligned in TMEM https://github.com/DragonMinded/libdragon/blob/f360fa1bb1fb3ff3d98f4ab58692d40c828636c9/src/rdpq/rdpq_tex.c#L132 // so even though width * height * pixel size may fit within 4096 bytes, after adjusting for 8 byte alignment, row pitch * height may exceed 4096 bytes diff --git a/src/Graphics_NDS.c b/src/Graphics_NDS.c index 7587eb91a..542368159 100644 --- a/src/Graphics_NDS.c +++ b/src/Graphics_NDS.c @@ -101,7 +101,7 @@ void Gfx_EndFrame(void) { *#########################################################################################################################*/ static int tex_width, tex_height; -static GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, cc_bool mipmaps) { +GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, cc_bool mipmaps) { vramSetBankA(VRAM_A_TEXTURE); cc_uint16* tmp = Mem_TryAlloc(bmp->width * bmp->height, 2); diff --git a/src/Graphics_PS1.c b/src/Graphics_PS1.c index 1ba39a26d..bc4847ee3 100644 --- a/src/Graphics_PS1.c +++ b/src/Graphics_PS1.c @@ -272,7 +272,7 @@ static void* AllocTextureAt(int i, struct Bitmap* bmp, int rowWidth) { return tex; } -static GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, cc_bool mipmaps) { +GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, cc_bool mipmaps) { for (int i = 0; i < TEXTURES_MAX_COUNT; i++) { if (textures[i].width) continue; diff --git a/src/Graphics_PS2.c b/src/Graphics_PS2.c index 80f0b124a..be9ac35ac 100644 --- a/src/Graphics_PS2.c +++ b/src/Graphics_PS2.c @@ -166,7 +166,7 @@ typedef struct CCTexture_ { BitmapCol pixels[]; // aligned to 64 bytes (only need 16?) } CCTexture; -static GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, cc_bool mipmaps) { +GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, cc_bool mipmaps) { int size = bmp->width * bmp->height * 4; CCTexture* tex = (CCTexture*)memalign(16, 64 + size); diff --git a/src/Graphics_PS3.c b/src/Graphics_PS3.c index 57039e489..416478870 100644 --- a/src/Graphics_PS3.c +++ b/src/Graphics_PS3.c @@ -581,7 +581,7 @@ typedef struct CCTexture_ { cc_uint32 pixels[]; } CCTexture; -static GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, cc_bool mipmaps) { +GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, cc_bool mipmaps) { int size = bmp->width * bmp->height * 4; CCTexture* tex = (CCTexture*)rsxMemalign(128, 128 + size); diff --git a/src/Graphics_PSP.c b/src/Graphics_PSP.c index d1d75f34e..a9d8f793b 100644 --- a/src/Graphics_PSP.c +++ b/src/Graphics_PSP.c @@ -114,7 +114,7 @@ typedef struct CCTexture_ { BitmapCol pixels[]; } CCTexture; -static GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, cc_bool mipmaps) { +GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, cc_bool mipmaps) { int size = bmp->width * bmp->height * 4; CCTexture* tex = (CCTexture*)memalign(16, 16 + size); diff --git a/src/Graphics_PSVita.c b/src/Graphics_PSVita.c index 21c403a32..11a980858 100644 --- a/src/Graphics_PSVita.c +++ b/src/Graphics_PSVita.c @@ -679,7 +679,7 @@ static void GPUTextures_DeleteUnreferenced(void) { /*########################################################################################################################* *---------------------------------------------------------Textures--------------------------------------------------------* *#########################################################################################################################*/ -static GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, cc_bool mipmaps) { +GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, cc_bool mipmaps) { int size = bmp->width * bmp->height * 4; struct GPUTexture* tex = GPUTexture_Alloc(size); CopyTextureData(tex->data, bmp->width * BITMAPCOLOR_SIZE, diff --git a/src/Graphics_Saturn.c b/src/Graphics_Saturn.c index 1012861d6..fac6b5b0a 100644 --- a/src/Graphics_Saturn.c +++ b/src/Graphics_Saturn.c @@ -117,7 +117,7 @@ typedef struct CCTexture { void* addr; } CCTexture; -static GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, cc_bool mipmaps) { +GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, cc_bool mipmaps) { CCTexture* tex = Mem_TryAlloc(1, sizeof(CCTexture)); if (!tex) return NULL; diff --git a/src/Graphics_SoftGPU.c b/src/Graphics_SoftGPU.c index 8d625df6e..ebac1e940 100644 --- a/src/Graphics_SoftGPU.c +++ b/src/Graphics_SoftGPU.c @@ -94,7 +94,7 @@ void Gfx_DeleteTexture(GfxResourceID* texId) { *texId = NULL; } -static GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, cc_bool mipmaps) { +GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, cc_bool mipmaps) { CCTexture* tex = (CCTexture*)Mem_Alloc(2 + bmp->width * bmp->height, 4, "Texture"); tex->width = bmp->width; diff --git a/src/Graphics_WiiU.c b/src/Graphics_WiiU.c index bb142cbd4..106cb066e 100644 --- a/src/Graphics_WiiU.c +++ b/src/Graphics_WiiU.c @@ -84,7 +84,7 @@ static void Gfx_RestoreState(void) { *#########################################################################################################################*/ static GX2Texture* pendingTex; -static GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, cc_bool mipmaps) { +GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, cc_bool mipmaps) { GX2Texture* tex = Mem_TryAllocCleared(1, sizeof(GX2Texture)); if (!tex) return NULL; diff --git a/src/Graphics_Xbox.c b/src/Graphics_Xbox.c index c39370a99..7c40191fc 100644 --- a/src/Graphics_Xbox.c +++ b/src/Graphics_Xbox.c @@ -195,7 +195,7 @@ static void ConvertTexture(cc_uint32* dst, struct Bitmap* bmp, int rowWidth) { } } -static GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, cc_bool mipmaps) { +GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, cc_bool mipmaps) { int size = bmp->width * bmp->height * 4; CCTexture* tex = Mem_Alloc(1, sizeof(CCTexture), "GPU texture"); tex->pixels = MmAllocateContiguousMemoryEx(size, 0, MAX_RAM_ADDR, 0, PAGE_WRITECOMBINE | PAGE_READWRITE); diff --git a/src/Graphics_Xbox360.c b/src/Graphics_Xbox360.c index 5f8863a21..22e300f9d 100644 --- a/src/Graphics_Xbox360.c +++ b/src/Graphics_Xbox360.c @@ -102,7 +102,7 @@ static void SetTextureData(struct XenosSurface* xtex, int x, int y, const struct Xe_Surface_Unlock(xe, xtex); } -static GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, cc_bool mipmaps) { +GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, cc_bool mipmaps) { struct XenosSurface* xtex = Xe_CreateTexture(xe, bmp->width, bmp->height, 1, XE_FMT_8888, 0); SetTextureData(xtex, 0, 0, bmp, rowWidth, 0); return xtex; diff --git a/src/_GLShared.h b/src/_GLShared.h index 2c0f7327d..95074461b 100644 --- a/src/_GLShared.h +++ b/src/_GLShared.h @@ -118,7 +118,7 @@ static CC_NOINLINE void UpdateTextureSlow(int x, int y, struct Bitmap* part, int if (count > UPDATE_FAST_SIZE) Mem_Free(ptr); } -static GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, cc_bool mipmaps) { +GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, cc_bool mipmaps) { GfxResourceID texId = NULL; _glGenTextures(1, (GLuint*)&texId); _glBindTexture(GL_TEXTURE_2D, ptr_to_uint(texId)); diff --git a/src/_GraphicsBase.h b/src/_GraphicsBase.h index 85b485389..a09d56ed5 100644 --- a/src/_GraphicsBase.h +++ b/src/_GraphicsBase.h @@ -420,8 +420,6 @@ cc_bool Gfx_CheckTextureSize(int width, int height, cc_uint8 flags) { return maxSize == 0 || (width * height <= maxSize); } -static GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, cc_bool mipmaps); - GfxResourceID Gfx_CreateTexture(struct Bitmap* bmp, cc_uint8 flags, cc_bool mipmaps) { return Gfx_CreateTexture2(bmp, bmp->width, flags, mipmaps); }