Cleanup HWR_RenderExtraTexture a bit

This commit is contained in:
Lactozilla 2024-01-24 02:17:59 -03:00
parent e448e60a44
commit a64d107cda

View file

@ -1330,29 +1330,31 @@ static void HWR_GetExtraTextureCoords(unsigned which, fixed_t *top, fixed_t *bot
// Draws an extra texture (WIP) // Draws an extra texture (WIP)
// This function is huge and lengthy (sorry) as it may need to split a wall in half // This function is huge and lengthy (sorry) as it may need to split a wall in half
static void HWR_RenderExtraTexture(unsigned which, v2d_t vs, v2d_t ve, fixed_t texturehpeg, fixed_t worldtop, fixed_t worldbottom, fixed_t worldhigh, fixed_t worldlow, fixed_t worldtopslope, fixed_t worldbottomslope, fixed_t worldhighslope, fixed_t worldlowslope, UINT32 lightnum, FOutVector *inWallVerts) static void HWR_RenderExtraTexture(unsigned which, v2d_t vs, v2d_t ve, float xcliplow, float xcliphigh, UINT32 lightnum)
{ {
INT32 texnum = R_GetTextureNum(gl_sidedef->overlays[which].texture); INT32 texnum = R_GetTextureNum(gl_sidedef->overlays[which].texture);
if (texnum <= 0 || texnum >= numtextures) if (texnum <= 0 || texnum >= numtextures)
return; return;
FOutVector wallVerts[4]; fixed_t v1x = FloatToFixed(vs.x);
fixed_t v1y = FloatToFixed(vs.y);
UINT8 intersected = 0; fixed_t v2x = FloatToFixed(ve.x);
fixed_t v2y = FloatToFixed(ve.y);
fixed_t v1x = 0, v1y = 0, v2x = 0, v2y = 0;
float ptx = 0.0f, pty = 0.0f;
fixed_t cliptop = 0, clipbottom = 0, cliphigh = 0, cliplow = 0;
fixed_t cliptopslope = 0, clipbottomslope = 0, cliphighslope = 0, cliplowslope = 0;
sector_t *back = gl_backsector ? gl_backsector : gl_frontsector; sector_t *back = gl_backsector ? gl_backsector : gl_frontsector;
FSurfaceInfo Surf; fixed_t worldtop = P_GetSectorCeilingZAt(gl_frontsector, v1x, v1y);
Surf.PolyColor.s.alpha = 255; fixed_t worldtopslope = P_GetSectorCeilingZAt(gl_frontsector, v2x, v2y);
Surf.PolyFlags = PF_Masked; fixed_t worldbottom = P_GetSectorFloorZAt(gl_frontsector, v1x, v1y);
fixed_t worldbottomslope = P_GetSectorFloorZAt(gl_frontsector, v2x, v2y);
fixed_t worldhigh = P_GetSectorCeilingZAt(back, v1x, v1y);
fixed_t worldhighslope = P_GetSectorCeilingZAt(back, v2x, v2y);
fixed_t worldlow = P_GetSectorFloorZAt(back, v1x, v1y);
fixed_t worldlowslope = P_GetSectorFloorZAt(back, v2x, v2y);
fixed_t texheight = FixedDiv(textureheight[texnum], abs(gl_sidedef->overlays[which].scaley)); fixed_t texheight = FixedDiv(textureheight[texnum], abs(gl_sidedef->overlays[which].scaley));
INT32 repeats; INT32 repeats;
if (gl_sidedef->flags & GET_SIDEFLAG_EDGEWRAP(which)) if (gl_sidedef->flags & GET_SIDEFLAG_EDGEWRAP(which))
@ -1364,23 +1366,23 @@ static void HWR_RenderExtraTexture(unsigned which, v2d_t vs, v2d_t ve, fixed_t t
if (IS_TOP_EDGE_TEXTURE(which)) if (IS_TOP_EDGE_TEXTURE(which))
{ {
high = max( high = max(
P_GetSectorCeilingZAt(gl_frontsector, gl_curline->v1->x, gl_curline->v1->y), P_GetSectorCeilingZAt(gl_frontsector, v1x, v1y),
P_GetSectorCeilingZAt(gl_frontsector, gl_curline->v2->x, gl_curline->v2->y) P_GetSectorCeilingZAt(gl_frontsector, v2x, v2y)
); );
low = min( low = min(
P_GetSectorCeilingZAt(gl_backsector, gl_curline->v1->x, gl_curline->v1->y), P_GetSectorCeilingZAt(gl_backsector, v1x, v1y),
P_GetSectorCeilingZAt(gl_backsector, gl_curline->v2->x, gl_curline->v2->y) P_GetSectorCeilingZAt(gl_backsector, v2x, v2y)
); );
} }
else else
{ {
high = max( high = max(
P_GetSectorFloorZAt(gl_frontsector, gl_curline->v1->x, gl_curline->v1->y), P_GetSectorFloorZAt(gl_frontsector, v1x, v1y),
P_GetSectorFloorZAt(gl_frontsector, gl_curline->v2->x, gl_curline->v2->y) P_GetSectorFloorZAt(gl_frontsector, v2x, v2y)
); );
low = min( low = min(
P_GetSectorFloorZAt(gl_backsector, gl_curline->v1->x, gl_curline->v1->y), P_GetSectorFloorZAt(gl_backsector, v1x, v1y),
P_GetSectorFloorZAt(gl_backsector, gl_curline->v2->x, gl_curline->v2->y) P_GetSectorFloorZAt(gl_backsector, v2x, v2y)
); );
} }
} }
@ -1407,8 +1409,7 @@ static void HWR_RenderExtraTexture(unsigned which, v2d_t vs, v2d_t ve, fixed_t t
float xscale = FixedToFloat(gl_sidedef->overlays[which].scalex); float xscale = FixedToFloat(gl_sidedef->overlays[which].scalex);
float yscale = FixedToFloat(gl_sidedef->overlays[which].scaley); float yscale = FixedToFloat(gl_sidedef->overlays[which].scaley);
float xcliplow = (float)texturehpeg; float xcliplowbase = xcliplow;
float xcliphigh = (float)(texturehpeg + (gl_curline->flength*FRACUNIT));
float xclipoffset = 0.0f; float xclipoffset = 0.0f;
fixed_t polytop, polybottom; fixed_t polytop, polybottom;
@ -1444,9 +1445,17 @@ static void HWR_RenderExtraTexture(unsigned which, v2d_t vs, v2d_t ve, fixed_t t
fixed_t hS = polytopslope; fixed_t hS = polytopslope;
fixed_t lS = polybottomslope; fixed_t lS = polybottomslope;
memcpy(wallVerts, inWallVerts, sizeof(wallVerts)); FOutVector wallVerts[4];
wallVerts[0].x = wallVerts[3].x = vs.x;
wallVerts[0].z = wallVerts[3].z = vs.y;
wallVerts[2].x = wallVerts[1].x = ve.x;
wallVerts[2].z = wallVerts[1].z = ve.y;
// If this edge extends over a wall that is sloped, it needs to be split // If this edge extends over a wall that is sloped, it needs to be split
UINT8 intersected = 0;
float ptx = 0.0f, pty = 0.0f;
if (h > highcut || hS > highcutslope || l < lowcut || lS < lowcutslope) if (h > highcut || hS > highcutslope || l < lowcut || lS < lowcutslope)
{ {
float polypos = 0.0f; float polypos = 0.0f;
@ -1566,7 +1575,7 @@ static void HWR_RenderExtraTexture(unsigned which, v2d_t vs, v2d_t ve, fixed_t t
wallVerts[2].z = wallVerts[1].z = pty; wallVerts[2].z = wallVerts[1].z = pty;
xclipoffset = gl_curline->flength * t * FRACUNIT; xclipoffset = gl_curline->flength * t * FRACUNIT;
xcliphigh = (float)(texturehpeg + xclipoffset); xcliphigh = (float)(xcliplow + xclipoffset);
} }
// Left side // Left side
else if (intersected == 2) else if (intersected == 2)
@ -1584,15 +1593,15 @@ static void HWR_RenderExtraTexture(unsigned which, v2d_t vs, v2d_t ve, fixed_t t
} }
// Get new coordinates based on this split // Get new coordinates based on this split
cliptop = P_GetSectorCeilingZAt(gl_frontsector, v1x, v1y); fixed_t cliptop = P_GetSectorCeilingZAt(gl_frontsector, v1x, v1y);
cliptopslope = P_GetSectorCeilingZAt(gl_frontsector, v2x, v2y); fixed_t cliptopslope = P_GetSectorCeilingZAt(gl_frontsector, v2x, v2y);
clipbottom = P_GetSectorFloorZAt(gl_frontsector, v1x, v1y); fixed_t clipbottom = P_GetSectorFloorZAt(gl_frontsector, v1x, v1y);
clipbottomslope = P_GetSectorFloorZAt(gl_frontsector, v2x, v2y); fixed_t clipbottomslope = P_GetSectorFloorZAt(gl_frontsector, v2x, v2y);
cliphigh = P_GetSectorCeilingZAt(back, v1x, v1y); fixed_t cliphigh = P_GetSectorCeilingZAt(back, v1x, v1y);
cliphighslope = P_GetSectorCeilingZAt(back, v2x, v2y); fixed_t cliphighslope = P_GetSectorCeilingZAt(back, v2x, v2y);
cliplow = P_GetSectorFloorZAt(back, v1x, v1y); fixed_t cliplow = P_GetSectorFloorZAt(back, v1x, v1y);
cliplowslope = P_GetSectorFloorZAt(back, v2x, v2y); fixed_t cliplowslope = P_GetSectorFloorZAt(back, v2x, v2y);
HWR_GetExtraTextureCoords(which, &polytop, &polybottom, &polytopslope, &polybottomslope, cliptop, clipbottom, cliphigh, cliplow, cliptopslope, clipbottomslope, cliphighslope, cliplowslope, midtexheight); HWR_GetExtraTextureCoords(which, &polytop, &polybottom, &polytopslope, &polybottomslope, cliptop, clipbottom, cliphigh, cliplow, cliptopslope, clipbottomslope, cliphighslope, cliplowslope, midtexheight);
@ -1643,8 +1652,10 @@ static void HWR_RenderExtraTexture(unsigned which, v2d_t vs, v2d_t ve, fixed_t t
wallVerts[2].y = FIXED_TO_FLOAT(hS); wallVerts[2].y = FIXED_TO_FLOAT(hS);
wallVerts[1].y = FIXED_TO_FLOAT(lS); wallVerts[1].y = FIXED_TO_FLOAT(lS);
// TODO: Actually use the surface's flags so that I don't have to do this FSurfaceInfo Surf;
FUINT blendmode = Surf.PolyFlags | PF_Decal; Surf.PolyColor.s.alpha = 255;
FUINT blendmode = PF_Masked | PF_Decal;
extracolormap_t *colormap = gl_frontsector->extra_colormap; extracolormap_t *colormap = gl_frontsector->extra_colormap;
@ -1653,69 +1664,50 @@ static void HWR_RenderExtraTexture(unsigned which, v2d_t vs, v2d_t ve, fixed_t t
else else
HWR_ProjectWall(wallVerts, &Surf, blendmode, lightnum, colormap); HWR_ProjectWall(wallVerts, &Surf, blendmode, lightnum, colormap);
// Wall wasn't split, stop here
if (!intersected)
return;
// Draw the rest of the wall if it was split // Draw the rest of the wall if it was split
float fv1x, fv1y, fv2x, fv2y;
float flength;
// Right side
if (intersected == 1) if (intersected == 1)
{ {
fv1x = ptx; // Right side
fv1y = pty; vs.x = ptx;
fv2x = ve.x; vs.y = pty;
fv2y = ve.y;
} }
// Left side else if (intersected == 2)
else
{ {
fv1x = vs.x; // Left side
fv1y = vs.y; ve.x = ptx;
fv2x = ptx; ve.y = pty;
fv2y = pty;
} }
else
return;
v1x = FloatToFixed(fv1x); // Redefine the wall X/Y
v1y = FloatToFixed(fv1y); wallVerts[0].x = wallVerts[3].x = vs.x;
v2x = FloatToFixed(fv2x); wallVerts[0].z = wallVerts[3].z = vs.y;
v2y = FloatToFixed(fv2y); wallVerts[2].x = wallVerts[1].x = ve.x;
wallVerts[2].z = wallVerts[1].z = ve.y;
wallVerts[0].x = wallVerts[3].x = fv1x; v1x = FloatToFixed(vs.x);
wallVerts[0].z = wallVerts[3].z = fv1y; v1y = FloatToFixed(vs.y);
wallVerts[2].x = wallVerts[1].x = fv2x; v2x = FloatToFixed(ve.x);
wallVerts[2].z = wallVerts[1].z = fv2y; v2y = FloatToFixed(ve.y);
flength = hypotf(fv2x - fv1x, fv2y - fv1y); worldtop = P_GetSectorCeilingZAt(gl_frontsector, v1x, v1y);
xcliplow = (float)texturehpeg + xclipoffset; worldtopslope = P_GetSectorCeilingZAt(gl_frontsector, v2x, v2y);
xcliphigh = xcliplow + (flength * FRACUNIT); worldbottom = P_GetSectorFloorZAt(gl_frontsector, v1x, v1y);
worldbottomslope = P_GetSectorFloorZAt(gl_frontsector, v2x, v2y);
cliptop = P_GetSectorCeilingZAt(gl_frontsector, v1x, v1y); worldhigh = P_GetSectorCeilingZAt(back, v1x, v1y);
cliptopslope = P_GetSectorCeilingZAt(gl_frontsector, v2x, v2y); worldhighslope = P_GetSectorCeilingZAt(back, v2x, v2y);
clipbottom = P_GetSectorFloorZAt(gl_frontsector, v1x, v1y); worldlow = P_GetSectorFloorZAt(back, v1x, v1y);
clipbottomslope = P_GetSectorFloorZAt(gl_frontsector, v2x, v2y); worldlowslope = P_GetSectorFloorZAt(back, v2x, v2y);
cliphigh = P_GetSectorCeilingZAt(back, v1x, v1y); HWR_GetExtraTextureCoords(which, &polytop, &polybottom, &polytopslope, &polybottomslope, worldtop, worldbottom, worldhigh, worldlow, worldtopslope, worldbottomslope, worldhighslope, worldlowslope, midtexheight);
cliphighslope = P_GetSectorCeilingZAt(back, v2x, v2y);
cliplow = P_GetSectorFloorZAt(back, v1x, v1y);
cliplowslope = P_GetSectorFloorZAt(back, v2x, v2y);
HWR_GetExtraTextureCoords(which, &polytop, &polybottom, &polytopslope, &polybottomslope, cliptop, clipbottom, cliphigh, cliplow, cliptopslope, clipbottomslope, cliphighslope, cliplowslope, midtexheight);
h = min(highcut, polytop); h = min(highcut, polytop);
l = max(polybottom, lowcut); l = max(polybottom, lowcut);
hS = min(highcutslope, polytopslope); hS = min(highcutslope, polytopslope);
lS = max(polybottomslope, lowcutslope); lS = max(polybottomslope, lowcutslope);
#if 0
if (l > highcut)
l = highcut;
if (lS > highcutslope)
lS = highcutslope;
#endif
wallVerts[3].y = FixedToFloat(h); wallVerts[3].y = FixedToFloat(h);
wallVerts[0].y = FixedToFloat(l); wallVerts[0].y = FixedToFloat(l);
wallVerts[2].y = FixedToFloat(hS); wallVerts[2].y = FixedToFloat(hS);
@ -1732,6 +1724,10 @@ static void HWR_RenderExtraTexture(unsigned which, v2d_t vs, v2d_t ve, fixed_t t
texturevpegslope = polytopslope - hS; texturevpegslope = polytopslope - hS;
} }
float flength = hypotf(ve.x - vs.x, ve.y - vs.y);
xcliplow = xcliplowbase + xclipoffset;
xcliphigh = xcliplow + (flength * FRACUNIT);
// Left side // Left side
wallVerts[3].t = texturevpeg * yscale * grTex->scaleY; wallVerts[3].t = texturevpeg * yscale * grTex->scaleY;
wallVerts[0].t = (h - l + texturevpeg) * yscale * grTex->scaleY; wallVerts[0].t = (h - l + texturevpeg) * yscale * grTex->scaleY;
@ -2040,7 +2036,7 @@ static void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom
// Render extra textures // Render extra textures
for (unsigned i = 0; i < NUM_WALL_OVERLAYS; i++) for (unsigned i = 0; i < NUM_WALL_OVERLAYS; i++)
HWR_RenderExtraTexture(i, vs, ve, texturehpeg, worldtop, worldbottom, worldhigh, worldlow, worldtopslope, worldbottomslope, worldhighslope, worldlowslope, lightnum, wallVerts); HWR_RenderExtraTexture(i, vs, ve, cliplow, cliphigh, lightnum);
// Sky culling // Sky culling
// No longer so much a mess as before! // No longer so much a mess as before!
@ -2126,7 +2122,7 @@ static void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom
// Render extra textures // Render extra textures
for (unsigned i = 0; i < NUM_WALL_OVERLAYS; i++) for (unsigned i = 0; i < NUM_WALL_OVERLAYS; i++)
HWR_RenderExtraTexture(i, vs, ve, texturehpeg, worldtop, worldbottom, worldtop, worldbottom, worldtopslope, worldbottomslope, worldtopslope, worldbottomslope, lightnum, wallVerts); HWR_RenderExtraTexture(i, vs, ve, cliplow, cliphigh, lightnum);
if (!gl_curline->polyseg) if (!gl_curline->polyseg)
{ {