Change managedPool parameter to flags for Gfx_CreateTexture/GfxRecreateTexture

This commit is contained in:
UnknownShadow200 2021-09-20 20:34:51 +10:00
parent b2a230b451
commit c7aa361240
10 changed files with 18 additions and 15 deletions

View File

@ -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) { 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->Width = width;
tex->Height = height; tex->Height = height;

View File

@ -443,7 +443,7 @@ static cc_result ApplySkin(struct Entity* e, struct Bitmap* bmp, struct Stream*
Chat_Add1("&cSkin %s is too large", skin); Chat_Add1("&cSkin %s is too large", skin);
} else { } else {
if (e->Model->usesHumanSkin) Entity_ClearHat(bmp, e->SkinType); 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); Entity_SetSkinAll(e, false);
} }
return 0; return 0;

View File

@ -607,7 +607,7 @@ static void ShadowComponent_MakeTex(void) {
row[x] = dist < sh_half * sh_half ? col : 0; 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) { void ShadowComponent_Draw(struct Entity* e) {

View File

@ -208,7 +208,7 @@ cc_bool Game_UpdateTexture(GfxResourceID* texId, struct Stream* src, const cc_st
success = !res && Game_ValidateBitmap(file, &bmp); success = !res && Game_ValidateBitmap(file, &bmp);
if (success) { if (success) {
if (skinType) { *skinType = Utils_CalcSkinType(&bmp); } if (skinType) { *skinType = Utils_CalcSkinType(&bmp); }
Gfx_RecreateTexture(texId, &bmp, true, false); Gfx_RecreateTexture(texId, &bmp, TEXTURE_FLAG_MANAGED, false);
} }
Mem_Free(bmp.scan0); Mem_Free(bmp.scan0);

View File

@ -55,14 +55,17 @@ extern GfxResourceID Gfx_quadVb, Gfx_texVb;
#define GFX_MAX_INDICES (65536 / 4 * 6) #define GFX_MAX_INDICES (65536 / 4 * 6)
#define GFX_MAX_VERTICES 65536 #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_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); void* Gfx_RecreateAndLockVb(GfxResourceID* vb, VertexFormat fmt, int count);
/* Creates a new texture. (and also generates mipmaps if mipmaps) */ /* 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 /* 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. */ 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) */ /* 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 */ 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) */ /* Updates a region of the given texture. (and mipmapped regions if mipmaps) */

View File

@ -296,7 +296,7 @@ static void D3D9_DoMipmaps(IDirect3DTexture9* texture, int x, int y, struct Bitm
if (prev != bmp->scan0) Mem_Free(prev); 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* tex;
IDirect3DTexture9* sys; IDirect3DTexture9* sys;
cc_result res; cc_result res;
@ -308,7 +308,7 @@ GfxResourceID Gfx_CreateTexture(struct Bitmap* bmp, cc_bool managedPool, cc_bool
} }
if (Gfx.LostContext) return 0; if (Gfx.LostContext) return 0;
if (managedPool) { if (flags & TEXTURE_FLAG_MANAGED) {
for (;;) { for (;;) {
res = IDirect3DDevice9_CreateTexture(device, bmp->width, bmp->height, levels, res = IDirect3DDevice9_CreateTexture(device, bmp->width, bmp->height, levels,
0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &tex, NULL); 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &tex, NULL);

View File

@ -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); 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; GLuint texId;
glGenTextures(1, &texId); glGenTextures(1, &texId);
glBindTexture(GL_TEXTURE_2D, texId); glBindTexture(GL_TEXTURE_2D, texId);

View File

@ -248,14 +248,14 @@ static const cc_string curlAlt = String_FromConst("libcurl.so.3");
#endif #endif
static cc_bool LoadCurlFuncs(void) { 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_global_init), DynamicLib_Sym(curl_global_cleanup),
DynamicLib_Sym(curl_easy_init), DynamicLib_Sym(curl_easy_perform), DynamicLib_Sym(curl_easy_init), DynamicLib_Sym(curl_easy_perform),
DynamicLib_Sym(curl_easy_setopt), DynamicLib_Sym(curl_easy_cleanup), DynamicLib_Sym(curl_easy_setopt), DynamicLib_Sym(curl_easy_cleanup),
DynamicLib_Sym(curl_slist_free_all), DynamicLib_Sym(curl_slist_append) DynamicLib_Sym(curl_slist_free_all), DynamicLib_Sym(curl_slist_append)
}; };
/* Non-essential function missing in older curl versions */ /* 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); void* lib = DynamicLib_Load2(&curlLib);
if (!lib) { if (!lib) {

View File

@ -55,7 +55,7 @@ static void Atlas_Convert2DTo1D(void) {
Bitmap_UNSAFE_CopyBlock(atlasX, atlasY, 0, y * tileSize, Bitmap_UNSAFE_CopyBlock(atlasX, atlasY, 0, y * tileSize,
&Atlas2D.Bmp, &atlas1D, 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); Mem_Free(atlas1D.scan0);
} }
@ -92,7 +92,7 @@ static GfxResourceID Atlas_LoadTile_Raw(TextureLoc texLoc, struct Bitmap* elemen
if (y >= Atlas2D.RowsCount) return 0; if (y >= Atlas2D.RowsCount) return 0;
Bitmap_UNSAFE_CopyBlock(x * size, y * size, 0, 0, &Atlas2D.Bmp, element, size); 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) { GfxResourceID Atlas2D_LoadTile(TextureLoc texLoc) {

View File

@ -97,9 +97,9 @@ void Gfx_RecreateDynamicVb(GfxResourceID* vb, VertexFormat fmt, int maxVertices)
*vb = Gfx_CreateDynamicVb(fmt, 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); Gfx_DeleteTexture(tex);
*tex = Gfx_CreateTexture(bmp, managedPool, mipmaps); *tex = Gfx_CreateTexture(bmp, flags, mipmaps);
} }
void* Gfx_RecreateAndLockVb(GfxResourceID* vb, VertexFormat fmt, int count) { void* Gfx_RecreateAndLockVb(GfxResourceID* vb, VertexFormat fmt, int count) {