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.
next = pat->mipmap->nextcolormap;
if (!next)
break;
pat->mipmap->nextcolormap = next->nextcolormap;
// Free image data from memory.
@ -671,14 +674,14 @@ void HWR_ClearAllTextures(void)
{
HWR_FreeMapTextures();
// free references to the textures
HWD.pfnClearMipMapCache();
// Alam: free the Z_Blocks before freeing it's users
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)
{
HWR_FreePatchCache(false);
@ -696,6 +699,7 @@ static void FreeMapTexture(GLMapTexture_t *tex)
HWD.pfnDeleteTexture(&tex->mipmap);
if (tex->mipmap.data)
Z_Free(tex->mipmap.data);
tex->mipmap.data = NULL;
}
void HWR_FreeMapTextures(void)
@ -722,18 +726,15 @@ void HWR_FreeMapTextures(void)
void HWR_LoadMapTextures(size_t pnumtextures)
{
// we must free it since numtextures changed
// we must free it since numtextures may have changed
HWR_FreeMapTextures();
// Why not Z_Malloc?
gl_numtextures = pnumtextures;
gl_textures = calloc(gl_numtextures, sizeof(*gl_textures));
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))
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;
}

View file

@ -55,8 +55,7 @@ struct GLMipmap_s
struct GLMipmap_s *nextcolormap;
const UINT8 *colormap;
// opengl
struct GLMipmap_s *nextmipmap; // opengl : liste of all texture in opengl driver
struct GLMipmap_s *prevmipmap, *nextmipmap; // Linked list of all textures
};
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(GClipRect) (INT32 minx, INT32 miny, INT32 maxx, INT32 maxy, float nearclip);
EXPORT void HWRAPI(ClearMipMapCache) (void);
EXPORT void HWRAPI(ClearCacheList) (void);
//Hurdler: added for backward compatibility
EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value);
@ -100,6 +101,7 @@ struct hwdriver_s
ReadRect pfnReadRect;
GClipRect pfnGClipRect;
ClearMipMapCache pfnClearMipMapCache;
ClearCacheList pfnClearCacheList;
SetSpecialState pfnSetSpecialState;//Hurdler: added for backward compatibility
DrawModel pfnDrawModel;
CreateModelVBOs pfnCreateModelVBOs;

View file

@ -1292,6 +1292,9 @@ EXPORT void HWRAPI(DeleteTexture) (FTextureInfo *pTexInfo)
if (pTexInfo->downloaded)
pglDeleteTextures(1, (GLuint *)&pTexInfo->downloaded);
pTexInfo->downloaded = 0;
if (pTexInfo->prevmipmap)
pTexInfo->prevmipmap->nextmipmap = pTexInfo->nextmipmap;
}
@ -1308,12 +1311,21 @@ void Flush(void)
DeleteTexture(gl_cachehead);
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;
}
// -----------------+
// 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
// Returns : true if extension available
@ -1929,10 +1941,15 @@ EXPORT void HWRAPI(SetTexture) (FTextureInfo *pTexInfo)
else
{
UpdateTexture(pTexInfo);
pTexInfo->prevmipmap = NULL;
pTexInfo->nextmipmap = NULL;
// insertion at the tail
if (gl_cachetail)
{ // insertion at the tail
{
gl_cachetail->nextmipmap = pTexInfo;
pTexInfo->prevmipmap = gl_cachetail;
gl_cachetail = pTexInfo;
}
else // initialization of the linked list

View file

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

View file

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

View file

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