From 5c48744842922fd24f574797a7c8fa254c10bd7f Mon Sep 17 00:00:00 2001 From: Oni Date: Sat, 13 Jan 2024 00:33:50 +0000 Subject: [PATCH] Merge branch 'templated-drawing' into 'master' Use C++ templates for DrawColumn/Span See merge request KartKrew/Kart!1728 --- src/r_defs.h | 1 + src/r_draw.h | 1 + src/r_draw_column.cpp | 30 ++++++++++++++++++++++++------ src/r_draw_span.cpp | 2 +- src/r_plane.cpp | 3 +++ src/r_segs.cpp | 22 ++++++++++++++++++++-- src/r_things.cpp | 2 ++ src/screen.c | 5 +++++ src/screen.h | 11 ----------- 9 files changed, 57 insertions(+), 20 deletions(-) diff --git a/src/r_defs.h b/src/r_defs.h index 304641508..1f9bae38f 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -1079,6 +1079,7 @@ typedef struct //Fix TUTIFRUTI INT32 texheight; + INT32 sourcelength; UINT8 r8_flatcolor; } drawcolumndata_t; diff --git a/src/r_draw.h b/src/r_draw.h index 29d923e92..7a070ccdd 100644 --- a/src/r_draw.h +++ b/src/r_draw.h @@ -103,6 +103,7 @@ enum SPANDRAWFUNC_SPLAT, SPANDRAWFUNC_TRANSSPLAT, SPANDRAWFUNC_TILTEDSPLAT, + SPANDRAWFUNC_TILTEDTRANSSPLAT, SPANDRAWFUNC_SPRITE, SPANDRAWFUNC_TRANSSPRITE, diff --git a/src/r_draw_column.cpp b/src/r_draw_column.cpp index 93f6b8a8d..b9f3b2cbd 100644 --- a/src/r_draw_column.cpp +++ b/src/r_draw_column.cpp @@ -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(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(dc, dest, CLAMP(frac >> FRACBITS, npow2min, npow2max)); dest += vid.width; diff --git a/src/r_draw_span.cpp b/src/r_draw_span.cpp index bd7d2cc41..c002f72b7 100644 --- a/src/r_draw_span.cpp +++ b/src/r_draw_span.cpp @@ -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(ds, dsrc, ds->colormap, bit); + dest[i] = R_DrawSpanPixel(ds, &dsrc[i], ds->colormap, bit); xposition += xstep; yposition += ystep; diff --git a/src/r_plane.cpp b/src/r_plane.cpp index 07f87b066..1bbf0c538 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -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; diff --git a/src/r_segs.cpp b/src/r_segs.cpp index cf5da0956..a4373f1c6 100644 --- a/src/r_segs.cpp +++ b/src/r_segs.cpp @@ -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(&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; diff --git a/src/r_things.cpp b/src/r_things.cpp index e1c427aee..b721ef52a 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -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(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; diff --git a/src/screen.c b/src/screen.c index ff3d933bf..dfb8213cb 100644 --- a/src/screen.c +++ b/src/screen.c @@ -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; diff --git a/src/screen.h b/src/screen.h index 28aac4816..8ae4743ad 100644 --- a/src/screen.h +++ b/src/screen.h @@ -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 // ----------------