Change how texture deletion works in OpenGL

This commit is contained in:
Jaime Ita Passos 2020-11-22 17:03:04 -03:00
parent 071ec73389
commit 9ab3acae2d
7 changed files with 37 additions and 14 deletions

View file

@ -642,6 +642,9 @@ void HWR_FreeTextureColormaps(patch_t *patch)
// Set the first colormap to the one that comes after it. // Set the first colormap to the one that comes after it.
next = pat->mipmap->nextcolormap; next = pat->mipmap->nextcolormap;
if (!next)
break;
pat->mipmap->nextcolormap = next->nextcolormap; pat->mipmap->nextcolormap = next->nextcolormap;
// Free image data from memory. // Free image data from memory.
@ -671,14 +674,14 @@ void HWR_ClearAllTextures(void)
{ {
HWR_FreeMapTextures(); HWR_FreeMapTextures();
// free references to the textures
HWD.pfnClearMipMapCache();
// Alam: free the Z_Blocks before freeing it's users // Alam: free the Z_Blocks before freeing it's users
HWR_FreePatchCache(true); HWR_FreePatchCache(true);
// free references to the textures
HWD.pfnClearCacheList();
} }
// free all patch colormaps after each level: must be done after ClearMipMapCache! // free all patch colormaps after each level
void HWR_FreeColormapCache(void) void HWR_FreeColormapCache(void)
{ {
HWR_FreePatchCache(false); HWR_FreePatchCache(false);
@ -696,6 +699,7 @@ static void FreeMapTexture(GLMapTexture_t *tex)
HWD.pfnDeleteTexture(&tex->mipmap); HWD.pfnDeleteTexture(&tex->mipmap);
if (tex->mipmap.data) if (tex->mipmap.data)
Z_Free(tex->mipmap.data); Z_Free(tex->mipmap.data);
tex->mipmap.data = NULL;
} }
void HWR_FreeMapTextures(void) void HWR_FreeMapTextures(void)
@ -722,18 +726,15 @@ void HWR_FreeMapTextures(void)
void HWR_LoadMapTextures(size_t pnumtextures) void HWR_LoadMapTextures(size_t pnumtextures)
{ {
// we must free it since numtextures changed // we must free it since numtextures may have changed
HWR_FreeMapTextures(); HWR_FreeMapTextures();
// Why not Z_Malloc?
gl_numtextures = pnumtextures; gl_numtextures = pnumtextures;
gl_textures = calloc(gl_numtextures, sizeof(*gl_textures)); gl_textures = calloc(gl_numtextures, sizeof(*gl_textures));
gl_flats = calloc(gl_numtextures, sizeof(*gl_flats)); gl_flats = calloc(gl_numtextures, sizeof(*gl_flats));
// Doesn't tell you which it _is_, but hopefully
// should never ever happen (right?!)
if ((gl_textures == NULL) || (gl_flats == NULL)) if ((gl_textures == NULL) || (gl_flats == NULL))
I_Error("HWR_LoadMapTextures: ran out of memory for OpenGL textures. Sad!"); I_Error("HWR_LoadMapTextures: ran out of memory for OpenGL textures");
gl_maptexturesloaded = true; gl_maptexturesloaded = true;
} }

View file

@ -55,8 +55,7 @@ struct GLMipmap_s
struct GLMipmap_s *nextcolormap; struct GLMipmap_s *nextcolormap;
const UINT8 *colormap; const UINT8 *colormap;
// opengl struct GLMipmap_s *prevmipmap, *nextmipmap; // Linked list of all textures
struct GLMipmap_s *nextmipmap; // opengl : liste of all texture in opengl driver
}; };
typedef struct GLMipmap_s GLMipmap_t; typedef struct GLMipmap_s GLMipmap_t;

View file

@ -46,6 +46,7 @@ EXPORT void HWRAPI(DeleteTexture) (FTextureInfo *TexInfo);
EXPORT void HWRAPI(ReadRect) (INT32 x, INT32 y, INT32 width, INT32 height, INT32 dst_stride, UINT16 *dst_data); EXPORT void HWRAPI(ReadRect) (INT32 x, INT32 y, INT32 width, INT32 height, INT32 dst_stride, UINT16 *dst_data);
EXPORT void HWRAPI(GClipRect) (INT32 minx, INT32 miny, INT32 maxx, INT32 maxy, float nearclip); EXPORT void HWRAPI(GClipRect) (INT32 minx, INT32 miny, INT32 maxx, INT32 maxy, float nearclip);
EXPORT void HWRAPI(ClearMipMapCache) (void); EXPORT void HWRAPI(ClearMipMapCache) (void);
EXPORT void HWRAPI(ClearCacheList) (void);
//Hurdler: added for backward compatibility //Hurdler: added for backward compatibility
EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value); EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value);
@ -100,6 +101,7 @@ struct hwdriver_s
ReadRect pfnReadRect; ReadRect pfnReadRect;
GClipRect pfnGClipRect; GClipRect pfnGClipRect;
ClearMipMapCache pfnClearMipMapCache; ClearMipMapCache pfnClearMipMapCache;
ClearCacheList pfnClearCacheList;
SetSpecialState pfnSetSpecialState;//Hurdler: added for backward compatibility SetSpecialState pfnSetSpecialState;//Hurdler: added for backward compatibility
DrawModel pfnDrawModel; DrawModel pfnDrawModel;
CreateModelVBOs pfnCreateModelVBOs; CreateModelVBOs pfnCreateModelVBOs;

View file

