Optimize mipmaps

This commit is contained in:
Jaime Passos 2019-12-08 03:23:37 -03:00
parent ce61b17117
commit cc12496e9c
6 changed files with 35 additions and 20 deletions

View File

@ -804,15 +804,17 @@ static void FreeMipmapColormap(INT32 patchnum, void *patch)
// Free image data from memory.
if (next->grInfo.data)
Z_Free(next->grInfo.data);
next->grInfo.data = NULL;
// Free the old colormap from memory.
// Free the old colormap mipmap from memory.
free(next);
}
}
void HWR_FreeTextureCache(void)
void HWR_FreeMipmapCache(void)
{
INT32 i;
// free references to the textures
HWD.pfnClearMipMapCache();
@ -822,10 +824,15 @@ void HWR_FreeTextureCache(void)
Z_FreeTag(PU_HWRCACHE_UNLOCKED);
// Alam: free the Z_Blocks before freeing it's users
// free all patch colormaps after each level: must be done after ClearMipMapCache!
for (i = 0; i < numwadfiles; i++)
M_AATreeIterate(wadfiles[i]->hwrcache, FreeMipmapColormap);
}
void HWR_FreeTextureCache(void)
{
// free references to the textures
HWR_FreeMipmapCache();
// now the heap don't have any 'user' pointing to our
// texturecache info, we can free it
@ -838,13 +845,8 @@ void HWR_FreeTextureCache(void)
gr_numtextures = 0;
}
void HWR_PrepLevelCache(size_t pnumtextures)
void HWR_LoadTextures(size_t pnumtextures)
{
// problem: the mipmap cache management hold a list of mipmaps.. but they are
// reallocated on each level..
//sub-optimal, but 1) just need re-download stuff in hardware cache VERY fast
// 2) sprite/menu stuff mixed with level textures so can't do anything else
// we must free it since numtextures changed
HWR_FreeTextureCache();
@ -856,7 +858,7 @@ void HWR_PrepLevelCache(size_t pnumtextures)
// Doesn't tell you which it _is_, but hopefully
// should never ever happen (right?!)
if ((gr_textures == NULL) || (gr_flats == NULL))
I_Error("HWR_PrepLevelCache: ran out of memory for OpenGL textures. Sad!");
I_Error("HWR_LoadTextures: ran out of memory for OpenGL textures. Sad!");
}
void HWR_SetPalette(RGBA_t *palette)

View File

@ -100,6 +100,7 @@ void HWR_FreePolyPool(void);
// --------
void HWR_InitTextureCache(void);
void HWR_FreeTextureCache(void);
void HWR_FreeMipmapCache(void);
void HWR_FreeExtraSubsectors(void);
void HWR_GetLevelFlat(levelflat_t *levelflat);

View File

@ -6687,6 +6687,7 @@ void HWR_Shutdown(void)
CONS_Printf("HWR_Shutdown()\n");
HWR_FreeExtraSubsectors();
HWR_FreePolyPool();
HWR_FreeMipmapCache();
HWR_FreeTextureCache();
HWD.pfnFlushScreenTextures();
}

View File

@ -47,7 +47,7 @@ void HWR_DrawCroppedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t scale
void HWR_MakePatch(const patch_t *patch, GLPatch_t *grPatch, GLMipmap_t *grMipmap, boolean makebitmap);
void HWR_CreatePlanePolygons(INT32 bspnum);
void HWR_CreateStaticLightmaps(INT32 bspnum);
void HWR_PrepLevelCache(size_t pnumtextures);
void HWR_LoadTextures(size_t pnumtextures);
void HWR_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 color);
void HWR_DrawFadeFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 color, UINT16 actualcolor, UINT8 strength);
void HWR_DrawConsoleFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 color, UINT32 actualcolor); // Lat: separate flags from color since color needs to be an uint to work right.

View File

@ -3019,8 +3019,17 @@ boolean P_SetupLevel(boolean skipprecip)
P_SpawnPrecipitation();
#ifdef HWRENDER // not win32 only 19990829 by Kin
if (rendermode != render_soft && rendermode != render_none)
if (rendermode == render_opengl)
{
// Lactozilla (December 8, 2019)
// Level setup used to free EVERY mipmap from memory.
// Even mipmaps that aren't related to level textures.
// Presumably, the hardware render code used to store textures as level data.
// Meaning, they had memory allocated and marked with the PU_LEVEL tag.
// Now, only mipmaps that AREN'T level textures are freed between levels.
// Level textures are only reloaded after R_LoadTextures, which is
// when the texture list is loaded.
HWR_FreeMipmapCache();
#ifdef ALAM_LIGHTING
// BP: reset light between levels (we draw preview frame lights on current frame)
HWR_ResetLights();
@ -3203,14 +3212,6 @@ boolean P_SetupLevel(boolean skipprecip)
// Fab : 19-07-98 : start cd music for this level (note: can be remapped)
I_PlayCD((UINT8)(gamemap), false);
// preload graphics
#ifdef HWRENDER // not win32 only 19990829 by Kin
if (rendermode != render_soft && rendermode != render_none)
{
HWR_PrepLevelCache(numtextures);
}
#endif
P_MapEnd();
// Remove the loading shit from the screen
@ -3540,6 +3541,7 @@ boolean P_AddWadFile(const char *wadfilename)
#ifdef HWRENDER
HWR_ReloadModels();
HWR_FreeMipmapCache();
#endif
// reload status bar (warning should have valid player!)

View File

@ -32,6 +32,10 @@
#include <malloc.h> // alloca(sizeof)
#endif
#ifdef HWRENDER
#include "hardware/hw_main.h" // HWR_LoadTextures
#endif
#if defined(_MSC_VER)
#pragma pack(1)
#endif
@ -872,6 +876,11 @@ void R_LoadTextures(void)
i++;
}
}
#ifdef HWRENDER
if (rendermode == render_opengl)
HWR_LoadTextures(numtextures);
#endif
}
static texpatch_t *R_ParsePatch(boolean actuallyLoadPatch)