From 653b9ffaa0f1d60c2c393b0de46958fbc2b41342 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 8 Apr 2025 21:39:03 +0200 Subject: [PATCH] Revert "HACK: make translucent fofs not cut cyan pixels" This reverts commit 0503841939e0385b1eb571ea98aadeee2f3dfb10. --- src/hardware/hw_cache.c | 154 ++++++++++++---------------------------- src/hardware/hw_draw.c | 2 +- src/hardware/hw_glob.h | 2 +- src/hardware/hw_main.c | 16 ++--- 4 files changed, 54 insertions(+), 120 deletions(-) diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index ef6995268..5ba8655b8 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -103,8 +103,11 @@ static void HWR_DrawColumnInCache(const column_t *patchcol, UINT8 *block, GLMipm if (position + count >= pblockheight) count = pblockheight - position; - for (dest = block + (position*blockmodulo); count > 0; count--, dest += blockmodulo, yfrac += yfracstep) + dest = block + (position*blockmodulo); + while (count > 0) { + count--; + texel = source[yfrac>>FRACBITS]; alpha = 0xFF; @@ -136,6 +139,9 @@ static void HWR_DrawColumnInCache(const column_t *patchcol, UINT8 *block, GLMipm default: *dest = texel; break; } + + dest += blockmodulo; + yfrac += yfracstep; } patchcol = (const column_t *)((const UINT8 *)patchcol + patchcol->length + 4); @@ -302,7 +308,7 @@ static UINT8 *MakeBlock(GLMipmap_t *glMipmap) // Create a composite texture from patches, adapt the texture size to a power of 2 // height and width for the hardware texture cache. // -static void HWR_GenerateTexture(INT32 texnum, GLMapTexture_t *gltex, boolean noencore, GLMipmap_t *mipmap) +static void HWR_GenerateTexture(INT32 texnum, GLMapTexture_t *gltex, boolean noencore) { UINT8 *block; texture_t *texture; @@ -318,24 +324,24 @@ static void HWR_GenerateTexture(INT32 texnum, GLMapTexture_t *gltex, boolean noe texture = textures[texnum]; - mipmap->flags = TF_CHROMAKEYED|TF_WRAPXY; - mipmap->width = (UINT16)texture->width; - mipmap->height = (UINT16)texture->height; - mipmap->colormap = colormaps; - mipmap->format = textureformat; + gltex->mipmap.flags = TF_CHROMAKEYED | TF_WRAPXY; + gltex->mipmap.width = (UINT16)(texture->width); + gltex->mipmap.height = (UINT16)(texture->height); + gltex->mipmap.colormap = colormaps; + gltex->mipmap.format = textureformat; // hack the Legacy skies.. if (UNLIKELY(strncmp(texture->name, "SKY", 3) == 0 && (texture->name[4] == 0 || texture->name[5] == 0))) { skyspecial = true; - mipmap->flags &= ~TF_CHROMAKEYED; // don't use the chromakey for sky - mipmap->format = GL_TEXFMT_RGBA; // that skyspecial code below assumes this format ... + gltex->mipmap.flags &= ~TF_CHROMAKEYED; // don't use the chromakey for sky + gltex->mipmap.format = GL_TEXFMT_RGBA; // that skyspecial code below assumes this format ... } #ifdef GLENCORE if (encoremap && !noencore) - mipmap->colormap += COLORMAP_REMAPOFFSET; + gltex->mipmap.colormap += COLORMAP_REMAPOFFSET; #endif blockwidth = texture->width; @@ -375,14 +381,14 @@ static void HWR_GenerateTexture(INT32 texnum, GLMapTexture_t *gltex, boolean noe } //Hurdler: not efficient at all but I don't remember exactly how HWR_DrawPatchInCache works :( - if (format2bpp(mipmap->format) == 4) + if (format2bpp(gltex->mipmap.format) == 4) { for (i = 3; i < blocksize*4; i += 4) // blocksize*4 because blocksize doesn't include the bpp { if (block[i] != 0) continue; - mipmap->flags |= TF_TRANSPARENT; + gltex->mipmap.flags |= TF_TRANSPARENT; break; } } @@ -482,8 +488,7 @@ static void FreeMipmapColormap(INT32 patchnum, void *patch) // Free image data from memory. if (next->data) - if (!(next->flags & TF_CHROMAKEYED)) - Z_Free(next->data); + Z_Free(next->data); next->data = NULL; GL_DeleteTexture(next); @@ -554,14 +559,14 @@ static void HWR_PrecacheLevelFlats(void) levelflat = levelflats[pic]; lump = levelflat.lumpnum; - HWR_GetFlat(lump, R_NoEncore(sec, ceiling), true); + HWR_GetFlat(lump, R_NoEncore(sec, ceiling)); if (levelflat.speed) // it is an animated flat { for (k = 1; k < levelflat.numpics; k++) { lump = levelflat.baselumpnum + k; - HWR_GetFlat(lump, R_NoEncore(sec, ceiling), true); + HWR_GetFlat(lump, R_NoEncore(sec, ceiling)); } } } @@ -577,14 +582,14 @@ static void HWR_PrecacheLevelFlats(void) levelflat = levelflats[i]; lump = levelflat.lumpnum; - HWR_GetFlat(lump, false, true); + HWR_GetFlat(lump, false); if (levelflat.speed) // it is an animated flat { for (k = 1; k < levelflat.numpics; k++) { lump = levelflat.baselumpnum + k; - HWR_GetFlat(lump, false, true); + HWR_GetFlat(lump, false); } } } @@ -795,22 +800,6 @@ void HWR_LoadTextures(size_t pnumtextures) // -------------------------------------------------------------------------- // Make sure texture is downloaded and set it as the source // -------------------------------------------------------------------------- - -static void GetMapTexture(INT32 tex, GLMapTexture_t *grtex, boolean noencore, GLMipmap_t *mipmap) -{ - // Generate texture if missing from the cache - if (!mipmap->data && !mipmap->downloaded) - HWR_GenerateTexture(tex, grtex, noencore, mipmap); - - // If hardware does not have the texture, then call pfnSetTexture to upload it - if (!mipmap->downloaded) - GL_SetTexture(mipmap); - HWR_SetCurrentTexture(mipmap); - - // The system-memory data can be purged now. - Z_ChangeTag(mipmap->data, PU_HWRCACHE_UNLOCKED); -} - GLMapTexture_t *HWR_GetTexture(INT32 tex, boolean noencore) { GLMapTexture_t *gltex; @@ -823,19 +812,26 @@ GLMapTexture_t *HWR_GetTexture(INT32 tex, boolean noencore) tex = 0; #endif } - #ifdef GLENCORE gltex = &gl_textures[tex*2 + (encoremap && !noencore ? 0 : 1)]; #else gltex = &gl_textures[tex]; #endif + if (!gltex->mipmap.data && !gltex->mipmap.downloaded) + HWR_GenerateTexture(tex, gltex, noencore); - GetMapTexture(tex, gltex, noencore, &gltex->mipmap); + // If hardware does not have the texture, then call pfnSetTexture to upload it + if (!gltex->mipmap.downloaded) + GL_SetTexture(&gltex->mipmap); + HWR_SetCurrentTexture(&gltex->mipmap); + + // The system-memory data can be purged now. + Z_ChangeTag(gltex->mipmap.data, PU_HWRCACHE_UNLOCKED); return gltex; } -static void HWR_CacheRawFlat(GLMipmap_t *glMipmap, lumpnum_t flatlumpnum) +static void HWR_CacheFlat(GLMipmap_t *glMipmap, lumpnum_t flatlumpnum) { #ifdef GLENCORE UINT8 *flat; @@ -845,7 +841,7 @@ static void HWR_CacheRawFlat(GLMipmap_t *glMipmap, lumpnum_t flatlumpnum) // setup the texture info glMipmap->format = GL_TEXFMT_P_8; - glMipmap->flags = TF_WRAPXY; + glMipmap->flags = TF_WRAPXY|TF_CHROMAKEYED; size = W_LumpLength(flatlumpnum); @@ -891,94 +887,32 @@ static void HWR_CacheRawFlat(GLMipmap_t *glMipmap, lumpnum_t flatlumpnum) #endif } -static void MakeLevelFlatMipmap(GLMipmap_t *glMipmap, lumpnum_t flatlumpnum, UINT16 flags) +// Download a Doom 'flat' to the hardware cache and make it ready for use +void HWR_GetFlat(lumpnum_t flatlumpnum, boolean noencoremap) { - glMipmap->format = GL_TEXFMT_P_8; - glMipmap->flags = flags; + GLMipmap_t *glMipmap; - size_t pflatsize; - size_t size = W_LumpLength(flatlumpnum); - - switch (size) - { - case 4194304: // 2048x2048 lump - pflatsize = 2048; - break; - case 1048576: // 1024x1024 lump - pflatsize = 1024; - break; - case 262144:// 512x512 lump - pflatsize = 512; - break; - case 65536: // 256x256 lump - pflatsize = 256; - break; - case 16384: // 128x128 lump - pflatsize = 128; - break; - case 1024: // 32x32 lump - pflatsize = 32; - break; - default: // 64x64 lump - pflatsize = 64; - break; - } - glMipmap->width = (UINT16)pflatsize; - glMipmap->height = (UINT16)pflatsize; -} - -void HWR_GetFlat(lumpnum_t flatlumpnum, boolean noencoremap, boolean chromakeyed) -{ if (flatlumpnum == LUMPERROR) return; - GLMipmap_t *glMipmap = HWR_GetCachedGLPatch(flatlumpnum)->mipmap; - GLMipmap_t *originalMipmap = glMipmap; + glMipmap = HWR_GetCachedGLPatch(flatlumpnum)->mipmap; - originalMipmap->colormap = colormaps; + glMipmap->colormap = colormaps; #ifdef GLENCORE if (!noencoremap && encoremap) - { - originalMipmap->colormap += COLORMAP_REMAPOFFSET; - } + glMipmap->colormap += COLORMAP_REMAPOFFSET; #endif - if (!originalMipmap->downloaded && !originalMipmap->data) - HWR_CacheRawFlat(originalMipmap, flatlumpnum); - - // If chroma-keyed, create or use a different mipmap for the variant - if (chromakeyed) - { - if (!originalMipmap->data) - { - HWR_SetCurrentTexture(NULL); - return; - } - - // Allocate it if it wasn't already - if (!originalMipmap->nextcolormap) - { - GLMipmap_t *newMipmap = calloc(1, sizeof (*glMipmap)); - if (newMipmap == NULL) - I_Error("%s: Out of memory", "HWR_GetLevelFlat"); - MakeLevelFlatMipmap(newMipmap, flatlumpnum, TF_WRAPXY | TF_CHROMAKEYED); - originalMipmap->nextcolormap = newMipmap; - } - - // Upload and bind the variant texture instead of the original one - glMipmap = originalMipmap->nextcolormap; - - // Use the original texture's pixel data - // It can just be a pointer to it, since the r_opengl backend deals with the pixels - // that are supposed to be transparent. - glMipmap->data = originalMipmap->data; - } + if (!glMipmap->downloaded && !glMipmap->data) + HWR_CacheFlat(glMipmap, flatlumpnum); + // If hardware does not have the texture, then call pfnSetTexture to upload it if (!glMipmap->downloaded) GL_SetTexture(glMipmap); HWR_SetCurrentTexture(glMipmap); + // The system-memory data can be purged now. Z_ChangeTag(glMipmap->data, PU_HWRCACHE_UNLOCKED); } diff --git a/src/hardware/hw_draw.c b/src/hardware/hw_draw.c index 95b91969e..a23fc9977 100644 --- a/src/hardware/hw_draw.c +++ b/src/hardware/hw_draw.c @@ -541,7 +541,7 @@ void HWR_DrawFlatFill (INT32 x, INT32 y, INT32 w, INT32 h, lumpnum_t flatlumpnum v[0].t = v[1].t = (float)((y & flatflag)/dflatsize); v[2].t = v[3].t = (float)(v[0].t + h/dflatsize); - HWR_GetFlat(flatlumpnum, false, true); // Never Encore map drawflatfill, duh. + HWR_GetFlat(flatlumpnum, false); // Never Encore map drawflatfill, duh. //Hurdler: Boris, the same comment as above... but maybe for pics // it not a problem since they don't have any transparent pixel diff --git a/src/hardware/hw_glob.h b/src/hardware/hw_glob.h index 1b6a94c33..e4659c0e6 100644 --- a/src/hardware/hw_glob.h +++ b/src/hardware/hw_glob.h @@ -62,7 +62,7 @@ void HWR_FreeMipmapCache(void); void HWR_PrecacheLevel(void); -void HWR_GetFlat(lumpnum_t flatlumpnum, boolean noencoremap, boolean chromakeyed); +void HWR_GetFlat(lumpnum_t flatlumpnum, boolean noencoremap); // ^ some flats must NOT be remapped to encore, since we remap them as we cache them for ease, adding a toggle here seems wise. GLMapTexture_t *HWR_GetTexture(INT32 tex, boolean noencore); diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index f4c95a9e9..ce1e6fa77 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -2803,7 +2803,7 @@ static void HWR_AddPolyObjectPlanes(void) } else { - HWR_GetFlat(levelflats[polyobjsector->floorpic].lumpnum, R_NoEncore(polyobjsector, false), true); + HWR_GetFlat(levelflats[polyobjsector->floorpic].lumpnum, R_NoEncore(polyobjsector, false)); HWR_RenderPolyObjectPlane(po_ptrs[i], false, polyobjsector->floorheight, PF_Occlude, (light == -1 ? gl_frontsector->lightlevel : *gl_frontsector->lightlist[light].lightlevel), levelflats[polyobjsector->floorpic].lumpnum, polyobjsector, 255, (light == -1 ? gl_frontsector->extra_colormap : gl_frontsector->lightlist[light].extra_colormap)); @@ -2826,7 +2826,7 @@ static void HWR_AddPolyObjectPlanes(void) } else { - HWR_GetFlat(levelflats[polyobjsector->ceilingpic].lumpnum, R_NoEncore(polyobjsector, true), true); + HWR_GetFlat(levelflats[polyobjsector->ceilingpic].lumpnum, R_NoEncore(polyobjsector, true)); HWR_RenderPolyObjectPlane(po_ptrs[i], true, polyobjsector->ceilingheight, PF_Occlude, (light == -1 ? gl_frontsector->lightlevel : *gl_frontsector->lightlist[light].lightlevel), levelflats[polyobjsector->ceilingpic].lumpnum, polyobjsector, 255, (light == -1 ? gl_frontsector->extra_colormap : gl_frontsector->lightlist[light].extra_colormap)); @@ -2999,7 +2999,7 @@ static void HWR_Subsector(size_t num) { if (sub->validcount != validcount) { - HWR_GetFlat(levelflats[gl_frontsector->floorpic].lumpnum, R_NoEncore(gl_frontsector, false), true); + HWR_GetFlat(levelflats[gl_frontsector->floorpic].lumpnum, R_NoEncore(gl_frontsector, false)); HWR_RenderPlane(sub, &extrasubsectors[num], false, // Hack to make things continue to work around slopes. locFloorHeight == cullFloorHeight ? locFloorHeight : gl_frontsector->floorheight, @@ -3015,7 +3015,7 @@ static void HWR_Subsector(size_t num) { if (sub->validcount != validcount) { - HWR_GetFlat(levelflats[gl_frontsector->ceilingpic].lumpnum, R_NoEncore(gl_frontsector, true), true); + HWR_GetFlat(levelflats[gl_frontsector->ceilingpic].lumpnum, R_NoEncore(gl_frontsector, true)); HWR_RenderPlane(sub, &extrasubsectors[num], true, // Hack to make things continue to work around slopes. locCeilingHeight == cullCeilingHeight ? locCeilingHeight : gl_frontsector->ceilingheight, @@ -3085,7 +3085,7 @@ static void HWR_Subsector(size_t num) } else { - HWR_GetFlat(levelflats[*rover->bottompic].lumpnum, R_NoEncore(gl_frontsector, false), true); + HWR_GetFlat(levelflats[*rover->bottompic].lumpnum, R_NoEncore(gl_frontsector, false)); light = R_GetPlaneLight(gl_frontsector, centerHeight, viewz < bottomCullHeight ? true : false); HWR_RenderPlane(sub, &extrasubsectors[num], false, *rover->bottomheight, HWR_RippleBlend(gl_frontsector, rover, false)|PF_Occlude, *gl_frontsector->lightlist[light].lightlevel, levelflats[*rover->bottompic].lumpnum, @@ -3131,7 +3131,7 @@ static void HWR_Subsector(size_t num) } else { - HWR_GetFlat(levelflats[*rover->toppic].lumpnum, R_NoEncore(gl_frontsector, true), true); + HWR_GetFlat(levelflats[*rover->toppic].lumpnum, R_NoEncore(gl_frontsector, true)); light = R_GetPlaneLight(gl_frontsector, centerHeight, viewz < topCullHeight ? true : false); HWR_RenderPlane(sub, &extrasubsectors[num], true, *rover->topheight, HWR_RippleBlend(gl_frontsector, rover, false)|PF_Occlude, *gl_frontsector->lightlist[light].lightlevel, levelflats[*rover->toppic].lumpnum, @@ -4398,7 +4398,7 @@ static void HWR_RenderDrawNodes(void) gl_frontsector = NULL; if (!(plane->blend & PF_NoTexture)) - HWR_GetFlat(plane->lumpnum, R_NoEncore(plane->FOFSector, plane->isceiling), plane->alpha == 255); + HWR_GetFlat(plane->lumpnum, R_NoEncore(plane->FOFSector, plane->isceiling)); HWR_RenderPlane(NULL, plane->xsub, plane->isceiling, plane->fixedheight, plane->blend, plane->lightlevel, plane->lumpnum, plane->FOFSector, plane->alpha, plane->planecolormap); @@ -4411,7 +4411,7 @@ static void HWR_RenderDrawNodes(void) gl_frontsector = NULL; if (!(polyplane->blend & PF_NoTexture)) - HWR_GetFlat(polyplane->lumpnum, R_NoEncore(polyplane->FOFSector, polyplane->isceiling), polyplane->alpha == 255); + HWR_GetFlat(polyplane->lumpnum, R_NoEncore(polyplane->FOFSector, polyplane->isceiling)); HWR_RenderPolyObjectPlane(polyplane->polysector, polyplane->isceiling, polyplane->fixedheight, polyplane->blend, polyplane->lightlevel, polyplane->lumpnum, polyplane->FOFSector, polyplane->alpha, polyplane->planecolormap);