Merge branch 'templated-drawing' into 'master'

Use C++ templates for DrawColumn/Span

See merge request KartKrew/Kart!1728
This commit is contained in:
Oni 2024-01-13 00:33:50 +00:00 committed by NepDisk
parent 917b549f46
commit 5c48744842
9 changed files with 57 additions and 20 deletions

View file

@ -1079,6 +1079,7 @@ typedef struct
//Fix TUTIFRUTI
INT32 texheight;
INT32 sourcelength;
UINT8 r8_flatcolor;
} drawcolumndata_t;

View file

@ -103,6 +103,7 @@ enum
SPANDRAWFUNC_SPLAT,
SPANDRAWFUNC_TRANSSPLAT,
SPANDRAWFUNC_TILTEDSPLAT,
SPANDRAWFUNC_TILTEDTRANSSPLAT,
SPANDRAWFUNC_SPRITE,
SPANDRAWFUNC_TRANSSPRITE,

View file

@ -121,16 +121,16 @@ static void R_DrawColumnTemplate(drawcolumndata_t *dc)
realyh = dc_copy.yh;
// This runs through the lightlist from top to bottom and cuts up the column accordingly.
for (i = 0; i < dc->numlights; i++)
for (i = 0; i < dc_copy.numlights; i++)
{
// If the height of the light is above the column, get the colormap
// anyway because the lighting of the top should be affected.
solid = dc->lightlist[i].flags & FOF_CUTSOLIDS;
height = dc->lightlist[i].height >> LIGHTSCALESHIFT;
solid = dc_copy.lightlist[i].flags & FOF_CUTSOLIDS;
height = dc_copy.lightlist[i].height >> LIGHTSCALESHIFT;
if (solid)
{
bheight = dc->lightlist[i].botheight >> LIGHTSCALESHIFT;
bheight = dc_copy.lightlist[i].botheight >> LIGHTSCALESHIFT;
if (bheight < height)
{
@ -146,7 +146,7 @@ static void R_DrawColumnTemplate(drawcolumndata_t *dc)
if (height <= dc_copy.yl)
{
dc_copy.colormap = dc->lightlist[i].rcolormap;
dc_copy.colormap = dc_copy.lightlist[i].rcolormap;
dc_copy.fullbright = colormaps;
if (encoremap)
@ -202,6 +202,8 @@ static void R_DrawColumnTemplate(drawcolumndata_t *dc)
fixed_t fracstep;
fixed_t frac;
INT32 heightmask;
INT32 npow2min;
INT32 npow2max;
// Framebuffer destination address.
// Use ylookup LUT to avoid multiply with ScreenWidth.
@ -221,6 +223,19 @@ static void R_DrawColumnTemplate(drawcolumndata_t *dc)
// This is as fast as it gets.
heightmask = dc->texheight-1;
if (dc->sourcelength <= 0)
{
// Note: we need to unconditionally clamp in npow2 draw loop to avoid a CPU branch
// This is to just render it effectively the identity function.
npow2min = INT32_MIN;
npow2max = INT32_MAX;
}
else
{
npow2min = -1;
npow2max = dc->sourcelength;
}
if (dc->texheight & heightmask) // not a power of 2 -- killough
{
heightmask++;
@ -246,7 +261,10 @@ static void R_DrawColumnTemplate(drawcolumndata_t *dc)
// Re-map color indices from wall texture column
// using a lighting/special effects LUT.
// heightmask is the Tutti-Frutti fix
*dest = R_DrawColumnPixel<Type>(dc, dest, frac >> FRACBITS);
// -1 is the lower clamp bound because column posts have a "safe" byte before the real data
// and a few bytes after as well
*dest = R_DrawColumnPixel<Type>(dc, dest, CLAMP(frac >> FRACBITS, npow2min, npow2max));
dest += vid.width;

View file

@ -194,7 +194,7 @@ static void R_DrawSpanTemplate(drawspandata_t* ds)
{
bit = (((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift);
dest[i] = R_DrawSpanPixel<Type>(ds, dsrc, ds->colormap, bit);
dest[i] = R_DrawSpanPixel<Type>(ds, &dsrc[i], ds->colormap, bit);
xposition += xstep;
yposition += ystep;

View file

@ -1200,6 +1200,9 @@ void R_DrawSinglePlane(drawspandata_t *ds, visplane_t *pl, boolean allow_paralle
case SPANDRAWFUNC_SPLAT:
spanfunctype = SPANDRAWFUNC_TILTEDSPLAT;
break;
case SPANDRAWFUNC_TRANSSPLAT:
spanfunctype = SPANDRAWFUNC_TILTEDTRANSSPLAT;
break;
case SPANDRAWFUNC_FOG:
spanfunctype = SPANDRAWFUNC_TILTEDFOG;
break;

View file

@ -130,6 +130,7 @@ static void R_Render2sidedMultiPatchColumn(drawcolumndata_t* dc, column_t *colum
if (dc->yl <= dc->yh && dc->yh < vid.height && dc->yh > 0)
{
dc->source = (UINT8 *)column + 3;
dc->sourcelength = 0;
if (brightmap != NULL)
{
dc->brightmap = (UINT8 *)brightmap + 3;
@ -137,13 +138,29 @@ static void R_Render2sidedMultiPatchColumn(drawcolumndata_t* dc, column_t *colum
drawcolumndata_t dc_copy = *dc;
coldrawfunc_t* colfunccopy = colfunc;
// FIXME: do something better to look these up WITHOUT affecting global state...
if (R_CheckColumnFunc(BASEDRAWFUNC) == true)
{
colfunccopy = colfuncs[COLDRAWFUNC_TWOSMULTIPATCH];
if (brightmap != NULL)
{
colfunccopy = colfuncs_bm[COLDRAWFUNC_TWOSMULTIPATCH];
}
else
{
colfunccopy = colfuncs[COLDRAWFUNC_TWOSMULTIPATCH];
}
}
else if (R_CheckColumnFunc(COLDRAWFUNC_FUZZY) == true)
{
colfunccopy = colfuncs[COLDRAWFUNC_TWOSMULTIPATCHTRANS];
if (brightmap != NULL)
{
colfunccopy = colfuncs_bm[COLDRAWFUNC_TWOSMULTIPATCHTRANS];
}
else
{
colfunccopy = colfuncs[COLDRAWFUNC_TWOSMULTIPATCHTRANS];
}
}
colfunccopy(const_cast<drawcolumndata_t*>(&dc_copy));
@ -1333,6 +1350,7 @@ static void R_DrawWallColumn(drawcolumndata_t* dc, INT32 yl, INT32 yh, fixed_t m
dc->source = R_GetColumn(texture, texturecolumn);
dc->brightmap = (brightmapped ? R_GetBrightmapColumn(texture, texturecolumn) : NULL);
dc->texheight = textureheight[texture] >> FRACBITS;
dc->sourcelength = 0;
R_SetColumnFunc(colfunctype, dc->brightmap != NULL);
coldrawfunc_t* colfunccopy = colfunc;
drawcolumndata_t dc_copy = *dc;

View file

@ -688,6 +688,7 @@ void R_DrawMaskedColumn(drawcolumndata_t* dc, column_t *column, column_t *bright
if (dc->yl <= dc->yh && dc->yh > 0)
{
dc->source = (UINT8 *)column + 3;
dc->sourcelength = column->length;
if (brightmap != NULL)
{
dc->brightmap = (UINT8 *)brightmap + 3;
@ -773,6 +774,7 @@ void R_DrawFlippedMaskedColumn(drawcolumndata_t* dc, column_t *column, column_t
if (dc->yl <= dc->yh && dc->yh > 0)
{
dc->source = static_cast<UINT8*>(ZZ_Alloc(column->length));
dc->sourcelength = column->length;
for (s = (UINT8 *)column+2+column->length, d = dc->source; d < dc->source+column->length; --s)
*d++ = *s;

View file

@ -125,6 +125,7 @@ void SCR_SetDrawFuncs(void)
spanfuncs[SPANDRAWFUNC_SPLAT] = R_DrawSplat;
spanfuncs[SPANDRAWFUNC_TRANSSPLAT] = R_DrawTranslucentSplat;
spanfuncs[SPANDRAWFUNC_TILTEDSPLAT] = R_DrawSplat_Tilted;
spanfuncs[SPANDRAWFUNC_TILTEDTRANSSPLAT] = R_DrawTranslucentSplat_Tilted;
spanfuncs[SPANDRAWFUNC_SPRITE] = R_DrawFloorSprite;
spanfuncs[SPANDRAWFUNC_TRANSSPRITE] = R_DrawTranslucentFloorSprite;
spanfuncs[SPANDRAWFUNC_TILTEDSPRITE] = R_DrawFloorSprite_Tilted;
@ -141,6 +142,7 @@ void SCR_SetDrawFuncs(void)
spanfuncs_bm[SPANDRAWFUNC_SPLAT] = R_DrawSplat_Brightmap;
spanfuncs_bm[SPANDRAWFUNC_TRANSSPLAT] = R_DrawTranslucentSplat_Brightmap;
spanfuncs_bm[SPANDRAWFUNC_TILTEDSPLAT] = R_DrawSplat_Tilted_Brightmap;
spanfuncs_bm[SPANDRAWFUNC_TILTEDTRANSSPLAT] = R_DrawTranslucentSplat_Tilted_Brightmap;
spanfuncs_bm[SPANDRAWFUNC_SPRITE] = R_DrawFloorSprite_Brightmap;
spanfuncs_bm[SPANDRAWFUNC_TRANSSPRITE] = R_DrawTranslucentFloorSprite_Brightmap;
spanfuncs_bm[SPANDRAWFUNC_TILTEDSPRITE] = R_DrawFloorSprite_Tilted_Brightmap;
@ -158,6 +160,7 @@ void SCR_SetDrawFuncs(void)
spanfuncs_npo2[SPANDRAWFUNC_SPLAT] = R_DrawSplat_NPO2;
spanfuncs_npo2[SPANDRAWFUNC_TRANSSPLAT] = R_DrawTranslucentSplat_NPO2;
spanfuncs_npo2[SPANDRAWFUNC_TILTEDSPLAT] = R_DrawSplat_Tilted_NPO2;
spanfuncs_npo2[SPANDRAWFUNC_TILTEDTRANSSPLAT] = R_DrawTranslucentSplat_Tilted_NPO2;
spanfuncs_npo2[SPANDRAWFUNC_SPRITE] = R_DrawFloorSprite_NPO2;
spanfuncs_npo2[SPANDRAWFUNC_TRANSSPRITE] = R_DrawTranslucentFloorSprite_NPO2;
spanfuncs_npo2[SPANDRAWFUNC_TILTEDSPRITE] = R_DrawFloorSprite_Tilted_NPO2;
@ -174,6 +177,7 @@ void SCR_SetDrawFuncs(void)
spanfuncs_bm_npo2[SPANDRAWFUNC_SPLAT] = R_DrawSplat_Brightmap_NPO2;
spanfuncs_bm_npo2[SPANDRAWFUNC_TRANSSPLAT] = R_DrawTranslucentSplat_Brightmap_NPO2;
spanfuncs_bm_npo2[SPANDRAWFUNC_TILTEDSPLAT] = R_DrawSplat_Tilted_Brightmap_NPO2;
spanfuncs_bm_npo2[SPANDRAWFUNC_TILTEDTRANSSPLAT] = R_DrawTranslucentSplat_Tilted_Brightmap_NPO2;
spanfuncs_bm_npo2[SPANDRAWFUNC_SPRITE] = R_DrawFloorSprite_Brightmap_NPO2;
spanfuncs_bm_npo2[SPANDRAWFUNC_TRANSSPRITE] = R_DrawTranslucentFloorSprite_Brightmap_NPO2;
spanfuncs_bm_npo2[SPANDRAWFUNC_TILTEDSPRITE] = R_DrawFloorSprite_Tilted_Brightmap_NPO2;
@ -191,6 +195,7 @@ void SCR_SetDrawFuncs(void)
spanfuncs_flat[SPANDRAWFUNC_SPLAT] = R_DrawSpan_Flat;
spanfuncs_flat[SPANDRAWFUNC_TRANSSPLAT] = R_DrawSpan_Flat;
spanfuncs_flat[SPANDRAWFUNC_TILTEDSPLAT] = R_DrawTiltedSpan_Flat;
spanfuncs_flat[SPANDRAWFUNC_TILTEDTRANSSPLAT] = R_DrawTiltedSpan_Flat;
spanfuncs_flat[SPANDRAWFUNC_SPRITE] = R_DrawSpan_Flat;
spanfuncs_flat[SPANDRAWFUNC_TRANSSPRITE] = R_DrawSpan_Flat;
spanfuncs_flat[SPANDRAWFUNC_TILTEDSPRITE] = R_DrawTiltedSpan_Flat;

View file

@ -116,17 +116,6 @@ struct vmode_t
#define NUMSPECIALMODES 4
extern vmode_t specialmodes[NUMSPECIALMODES];
// -----
// CPUID
// -----
extern boolean R_ASM;
extern boolean R_486;
extern boolean R_586;
extern boolean R_MMX;
extern boolean R_3DNow;
extern boolean R_MMXExt;
extern boolean R_SSE2;
// ----------------
// screen variables
// ----------------