diff --git a/src/Drawer2D.c b/src/Drawer2D.c index c997c5c60..c47ab3394 100644 --- a/src/Drawer2D.c +++ b/src/Drawer2D.c @@ -309,7 +309,7 @@ void Drawer2D_MakeTextTexture(struct Texture* tex, struct DrawTextArgs* args) { } void Drawer2D_MakeTexture(struct Texture* tex, struct Bitmap* bmp, int width, int height) { - Gfx_RecreateTexture(&tex->ID, bmp, false, false); + Gfx_RecreateTexture(&tex->ID, bmp, 0, false); tex->Width = width; tex->Height = height; diff --git a/src/Entity.c b/src/Entity.c index 591040e93..7cbbac7ed 100644 --- a/src/Entity.c +++ b/src/Entity.c @@ -443,7 +443,7 @@ static cc_result ApplySkin(struct Entity* e, struct Bitmap* bmp, struct Stream* Chat_Add1("&cSkin %s is too large", skin); } else { if (e->Model->usesHumanSkin) Entity_ClearHat(bmp, e->SkinType); - Gfx_RecreateTexture(&e->TextureId, bmp, true, false); + Gfx_RecreateTexture(&e->TextureId, bmp, TEXTURE_FLAG_MANAGED, false); Entity_SetSkinAll(e, false); } return 0; diff --git a/src/EntityComponents.c b/src/EntityComponents.c index 0eabc60ca..30b3af71a 100644 --- a/src/EntityComponents.c +++ b/src/EntityComponents.c @@ -607,7 +607,7 @@ static void ShadowComponent_MakeTex(void) { row[x] = dist < sh_half * sh_half ? col : 0; } } - Gfx_RecreateTexture(&ShadowComponent_ShadowTex, &bmp, false, false); + Gfx_RecreateTexture(&ShadowComponent_ShadowTex, &bmp, 0, false); } void ShadowComponent_Draw(struct Entity* e) { diff --git a/src/Game.c b/src/Game.c index 2cb330e44..bddfb4a7e 100644 --- a/src/Game.c +++ b/src/Game.c @@ -208,7 +208,7 @@ cc_bool Game_UpdateTexture(GfxResourceID* texId, struct Stream* src, const cc_st success = !res && Game_ValidateBitmap(file, &bmp); if (success) { if (skinType) { *skinType = Utils_CalcSkinType(&bmp); } - Gfx_RecreateTexture(texId, &bmp, true, false); + Gfx_RecreateTexture(texId, &bmp, TEXTURE_FLAG_MANAGED, false); } Mem_Free(bmp.scan0); diff --git a/src/Graphics.h b/src/Graphics.h index 88b5f790c..d5a4c6a35 100644 --- a/src/Graphics.h +++ b/src/Graphics.h @@ -55,14 +55,17 @@ extern GfxResourceID Gfx_quadVb, Gfx_texVb; #define GFX_MAX_INDICES (65536 / 4 * 6) #define GFX_MAX_VERTICES 65536 +#define TEXTURE_FLAG_MANAGED 0x01 /* Texture should persist across gfx context loss */ + void Gfx_RecreateDynamicVb(GfxResourceID* vb, VertexFormat fmt, int maxVertices); -void Gfx_RecreateTexture(GfxResourceID* tex, struct Bitmap* bmp, cc_bool managedPool, cc_bool mipmaps); +void Gfx_RecreateTexture(GfxResourceID* tex, struct Bitmap* bmp, cc_uint8 flags, cc_bool mipmaps); void* Gfx_RecreateAndLockVb(GfxResourceID* vb, VertexFormat fmt, int count); /* Creates a new texture. (and also generates mipmaps if mipmaps) */ +/* Supported flags: TEXTURE_FLAG_MANAGED */ /* NOTE: Only set mipmaps to true if Gfx_Mipmaps is also true, because whether textures use mipmapping may be either a per-texture or global state depending on the backend. */ -CC_API GfxResourceID Gfx_CreateTexture(struct Bitmap* bmp, cc_bool managedPool, cc_bool mipmaps); +CC_API GfxResourceID Gfx_CreateTexture(struct Bitmap* bmp, 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); /* OBSOLETE */ /* Updates a region of the given texture. (and mipmapped regions if mipmaps) */ diff --git a/src/Graphics_D3D9.c b/src/Graphics_D3D9.c index 27977835c..c0953cddb 100644 --- a/src/Graphics_D3D9.c +++ b/src/Graphics_D3D9.c @@ -296,7 +296,7 @@ static void D3D9_DoMipmaps(IDirect3DTexture9* texture, int x, int y, struct Bitm if (prev != bmp->scan0) Mem_Free(prev); } -GfxResourceID Gfx_CreateTexture(struct Bitmap* bmp, cc_bool managedPool, cc_bool mipmaps) { +GfxResourceID Gfx_CreateTexture(struct Bitmap* bmp, cc_uint8 flags, cc_bool mipmaps) { IDirect3DTexture9* tex; IDirect3DTexture9* sys; cc_result res; @@ -308,7 +308,7 @@ GfxResourceID Gfx_CreateTexture(struct Bitmap* bmp, cc_bool managedPool, cc_bool } if (Gfx.LostContext) return 0; - if (managedPool) { + if (flags & TEXTURE_FLAG_MANAGED) { for (;;) { res = IDirect3DDevice9_CreateTexture(device, bmp->width, bmp->height, levels, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &tex, NULL); diff --git a/src/Graphics_GL.c b/src/Graphics_GL.c index b465edb08..05e120a47 100644 --- a/src/Graphics_GL.c +++ b/src/Graphics_GL.c @@ -160,7 +160,7 @@ static void Gfx_DoMipmaps(int x, int y, struct Bitmap* bmp, int rowWidth, cc_boo if (prev != bmp->scan0) Mem_Free(prev); } -GfxResourceID Gfx_CreateTexture(struct Bitmap* bmp, cc_bool managedPool, cc_bool mipmaps) { +GfxResourceID Gfx_CreateTexture(struct Bitmap* bmp, cc_uint8 flags, cc_bool mipmaps) { GLuint texId; glGenTextures(1, &texId); glBindTexture(GL_TEXTURE_2D, texId); diff --git a/src/Http_Worker.c b/src/Http_Worker.c index 1717e74b9..d5830a091 100644 --- a/src/Http_Worker.c +++ b/src/Http_Worker.c @@ -248,14 +248,14 @@ static const cc_string curlAlt = String_FromConst("libcurl.so.3"); #endif static cc_bool LoadCurlFuncs(void) { - static const struct DynamicLibSym funcs[8] = { + static const struct DynamicLibSym funcs[] = { DynamicLib_Sym(curl_global_init), DynamicLib_Sym(curl_global_cleanup), DynamicLib_Sym(curl_easy_init), DynamicLib_Sym(curl_easy_perform), DynamicLib_Sym(curl_easy_setopt), DynamicLib_Sym(curl_easy_cleanup), DynamicLib_Sym(curl_slist_free_all), DynamicLib_Sym(curl_slist_append) }; /* Non-essential function missing in older curl versions */ - static const struct DynamicLibSym optFuncs[1] = { DynamicLib_Sym(curl_easy_strerror) }; + static const struct DynamicLibSym optFuncs[] = { DynamicLib_Sym(curl_easy_strerror) }; void* lib = DynamicLib_Load2(&curlLib); if (!lib) { diff --git a/src/TexturePack.c b/src/TexturePack.c index 58249014a..b07e0b6f7 100644 --- a/src/TexturePack.c +++ b/src/TexturePack.c @@ -55,7 +55,7 @@ static void Atlas_Convert2DTo1D(void) { Bitmap_UNSAFE_CopyBlock(atlasX, atlasY, 0, y * tileSize, &Atlas2D.Bmp, &atlas1D, tileSize); } - Gfx_RecreateTexture(&Atlas1D.TexIds[i], &atlas1D, true, Gfx.Mipmaps); + Gfx_RecreateTexture(&Atlas1D.TexIds[i], &atlas1D, TEXTURE_FLAG_MANAGED, Gfx.Mipmaps); } Mem_Free(atlas1D.scan0); } @@ -92,7 +92,7 @@ static GfxResourceID Atlas_LoadTile_Raw(TextureLoc texLoc, struct Bitmap* elemen if (y >= Atlas2D.RowsCount) return 0; Bitmap_UNSAFE_CopyBlock(x * size, y * size, 0, 0, &Atlas2D.Bmp, element, size); - return Gfx_CreateTexture(element, false, Gfx.Mipmaps); + return Gfx_CreateTexture(element, 0, Gfx.Mipmaps); } GfxResourceID Atlas2D_LoadTile(TextureLoc texLoc) { diff --git a/src/_GraphicsBase.h b/src/_GraphicsBase.h index 839743f7a..2c57454c0 100644 --- a/src/_GraphicsBase.h +++ b/src/_GraphicsBase.h @@ -97,9 +97,9 @@ void Gfx_RecreateDynamicVb(GfxResourceID* vb, VertexFormat fmt, int maxVertices) *vb = Gfx_CreateDynamicVb(fmt, maxVertices); } -void Gfx_RecreateTexture(GfxResourceID* tex, struct Bitmap* bmp, cc_bool managedPool, cc_bool mipmaps) { +void Gfx_RecreateTexture(GfxResourceID* tex, struct Bitmap* bmp, cc_uint8 flags, cc_bool mipmaps) { Gfx_DeleteTexture(tex); - *tex = Gfx_CreateTexture(bmp, managedPool, mipmaps); + *tex = Gfx_CreateTexture(bmp, flags, mipmaps); } void* Gfx_RecreateAndLockVb(GfxResourceID* vb, VertexFormat fmt, int count) {