diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index 7e2e16c01..82c77be2a 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -437,8 +437,16 @@ void HWR_MakePatch(const patch_t *patch, GLPatch_t *glPatch, GLMipmap_t *glMipma // CACHING HANDLING // ================================================= +typedef struct +{ + GLMapTexture_t normal; +#ifdef GLENCORE + GLMapTexture_t encore; +#endif +} GLMapTextureSet_t; // idk i suck at naming things + static size_t gl_numtextures = 0; // Texture count -static GLMapTexture_t *gl_textures; // For all textures +static GLMapTextureSet_t *gl_textures; // For all textures static void HWR_FreeTextureData(patch_t *patch) { @@ -578,13 +586,12 @@ void HWR_FreeMapTextures(void) { size_t i; -#ifdef GLENCORE - for (i = 0; i < gl_numtextures*2; i++) -#else for (i = 0; i < gl_numtextures; i++) -#endif { - FreeMapTexture(&gl_textures[i]); + FreeMapTexture(&gl_textures[i].normal); +#ifdef GLENCORE + FreeMapTexture(&gl_textures[i].encore); +#endif } // now the heap don't have any 'user' pointing to our @@ -823,11 +830,8 @@ void HWR_LoadMapTextures(size_t pnumtextures) HWR_FreeMapTextures(); gl_numtextures = pnumtextures; -#ifdef GLENCORE - gl_textures = calloc(gl_numtextures, sizeof (*gl_textures)*2); // *2 - 1 for encore-remapped texture and another for noencore texture (unused when not in encore) -#else - gl_textures = calloc(gl_numtextures, sizeof (*gl_textures)); -#endif + gl_textures = calloc(gl_numtextures, sizeof(*gl_textures)); // *2 - 1 for encore-remapped texture and another for noencore texture (unused when not in encore), see: GLMapTextureSet_t + if (gl_textures == NULL) I_Error("HWR_LoadMapTextures: ran out of memory for OpenGL textures. Sad!"); } @@ -851,7 +855,7 @@ GLMapTexture_t *HWR_GetTexture(INT32 tex, boolean noencore) // Every texture in memory, stored in the // hardware renderer's bit depth format. Wow! #ifdef GLENCORE - gltex = &gl_textures[tex*2 + (encoremap && !noencore ? 0 : 1)]; + gltex = (encoremap && !noencore) ? &gl_textures[tex].encore : &gl_textures[tex].normal; #else gltex = &gl_textures[tex]; #endif