diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index 79fb6f4cb..4b9da2616 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -511,6 +511,7 @@ static void HWR_GenerateTexture(GLMapTexture_t *grtex, INT32 texnum, boolean noe for (i = 0, patch = texture->patches; i < texture->patchcount; i++, patch++) { boolean dealloc = true; + boolean doremap = W_NeedPaletteRemapPwad(patch->wad, patch->lump, false); size_t lumplength = W_LumpLengthPwad(patch->wad, patch->lump); pdata = W_CacheLumpNumPwad(patch->wad, patch->lump, PU_CACHE); realpatch = (softwarepatch_t *)pdata; @@ -523,16 +524,15 @@ static void HWR_GenerateTexture(GLMapTexture_t *grtex, INT32 texnum, boolean noe #ifdef WALLFLATS if (texture->type == TEXTURETYPE_FLAT) { - if (W_NeedPaletteRemap()) + if (doremap) R_DoPaletteRemapFlat(pdata, lumplength); realpatch = (softwarepatch_t *)Picture_Convert(PICFMT_FLAT, pdata, PICFMT_DOOMPATCH, 0, NULL, texture->width, texture->height, 0, 0, 0); } else #endif { - (void)lumplength; dealloc = false; - if (W_NeedPaletteRemap()) + if (doremap) R_DoPaletteRemapPatch(realpatch, lumplength); } @@ -844,6 +844,7 @@ static void HWR_CacheFlat(GLMipmap_t *grMipmap, lumpnum_t flatlumpnum) UINT8 *flat; size_t steppy; size_t size, pflatsize; + boolean doremap; // setup the texture info @@ -880,13 +881,13 @@ static void HWR_CacheFlat(GLMipmap_t *grMipmap, lumpnum_t flatlumpnum) grMipmap->width = (UINT16)pflatsize; grMipmap->height = (UINT16)pflatsize; + doremap = W_NeedPaletteRemap(flatlumpnum, true); + // the flat raw data needn't be converted with palettized textures W_ReadLump(flatlumpnum, Z_Malloc(W_LumpLength(flatlumpnum), PU_HWRCACHE, &grMipmap->data)); - // palette remapping - // have to do this here since the lump isn't cached - if (wadfiles[WADFILENUM(flatlumpnum)]->compatmode) + if (doremap) R_DoPaletteRemapFlat(grMipmap->data, size); flat = grMipmap->data; diff --git a/src/r_textures.c b/src/r_textures.c index 3dc4fb77e..dfff08149 100644 --- a/src/r_textures.c +++ b/src/r_textures.c @@ -355,6 +355,7 @@ UINT8 *R_GenerateTexture(size_t texnum) UINT16 wadnum; lumpnum_t lumpnum; size_t lumplength; + boolean doremap; I_Assert(texnum <= (size_t)numtextures); texture = textures[texnum]; @@ -384,6 +385,7 @@ UINT8 *R_GenerateTexture(size_t texnum) return block; } + doremap = W_NeedPaletteRemapPwad(wadnum, lumpnum, false); pdata = W_CacheLumpNumPwad(wadnum, lumpnum, PU_LEVEL); realpatch = (softwarepatch_t *)pdata; @@ -396,7 +398,7 @@ UINT8 *R_GenerateTexture(size_t texnum) goto multipatch; #endif - if (W_NeedPaletteRemap()) + if (doremap) R_DoPaletteRemapPatch(realpatch, lumplength); // Check the patch for holes. @@ -482,6 +484,7 @@ UINT8 *R_GenerateTexture(size_t texnum) wadnum = patch->wad; lumpnum = patch->lump; + doremap = W_NeedPaletteRemapPwad(wadnum, lumpnum, false); pdata = W_CacheLumpNumPwad(wadnum, lumpnum, PU_LEVEL); lumplength = W_LumpLengthPwad(wadnum, lumpnum); realpatch = (softwarepatch_t *)pdata; @@ -495,16 +498,15 @@ UINT8 *R_GenerateTexture(size_t texnum) #ifdef WALLFLATS if (texture->type == TEXTURETYPE_FLAT) { - if (W_NeedPaletteRemap()) + if (doremap) R_DoPaletteRemapFlat(pdata, lumplength); realpatch = (softwarepatch_t *)Picture_Convert(PICFMT_FLAT, pdata, PICFMT_DOOMPATCH, 0, NULL, texture->width, texture->height, 0, 0, 0); } else #endif { - (void)lumplength; dealloc = false; - if (W_NeedPaletteRemap()) + if (doremap) R_DoPaletteRemapPatch(realpatch, lumplength); } @@ -935,8 +937,11 @@ UINT8 *R_GetBrightmapColumn(fixed_t tex, INT32 col) void *R_GetFlat(lumpnum_t flatlumpnum) { + // FIXME: checking this every time a flat is fetched for drawing is stupid... + // sadly they are not cached anywhere else so i have no choice + boolean doremap = W_NeedPaletteRemap(flatlumpnum, false); void *flat = W_CacheLumpNum(flatlumpnum, PU_LEVEL); - if (W_NeedPaletteRemap()) + if (doremap) R_DoPaletteRemapFlat(flat, W_LumpLength(flatlumpnum)); return flat; } diff --git a/src/w_wad.c b/src/w_wad.c index 37cc1dea8..52b8a00f0 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -1681,16 +1681,19 @@ void zerr(int ret) } #endif -// only do palette swapping ONCE, when caching the whole patch -// dumb hack but it works! -static boolean dopalswap = false; - -// returns true if the most recently loaded lump is freshly cached, AND comes from a compatmode file -boolean W_NeedPaletteRemap(void) +// returns true if the given lump is not cached, AND comes from a compatmode file +boolean W_NeedPaletteRemapPwad(UINT16 wad, UINT16 lump, boolean ignorecache) { - boolean r = dopalswap; - dopalswap = false; - return r; + if (!wadfiles[wad]->lumpcache[lump] || ignorecache) + { + return wadfiles[wad]->compatmode; + } + return false; +} + +boolean W_NeedPaletteRemap(lumpnum_t lump, boolean ignorecache) +{ + return W_NeedPaletteRemapPwad(WADFILENUM(lump), LUMPNUM(lump), ignorecache); } /** Reads bytes from the head of a lump. @@ -1881,15 +1884,11 @@ void *W_CacheLumpNumPwad(UINT16 wad, UINT16 lump, INT32 tag) lumpcache = wadfiles[wad]->lumpcache; if (!lumpcache[lump]) { - dopalswap = wadfiles[wad]->compatmode; void *ptr = Z_Malloc(W_LumpLengthPwad(wad, lump), tag, &lumpcache[lump]); W_ReadLumpHeaderPwad(wad, lump, ptr, 0, 0); // read the lump in full } else - { - dopalswap = false; Z_ChangeTag(lumpcache[lump], tag); - } return lumpcache[lump]; } diff --git a/src/w_wad.h b/src/w_wad.h index 8a088ad3c..b518b7d39 100644 --- a/src/w_wad.h +++ b/src/w_wad.h @@ -205,7 +205,8 @@ void *W_CacheLumpNumForce(lumpnum_t lumpnum, INT32 tag); boolean W_IsLumpCached(lumpnum_t lump, void *ptr); boolean W_IsPatchCached(lumpnum_t lump, void *ptr); -boolean W_NeedPaletteRemap(void); +boolean W_NeedPaletteRemapPwad(UINT16 wad, UINT16 lump, boolean ignorecache); +boolean W_NeedPaletteRemap(lumpnum_t lump, boolean ignorecache); void *W_CacheLumpName(const char *name, INT32 tag); void *W_CachePatchName(const char *name, INT32 tag);