optimize HWR_AddLine and HWR_ProcessSeg

This commit is contained in:
Alug committed 2024-03-13 08:32:39 +01:00
1 parent 06acf6554d
commit 22f16c1d27
1 file changed
+109 -80
+109 -80
View File
@@ -1328,6 +1328,88 @@ void HWR_DrawSkyWall(FOutVector *wallVerts, FSurfaceInfo *Surf)
// PF_Occlude is set in HWR_ProjectWall to draw into the depth buffer
}
// Returns true if the midtexture is visible, and false if... it isn't...
static boolean HWR_BlendMidtextureSurface(FSurfaceInfo *pSurf)
{
FUINT blendmode = 0;
pSurf->PolyColor.s.alpha = 0xFF;
if (!gr_curline->polyseg)
{
// set alpha for transparent walls
switch (gr_linedef->special)
{
case 900:
blendmode = HWR_TranstableToAlpha(tr_trans10, pSurf);
break;
case 901:
blendmode = HWR_TranstableToAlpha(tr_trans20, pSurf);
break;
case 902:
blendmode = HWR_TranstableToAlpha(tr_trans30, pSurf);
break;
case 903:
blendmode = HWR_TranstableToAlpha(tr_trans40, pSurf);
break;
case 904:
blendmode = HWR_TranstableToAlpha(tr_trans50, pSurf);
break;
case 905:
blendmode = HWR_TranstableToAlpha(tr_trans60, pSurf);
break;
case 906:
blendmode = HWR_TranstableToAlpha(tr_trans70, pSurf);
break;
case 907:
blendmode = HWR_TranstableToAlpha(tr_trans80, pSurf);
break;
case 908:
blendmode = HWR_TranstableToAlpha(tr_trans90, pSurf);
break;
// Translucent
case 102:
case 121:
case 123:
case 124:
case 125:
case 141:
case 142:
case 144:
case 145:
case 174:
case 175:
case 192:
case 195:
case 221:
case 253:
case 256:
blendmode = PF_Translucent;
break;
default:
blendmode = PF_Masked;
break;
}
}
else if (gr_curline->polyseg->translucency > 0)
{
// Polyobject translucency is shared between all of its lines
if (gr_curline->polyseg->translucency >= NUMTRANSMAPS) // wall not drawn
return false;
//Surf.PolyColor.s.alpha = 0x00; // This shouldn't draw anything regardless of blendmode
//blendmode = PF_Masked;
else
blendmode = HWR_TranstableToAlpha(gr_curline->polyseg->translucency, pSurf);
}
if (blendmode != PF_Masked && pSurf->PolyColor.s.alpha == 0x00)
return false;
pSurf->PolyFlags = blendmode;
return true;
}
//
// HWR_ProcessSeg
// A portion or all of a wall segment will be drawn, from startfrac to endfrac,
@@ -1346,9 +1428,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom
fixed_t worldhighslope = 0, worldlowslope = 0;
fixed_t v1x, v1y, v2x, v2y;
GLMapTexture_t *grTex = NULL;
float cliplow = 0.0f, cliphigh = 0.0f;
INT32 gr_midtexture;
fixed_t h, l; // 3D sides and 2s middle textures
fixed_t hS, lS;
@@ -1410,11 +1490,9 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom
wallVerts[2].z = wallVerts[1].z = ve.y;
// x offset the texture
{
fixed_t texturehpeg = gr_sidedef->textureoffset + gr_curline->offset;
cliplow = (float)texturehpeg;
cliphigh = (float)(texturehpeg + (gr_curline->flength*FRACUNIT));
}
fixed_t texturehpeg = gr_sidedef->textureoffset + gr_curline->offset;
cliplow = (float)texturehpeg;
cliphigh = (float)(texturehpeg + (gr_curline->flength*FRACUNIT));
if (HWR_ShouldUsePaletteRendering())
{
@@ -1431,13 +1509,15 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom
if (gr_linedef->flags & ML_TFERLINE)
noencore = true;
if (gr_frontsector)
Surf.PolyColor.s.alpha = 255;
Surf.PolyColor.s.alpha = 255;
INT32 gr_midtexture = R_GetTextureNum(gr_sidedef->midtexture);
GLMapTexture_t *grTex = NULL;
// two sided line
if (gr_backsector)
{
INT32 gr_toptexture, gr_bottomtexture;
// two sided line
SLOPEPARAMS(gr_backsector->c_slope, worldhigh, worldhighslope, gr_backsector->ceilingheight)
SLOPEPARAMS(gr_backsector->f_slope, worldlow, worldlowslope, gr_backsector->floorheight)
@@ -1656,8 +1736,8 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom
else
HWR_ProjectWall(wallVerts, &Surf, PF_Masked, lightnum, colormap);
}
gr_midtexture = R_GetTextureNum(gr_sidedef->midtexture);
if (gr_midtexture || gr_portal == GRPORTAL_STENCIL || gr_portal == GRPORTAL_DEPTH || gl_drawing_stencil)
if ((gr_midtexture && HWR_BlendMidtextureSurface(&Surf)) || gr_portal == GRPORTAL_STENCIL || gr_portal == GRPORTAL_DEPTH || gl_drawing_stencil)
{
sector_t *front, *back;
INT32 repeats;
@@ -1876,72 +1956,8 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom
}
}
// set alpha for transparent walls (new boom and legacy linedef types)
FBITFIELD blendmode;
switch (gr_linedef->special)
{
case 900:
blendmode = HWR_TranstableToAlpha(tr_trans10, &Surf);
break;
case 901:
blendmode = HWR_TranstableToAlpha(tr_trans20, &Surf);
break;
case 902:
blendmode = HWR_TranstableToAlpha(tr_trans30, &Surf);
break;
case 903:
blendmode = HWR_TranstableToAlpha(tr_trans40, &Surf);
break;
case 904:
blendmode = HWR_TranstableToAlpha(tr_trans50, &Surf);
break;
case 905:
blendmode = HWR_TranstableToAlpha(tr_trans60, &Surf);
break;
case 906:
blendmode = HWR_TranstableToAlpha(tr_trans70, &Surf);
break;
case 907:
blendmode = HWR_TranstableToAlpha(tr_trans80, &Surf);
break;
case 908:
blendmode = HWR_TranstableToAlpha(tr_trans90, &Surf);
break;
// Translucent
case 102:
case 121:
case 123:
case 124:
case 125:
case 141:
case 142:
case 144:
case 145:
case 174:
case 175:
case 192:
case 195:
case 221:
case 253:
case 256:
blendmode = PF_Translucent;
break;
default:
blendmode = PF_Masked;
break;
}
if (gr_curline->polyseg && gr_curline->polyseg->translucency > 0)
{
if (gr_curline->polyseg->translucency >= NUMTRANSMAPS) // wall not drawn
{
Surf.PolyColor.s.alpha = 0x00; // This shouldn't draw anything regardless of blendmode
blendmode = PF_Masked;
}
else
blendmode = HWR_TranstableToAlpha(gr_curline->polyseg->translucency, &Surf);
}
// TODO: Actually use the surface's flags so that I don't have to do this
FUINT blendmode = Surf.PolyFlags;
// Render midtextures on two-sided lines with a z-buffer offset.
// This will cause the midtexture appear on top, if a FOF overlaps with it.
@@ -1964,7 +1980,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom
else
{
// Single sided line... Deal only with the middletexture (if one exists)
gr_midtexture = R_GetTextureNum(gr_sidedef->midtexture);
if (gr_midtexture && gr_linedef->special != HORIZONSPECIAL) // Ignore horizon line for OGL
{
{
@@ -2602,7 +2618,7 @@ static void HWR_AddLine(seg_t *line)
checkforemptylines = true;
gr_backsector = line->backsector;
// do an extra culling check when rendering portals
// check if any line vertex is on the viewable side of the portal target line
// if not, the line can be culled.
@@ -2664,6 +2680,19 @@ doaddline:
else
{
gr_backsector = R_FakeFlat(gr_backsector, &tempsec, NULL, NULL, true);
if ((gr_backsector->ceilingpic == skyflatnum && gr_frontsector->ceilingpic == skyflatnum) && (gr_backsector->floorpic == skyflatnum && gr_frontsector->floorpic == skyflatnum)) // everything's sky? let's save us a bit of time then
{
if (!line->polyseg &&
!line->sidedef->midtexture
&& ((!gr_frontsector->ffloors && !gr_backsector->ffloors)
|| gr_frontsector->tag == gr_backsector->tag))
return; // line is empty, don't even bother
// treat like wide open window instead
HWR_ProcessSeg(); // Doesn't need arguments because they're defined globally :D
return;
}
if (CheckClip(gr_frontsector, gr_backsector))
{
gld_clipper_SafeAddClipRange(angle2, angle1);