From b429a3e74cdf02f792f51cfe8f4a2249253a1264 Mon Sep 17 00:00:00 2001 From: NepDisk Date: Sun, 25 May 2025 10:57:20 -0400 Subject: [PATCH] Repair removeflats commit to make it function correctly with colormapping --- src/hardware/hw_cache.c | 17 +++++++++-------- src/r_textures.c | 17 ++++++----------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index 2d65d6511..25a950908 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -953,7 +953,9 @@ void HWR_GetLevelFlat(levelflat_t *levelflat, boolean noencoremap) if (!grMipmap->data && !grMipmap->downloaded) { + UINT8 *flat; UINT8 *colormap = colormaps; + UINT8 *converted; if (!noencoremap && encoremap) { @@ -967,7 +969,13 @@ void HWR_GetLevelFlat(levelflat_t *levelflat, boolean noencoremap) grMipmap->height = (UINT16)textures[texturenum]->height; size_t size = grMipmap->width * grMipmap->height; - memcpy(Z_Malloc(size, PU_HWRCACHE, &grMipmap->data), R_GetFlatForTexture(texturenum), size); + flat = Z_Malloc(size, PU_HWRCACHE, &grMipmap->data); + converted = (UINT8 *)Picture_TextureToFlat(texturenum); + for (size_t i = 0; i < size; i++) + { + flat[i] = colormap[converted[i]]; + } + Z_Free(converted); if (!noencoremap && encoremap) { @@ -991,13 +999,6 @@ void HWR_GetLevelFlat(levelflat_t *levelflat, boolean noencoremap) if (!grMipmap->data && !grMipmap->downloaded) { - UINT8 *colormap = colormaps; - - if (!noencoremap && encoremap) - { - colormap += COLORMAP_REMAPOFFSET; - } - grMipmap->format = GL_TEXFMT_P_8; grMipmap->flags = TF_WRAPXY|TF_CHROMAKEYED; diff --git a/src/r_textures.c b/src/r_textures.c index 3e99f4026..28e60090e 100644 --- a/src/r_textures.c +++ b/src/r_textures.c @@ -571,7 +571,12 @@ UINT8 *R_GetFlatForTexture(size_t texnum) texpatch_t *patch = &texture->patches[0]; UINT16 wadnum = patch->wad; lumpnum_t lumpnum = patch->lump; + boolean doremap = W_NeedPaletteRemapPwad(wadnum, lumpnum, false); UINT8 *pdata = W_CacheLumpNumPwad(wadnum, lumpnum, PU_CACHE); + if (doremap) + { + R_DoPaletteRemapFlat(pdata, W_LumpLengthPwad(wadnum, lumpnum)); + } #ifndef NO_PNG_LUMPS size_t lumplength = W_LumpLengthPwad(wadnum, lumpnum); @@ -951,17 +956,7 @@ void *R_GetFlat(levelflat_t *levelflat) if (levelflat->type == LEVELFLAT_NONE) return NULL; - // 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 - lumpnum_t flatlumpnum = levelflat->lump; - boolean doremap = W_NeedPaletteRemap(flatlumpnum, false); - void *flat = W_CacheLumpNum(flatlumpnum, PU_LEVEL); - if (doremap) - R_DoPaletteRemapFlat(flat, W_LumpLength(flatlumpnum)); - return flat; - - // FIXME: How do I convert above for new format. - //return R_GetFlatForTexture(R_GetTextureNumForFlat(levelflat)); + return R_GetFlatForTexture(R_GetTextureNumForFlat(levelflat)); } //