@ -1292,6 +1292,9 @@ EXPORT void HWRAPI(DeleteTexture) (FTextureInfo *pTexInfo)
if (pTexInfo->downloaded) if (pTexInfo->downloaded)
pglDeleteTextures(1, (GLuint *)&pTexInfo->downloaded); pglDeleteTextures(1, (GLuint *)&pTexInfo->downloaded);
pTexInfo->downloaded = 0; pTexInfo->downloaded = 0;
if (pTexInfo->prevmipmap)
pTexInfo->prevmipmap->nextmipmap = pTexInfo->nextmipmap;
} }
@ -1308,12 +1311,21 @@ void Flush(void)
DeleteTexture(gl_cachehead); DeleteTexture(gl_cachehead);
gl_cachehead = gl_cachehead->nextmipmap; gl_cachehead = gl_cachehead->nextmipmap;
} }
gl_cachetail = gl_cachehead = NULL; //Hurdler: well, gl_cachehead is already NULL
ClearCacheList(); //Hurdler: well, gl_cachehead is already NULL
tex_downloaded = 0; tex_downloaded = 0;
} }
// -----------------+
// ClearCacheList : Clears the texture cache tail and head
// -----------------+
EXPORT void HWRAPI(ClearCacheList) (void)
{
gl_cachetail = gl_cachehead = NULL;
}
// -----------------+ // -----------------+
// isExtAvailable : Look if an OpenGL extension is available // isExtAvailable : Look if an OpenGL extension is available
// Returns : true if extension available // Returns : true if extension available
@ -1929,10 +1941,15 @@ EXPORT void HWRAPI(SetTexture) (FTextureInfo *pTexInfo)
else else
{ {
UpdateTexture(pTexInfo); UpdateTexture(pTexInfo);
pTexInfo->prevmipmap = NULL;
pTexInfo->nextmipmap = NULL; pTexInfo->nextmipmap = NULL;
// insertion at the tail
if (gl_cachetail) if (gl_cachetail)
{ // insertion at the tail {
gl_cachetail->nextmipmap = pTexInfo; gl_cachetail->nextmipmap = pTexInfo;
pTexInfo->prevmipmap = gl_cachetail;
gl_cachetail = pTexInfo; gl_cachetail = pTexInfo;
} }
else // initialization of the linked list else // initialization of the linked list

View file

@ -90,6 +90,7 @@ void *hwSym(const char *funcName,void *handle)
GETFUNC(ReadRect); GETFUNC(ReadRect);
GETFUNC(GClipRect); GETFUNC(GClipRect);
GETFUNC(ClearMipMapCache); GETFUNC(ClearMipMapCache);
GETFUNC(ClearCacheList);
GETFUNC(SetSpecialState); GETFUNC(SetSpecialState);
GETFUNC(GetTextureUsed); GETFUNC(GetTextureUsed);
GETFUNC(DrawModel); GETFUNC(DrawModel);

View file

@ -1868,6 +1868,7 @@ void VID_StartupOpenGL(void)
HWD.pfnReadRect = hwSym("ReadRect",NULL); HWD.pfnReadRect = hwSym("ReadRect",NULL);
HWD.pfnGClipRect = hwSym("GClipRect",NULL); HWD.pfnGClipRect = hwSym("GClipRect",NULL);
HWD.pfnClearMipMapCache = hwSym("ClearMipMapCache",NULL); HWD.pfnClearMipMapCache = hwSym("ClearMipMapCache",NULL);
HWD.pfnClearCacheList = hwSym("ClearCacheList",NULL);
HWD.pfnSetSpecialState = hwSym("SetSpecialState",NULL); HWD.pfnSetSpecialState = hwSym("SetSpecialState",NULL);
HWD.pfnSetPalette = hwSym("SetPalette",NULL); HWD.pfnSetPalette = hwSym("SetPalette",NULL);
HWD.pfnGetTextureUsed = hwSym("GetTextureUsed",NULL); HWD.pfnGetTextureUsed = hwSym("GetTextureUsed",NULL);

View file

@ -111,6 +111,7 @@ static loadfunc_t hwdFuncTable[] = {
{"ReadRect@24", &hwdriver.pfnReadRect}, {"ReadRect@24", &hwdriver.pfnReadRect},
{"GClipRect@20", &hwdriver.pfnGClipRect}, {"GClipRect@20", &hwdriver.pfnGClipRect},
{"ClearMipMapCache@0", &hwdriver.pfnClearMipMapCache}, {"ClearMipMapCache@0", &hwdriver.pfnClearMipMapCache},
{"ClearCacheList@0", &hwdriver.pfnClearCacheList},
{"SetSpecialState@8", &hwdriver.pfnSetSpecialState}, {"SetSpecialState@8", &hwdriver.pfnSetSpecialState},
{"DrawModel@16", &hwdriver.pfnDrawModel}, {"DrawModel@16", &hwdriver.pfnDrawModel},
{"SetTransform@4", &hwdriver.pfnSetTransform}, {"SetTransform@4", &hwdriver.pfnSetTransform},
@ -144,6 +145,7 @@ static loadfunc_t hwdFuncTable[] = {
{"ReadRect", &hwdriver.pfnReadRect}, {"ReadRect", &hwdriver.pfnReadRect},
{"GClipRect", &hwdriver.pfnGClipRect}, {"GClipRect", &hwdriver.pfnGClipRect},
{"ClearMipMapCache", &hwdriver.pfnClearMipMapCache}, {"ClearMipMapCache", &hwdriver.pfnClearMipMapCache},
{"ClearCacheList", &hwdriver.pfnClearCacheList},
{"SetSpecialState", &hwdriver.pfnSetSpecialState}, {"SetSpecialState", &hwdriver.pfnSetSpecialState},
{"DrawModel", &hwdriver.pfnDrawModel}, {"DrawModel", &hwdriver.pfnDrawModel},
{"SetTransform", &hwdriver.pfnSetTransform}, {"SetTransform", &hwdriver.pfnSetTransform},