Move colfunc family of globals into a DrawerStyle class and localize its usage

This commit is contained in:
Magnus Norddahl 2017-01-28 07:08:59 +01:00
parent f9eb06a22e
commit 5f38b15635
17 changed files with 416 additions and 391 deletions

View File

@ -70,12 +70,6 @@ namespace swrenderer
short zeroarray[MAXWIDTH];
short screenheightarray[MAXWIDTH];
DrawerFunc colfunc;
DrawerFunc basecolfunc;
DrawerFunc fuzzcolfunc;
DrawerFunc transcolfunc;
DrawerFunc spanfunc;
namespace drawerargs
{
int dc_pitch;
@ -160,11 +154,6 @@ namespace swrenderer
active_drawers = &tc_drawers;
else
active_drawers = &pal_drawers;
colfunc = basecolfunc = &SWPixelFormatDrawers::DrawColumn;
fuzzcolfunc = &SWPixelFormatDrawers::DrawFuzzColumn;
transcolfunc = &SWPixelFormatDrawers::DrawTranslatedColumn;
spanfunc = &SWPixelFormatDrawers::DrawSpan;
}
void R_InitShadeMaps()
@ -252,282 +241,6 @@ namespace swrenderer
}
}
namespace
{
bool R_SetBlendFunc(int op, fixed_t fglevel, fixed_t bglevel, int flags)
{
using namespace drawerargs;
// r_drawtrans is a seriously bad thing to turn off. I wonder if I should
// just remove it completely.
if (!r_drawtrans || (op == STYLEOP_Add && fglevel == FRACUNIT && bglevel == 0 && !(flags & STYLEF_InvertSource)))
{
if (flags & STYLEF_ColorIsFixed)
{
colfunc = &SWPixelFormatDrawers::FillColumn;
}
else if (dc_translation == NULL)
{
colfunc = basecolfunc;
}
else
{
colfunc = transcolfunc;
drawer_needs_pal_input = true;
}
return true;
}
if (flags & STYLEF_InvertSource)
{
dc_srcblend = Col2RGB8_Inverse[fglevel >> 10];
dc_destblend = Col2RGB8_LessPrecision[bglevel >> 10];
dc_srcalpha = fglevel;
dc_destalpha = bglevel;
}
else if (op == STYLEOP_Add && fglevel + bglevel <= FRACUNIT)
{
dc_srcblend = Col2RGB8[fglevel >> 10];
dc_destblend = Col2RGB8[bglevel >> 10];
dc_srcalpha = fglevel;
dc_destalpha = bglevel;
}
else
{
dc_srcblend = Col2RGB8_LessPrecision[fglevel >> 10];
dc_destblend = Col2RGB8_LessPrecision[bglevel >> 10];
dc_srcalpha = fglevel;
dc_destalpha = bglevel;
}
switch (op)
{
case STYLEOP_Add:
if (fglevel == 0 && bglevel == FRACUNIT)
{
return false;
}
if (fglevel + bglevel <= FRACUNIT)
{ // Colors won't overflow when added
if (flags & STYLEF_ColorIsFixed)
{
colfunc = &SWPixelFormatDrawers::FillAddColumn;
}
else if (dc_translation == NULL)
{
colfunc = &SWPixelFormatDrawers::DrawAddColumn;
}
else
{
colfunc = &SWPixelFormatDrawers::DrawTranslatedAddColumn;
drawer_needs_pal_input = true;
}
}
else
{ // Colors might overflow when added
if (flags & STYLEF_ColorIsFixed)
{
colfunc = &SWPixelFormatDrawers::FillAddClampColumn;
}
else if (dc_translation == NULL)
{
colfunc = &SWPixelFormatDrawers::DrawAddClampColumn;
}
else
{
colfunc = &SWPixelFormatDrawers::DrawAddClampTranslatedColumn;
drawer_needs_pal_input = true;
}
}
return true;
case STYLEOP_Sub:
if (flags & STYLEF_ColorIsFixed)
{
colfunc = &SWPixelFormatDrawers::FillSubClampColumn;
}
else if (dc_translation == NULL)
{
colfunc = &SWPixelFormatDrawers::DrawSubClampColumn;
}
else
{
colfunc = &SWPixelFormatDrawers::DrawSubClampTranslatedColumn;
drawer_needs_pal_input = true;
}
return true;
case STYLEOP_RevSub:
if (fglevel == 0 && bglevel == FRACUNIT)
{
return false;
}
if (flags & STYLEF_ColorIsFixed)
{
colfunc = &SWPixelFormatDrawers::FillRevSubClampColumn;
}
else if (dc_translation == NULL)
{
colfunc = &SWPixelFormatDrawers::DrawRevSubClampColumn;
}
else
{
colfunc = &SWPixelFormatDrawers::DrawRevSubClampTranslatedColumn;
drawer_needs_pal_input = true;
}
return true;
default:
return false;
}
}
fixed_t GetAlpha(int type, fixed_t alpha)
{
switch (type)
{
case STYLEALPHA_Zero: return 0;
case STYLEALPHA_One: return OPAQUE;
case STYLEALPHA_Src: return alpha;
case STYLEALPHA_InvSrc: return OPAQUE - alpha;
default: return 0;
}
}
}
bool R_SetPatchStyle(FRenderStyle style, fixed_t alpha, int translation, uint32_t color, FDynamicColormap *&basecolormap)
{
using namespace drawerargs;
fixed_t fglevel, bglevel;
drawer_needs_pal_input = false;
style.CheckFuzz();
if (style.BlendOp == STYLEOP_Shadow)
{
style = LegacyRenderStyles[STYLE_TranslucentStencil];
alpha = TRANSLUC33;
color = 0;
}
if (style.Flags & STYLEF_ForceAlpha)
{
alpha = clamp<fixed_t>(alpha, 0, OPAQUE);
}
else if (style.Flags & STYLEF_TransSoulsAlpha)
{
alpha = fixed_t(transsouls * OPAQUE);
}
else if (style.Flags & STYLEF_Alpha1)
{
alpha = FRACUNIT;
}
else
{
alpha = clamp<fixed_t>(alpha, 0, OPAQUE);
}
if (translation != -1)
{
dc_translation = NULL;
if (translation != 0)
{
FRemapTable *table = TranslationToTable(translation);
if (table != NULL && !table->Inactive)
{
if (r_swtruecolor)
dc_translation = (uint8_t*)table->Palette;
else
dc_translation = table->Remap;
}
}
}
// Check for special modes
if (style.BlendOp == STYLEOP_Fuzz)
{
colfunc = fuzzcolfunc;
return true;
}
else if (style == LegacyRenderStyles[STYLE_Shaded])
{
// Shaded drawer only gets 16 levels of alpha because it saves memory.
if ((alpha >>= 12) == 0 || basecolormap == nullptr)
return false;
colfunc = &SWPixelFormatDrawers::DrawShadedColumn;
drawer_needs_pal_input = true;
CameraLight *cameraLight = CameraLight::Instance();
dc_color = cameraLight->fixedcolormap ? cameraLight->fixedcolormap->Maps[APART(color)] : basecolormap->Maps[APART(color)];
basecolormap = &ShadeFakeColormap[16 - alpha];
if (cameraLight->fixedlightlev >= 0 && cameraLight->fixedcolormap == NULL)
{
R_SetColorMapLight(basecolormap, 0, FIXEDLIGHT2SHADE(cameraLight->fixedlightlev));
}
else
{
R_SetColorMapLight(basecolormap, 0, 0);
}
return true;
}
fglevel = GetAlpha(style.SrcAlpha, alpha);
bglevel = GetAlpha(style.DestAlpha, alpha);
if (style.Flags & STYLEF_ColorIsFixed)
{
uint32_t x = fglevel >> 10;
uint32_t r = RPART(color);
uint32_t g = GPART(color);
uint32_t b = BPART(color);
// dc_color is used by the rt_* routines. It is indexed into dc_srcblend.
dc_color = RGB256k.RGB[r >> 2][g >> 2][b >> 2];
if (style.Flags & STYLEF_InvertSource)
{
r = 255 - r;
g = 255 - g;
b = 255 - b;
}
uint32_t alpha = clamp(fglevel >> (FRACBITS - 8), 0, 255);
dc_srccolor_bgra = (alpha << 24) | (r << 16) | (g << 8) | b;
// dc_srccolor is used by the R_Fill* routines. It is premultiplied
// with the alpha.
dc_srccolor = ((((r*x) >> 4) << 20) | ((g*x) >> 4) | ((((b)*x) >> 4) << 10)) & 0x3feffbff;
R_SetColorMapLight(&identitycolormap, 0, 0);
}
if (!R_SetBlendFunc(style.BlendOp, fglevel, bglevel, style.Flags))
{
return false;
}
return true;
}
bool R_SetPatchStyle(FRenderStyle style, float alpha, int translation, uint32_t color, FDynamicColormap *&basecolormap)
{
return R_SetPatchStyle(style, FLOAT2FIXED(alpha), translation, color, basecolormap);
}
DrawerFunc R_GetTransMaskDrawer()
{
if (colfunc == &SWPixelFormatDrawers::DrawAddColumn)
{
return &SWPixelFormatDrawers::DrawWallAddColumn;
}
if (colfunc == &SWPixelFormatDrawers::DrawAddClampColumn)
{
return &SWPixelFormatDrawers::DrawWallAddClampColumn;
}
if (colfunc == &SWPixelFormatDrawers::DrawSubClampColumn)
{
return &SWPixelFormatDrawers::DrawWallSubClampColumn;
}
if (colfunc == &SWPixelFormatDrawers::DrawRevSubClampColumn)
{
return &SWPixelFormatDrawers::DrawWallRevSubClampColumn;
}
return nullptr;
}
void R_SetColorMapLight(FSWColormap *base_colormap, float light, int shade)
{
using namespace drawerargs;
@ -643,14 +356,14 @@ namespace swrenderer
fuzzpos = (fuzzpos + dc_yh - dc_yl + 1) % FUZZTABLE;
}
void R_DrawMaskedColumn(int x, fixed_t iscale, FTexture *tex, fixed_t col, double spryscale, double sprtopscreen, bool sprflipvert, const short *mfloorclip, const short *mceilingclip, bool unmasked)
void DrawerStyle::DrawMaskedColumn(int x, fixed_t iscale, FTexture *tex, fixed_t col, double spryscale, double sprtopscreen, bool sprflipvert, const short *mfloorclip, const short *mceilingclip, bool unmasked)
{
using namespace drawerargs;
// Handle the linear filtered version in a different function to reduce chances of merge conflicts from zdoom.
if (r_swtruecolor && !drawer_needs_pal_input) // To do: add support to R_DrawColumnHoriz_rgba
{
R_DrawMaskedColumnBgra(x, iscale, tex, col, spryscale, sprtopscreen, sprflipvert, mfloorclip, mceilingclip, unmasked);
DrawMaskedColumnBgra(x, iscale, tex, col, spryscale, sprtopscreen, sprflipvert, mfloorclip, mceilingclip, unmasked);
return;
}
@ -722,7 +435,7 @@ namespace swrenderer
}
}
void R_DrawMaskedColumnBgra(int x, fixed_t iscale, FTexture *tex, fixed_t col, double spryscale, double sprtopscreen, bool sprflipvert, const short *mfloorclip, const short *mceilingclip, bool unmasked)
void DrawerStyle::DrawMaskedColumnBgra(int x, fixed_t iscale, FTexture *tex, fixed_t col, double spryscale, double sprtopscreen, bool sprflipvert, const short *mfloorclip, const short *mceilingclip, bool unmasked)
{
using namespace drawerargs;
@ -838,4 +551,335 @@ namespace swrenderer
span++;
}
}
bool DrawerStyle::SetBlendFunc(int op, fixed_t fglevel, fixed_t bglevel, int flags)
{
using namespace drawerargs;
// r_drawtrans is a seriously bad thing to turn off. I wonder if I should
// just remove it completely.
if (!r_drawtrans || (op == STYLEOP_Add && fglevel == FRACUNIT && bglevel == 0 && !(flags & STYLEF_InvertSource)))
{
if (flags & STYLEF_ColorIsFixed)
{
colfunc = &SWPixelFormatDrawers::FillColumn;
}
else if (dc_translation == NULL)
{
colfunc = basecolfunc;
}
else
{
colfunc = transcolfunc;
drawer_needs_pal_input = true;
}
return true;
}
if (flags & STYLEF_InvertSource)
{
dc_srcblend = Col2RGB8_Inverse[fglevel >> 10];
dc_destblend = Col2RGB8_LessPrecision[bglevel >> 10];
dc_srcalpha = fglevel;
dc_destalpha = bglevel;
}
else if (op == STYLEOP_Add && fglevel + bglevel <= FRACUNIT)
{
dc_srcblend = Col2RGB8[fglevel >> 10];
dc_destblend = Col2RGB8[bglevel >> 10];
dc_srcalpha = fglevel;
dc_destalpha = bglevel;
}
else
{
dc_srcblend = Col2RGB8_LessPrecision[fglevel >> 10];
dc_destblend = Col2RGB8_LessPrecision[bglevel >> 10];
dc_srcalpha = fglevel;
dc_destalpha = bglevel;
}
switch (op)
{
case STYLEOP_Add:
if (fglevel == 0 && bglevel == FRACUNIT)
{
return false;
}
if (fglevel + bglevel <= FRACUNIT)
{ // Colors won't overflow when added
if (flags & STYLEF_ColorIsFixed)
{
colfunc = &SWPixelFormatDrawers::FillAddColumn;
}
else if (dc_translation == NULL)
{
colfunc = &SWPixelFormatDrawers::DrawAddColumn;
}
else
{
colfunc = &SWPixelFormatDrawers::DrawTranslatedAddColumn;
drawer_needs_pal_input = true;
}
}
else
{ // Colors might overflow when added
if (flags & STYLEF_ColorIsFixed)
{
colfunc = &SWPixelFormatDrawers::FillAddClampColumn;
}
else if (dc_translation == NULL)
{
colfunc = &SWPixelFormatDrawers::DrawAddClampColumn;
}
else
{
colfunc = &SWPixelFormatDrawers::DrawAddClampTranslatedColumn;
drawer_needs_pal_input = true;
}
}
return true;
case STYLEOP_Sub:
if (flags & STYLEF_ColorIsFixed)
{
colfunc = &SWPixelFormatDrawers::FillSubClampColumn;
}
else if (dc_translation == NULL)
{
colfunc = &SWPixelFormatDrawers::DrawSubClampColumn;
}
else
{
colfunc = &SWPixelFormatDrawers::DrawSubClampTranslatedColumn;
drawer_needs_pal_input = true;
}
return true;
case STYLEOP_RevSub:
if (fglevel == 0 && bglevel == FRACUNIT)
{
return false;
}
if (flags & STYLEF_ColorIsFixed)
{
colfunc = &SWPixelFormatDrawers::FillRevSubClampColumn;
}
else if (dc_translation == NULL)
{
colfunc = &SWPixelFormatDrawers::DrawRevSubClampColumn;
}
else
{
colfunc = &SWPixelFormatDrawers::DrawRevSubClampTranslatedColumn;
drawer_needs_pal_input = true;
}
return true;
default:
return false;
}
}
fixed_t DrawerStyle::GetAlpha(int type, fixed_t alpha)
{
switch (type)
{
case STYLEALPHA_Zero: return 0;
case STYLEALPHA_One: return OPAQUE;
case STYLEALPHA_Src: return alpha;
case STYLEALPHA_InvSrc: return OPAQUE - alpha;
default: return 0;
}
}
bool DrawerStyle::SetPatchStyle(FRenderStyle style, fixed_t alpha, int translation, uint32_t color, FDynamicColormap *&basecolormap)
{
using namespace drawerargs;
fixed_t fglevel, bglevel;
drawer_needs_pal_input = false;
style.CheckFuzz();
if (style.BlendOp == STYLEOP_Shadow)
{
style = LegacyRenderStyles[STYLE_TranslucentStencil];
alpha = TRANSLUC33;
color = 0;
}
if (style.Flags & STYLEF_ForceAlpha)
{
alpha = clamp<fixed_t>(alpha, 0, OPAQUE);
}
else if (style.Flags & STYLEF_TransSoulsAlpha)
{
alpha = fixed_t(transsouls * OPAQUE);
}
else if (style.Flags & STYLEF_Alpha1)
{
alpha = FRACUNIT;
}
else
{
alpha = clamp<fixed_t>(alpha, 0, OPAQUE);
}
if (translation != -1)
{
dc_translation = NULL;
if (translation != 0)
{
FRemapTable *table = TranslationToTable(translation);
if (table != NULL && !table->Inactive)
{
if (r_swtruecolor)
dc_translation = (uint8_t*)table->Palette;
else
dc_translation = table->Remap;
}
}
}
// Check for special modes
if (style.BlendOp == STYLEOP_Fuzz)
{
colfunc = fuzzcolfunc;
return true;
}
else if (style == LegacyRenderStyles[STYLE_Shaded])
{
// Shaded drawer only gets 16 levels of alpha because it saves memory.
if ((alpha >>= 12) == 0 || basecolormap == nullptr)
return false;
colfunc = &SWPixelFormatDrawers::DrawShadedColumn;
drawer_needs_pal_input = true;
CameraLight *cameraLight = CameraLight::Instance();
dc_color = cameraLight->fixedcolormap ? cameraLight->fixedcolormap->Maps[APART(color)] : basecolormap->Maps[APART(color)];
basecolormap = &ShadeFakeColormap[16 - alpha];
if (cameraLight->fixedlightlev >= 0 && cameraLight->fixedcolormap == NULL)
{
R_SetColorMapLight(basecolormap, 0, FIXEDLIGHT2SHADE(cameraLight->fixedlightlev));
}
else
{
R_SetColorMapLight(basecolormap, 0, 0);
}
return true;
}
fglevel = GetAlpha(style.SrcAlpha, alpha);
bglevel = GetAlpha(style.DestAlpha, alpha);
if (style.Flags & STYLEF_ColorIsFixed)
{
uint32_t x = fglevel >> 10;
uint32_t r = RPART(color);
uint32_t g = GPART(color);
uint32_t b = BPART(color);
// dc_color is used by the rt_* routines. It is indexed into dc_srcblend.
dc_color = RGB256k.RGB[r >> 2][g >> 2][b >> 2];
if (style.Flags & STYLEF_InvertSource)
{
r = 255 - r;
g = 255 - g;
b = 255 - b;
}
uint32_t alpha = clamp(fglevel >> (FRACBITS - 8), 0, 255);
dc_srccolor_bgra = (alpha << 24) | (r << 16) | (g << 8) | b;
// dc_srccolor is used by the R_Fill* routines. It is premultiplied
// with the alpha.
dc_srccolor = ((((r*x) >> 4) << 20) | ((g*x) >> 4) | ((((b)*x) >> 4) << 10)) & 0x3feffbff;
R_SetColorMapLight(&identitycolormap, 0, 0);
}
if (!DrawerStyle::SetBlendFunc(style.BlendOp, fglevel, bglevel, style.Flags))
{
return false;
}
return true;
}
bool DrawerStyle::SetPatchStyle(FRenderStyle style, float alpha, int translation, uint32_t color, FDynamicColormap *&basecolormap)
{
return SetPatchStyle(style, FLOAT2FIXED(alpha), translation, color, basecolormap);
}
DrawerFunc DrawerStyle::GetTransMaskDrawer()
{
if (colfunc == &SWPixelFormatDrawers::DrawAddColumn)
{
return &SWPixelFormatDrawers::DrawWallAddColumn;
}
if (colfunc == &SWPixelFormatDrawers::DrawAddClampColumn)
{
return &SWPixelFormatDrawers::DrawWallAddClampColumn;
}
if (colfunc == &SWPixelFormatDrawers::DrawSubClampColumn)
{
return &SWPixelFormatDrawers::DrawWallSubClampColumn;
}
if (colfunc == &SWPixelFormatDrawers::DrawRevSubClampColumn)
{
return &SWPixelFormatDrawers::DrawWallRevSubClampColumn;
}
return nullptr;
}
void DrawerStyle::SetSpanStyle(bool masked, bool additive, fixed_t alpha)
{
using namespace drawerargs;
if (masked)
{
if (alpha < OPAQUE || additive)
{
if (!additive)
{
spanfunc = &SWPixelFormatDrawers::DrawSpanMaskedTranslucent;
dc_srcblend = Col2RGB8[alpha >> 10];
dc_destblend = Col2RGB8[(OPAQUE - alpha) >> 10];
dc_srcalpha = alpha;
dc_destalpha = OPAQUE - alpha;
}
else
{
spanfunc = &SWPixelFormatDrawers::DrawSpanMaskedAddClamp;
dc_srcblend = Col2RGB8_LessPrecision[alpha >> 10];
dc_destblend = Col2RGB8_LessPrecision[FRACUNIT >> 10];
dc_srcalpha = alpha;
dc_destalpha = FRACUNIT;
}
}
else
{
spanfunc = &SWPixelFormatDrawers::DrawSpanMasked;
}
}
else
{
if (alpha < OPAQUE || additive)
{
if (!additive)
{
spanfunc = &SWPixelFormatDrawers::DrawSpanTranslucent;
dc_srcblend = Col2RGB8[alpha >> 10];
dc_destblend = Col2RGB8[(OPAQUE - alpha) >> 10];
dc_srcalpha = alpha;
dc_destalpha = OPAQUE - alpha;
}
else
{
spanfunc = &SWPixelFormatDrawers::DrawSpanAddClamp;
dc_srcblend = Col2RGB8_LessPrecision[alpha >> 10];
dc_destblend = Col2RGB8_LessPrecision[FRACUNIT >> 10];
dc_srcalpha = alpha;
dc_destalpha = FRACUNIT;
}
}
else
{
spanfunc = &SWPixelFormatDrawers::DrawSpan;
}
}
}
}

View File

@ -174,10 +174,6 @@ namespace swrenderer
void R_InitFuzzTable(int fuzzoff);
void R_InitParticleTexture();
bool R_SetPatchStyle(FRenderStyle style, fixed_t alpha, int translation, uint32_t color, FDynamicColormap *&basecolormap);
bool R_SetPatchStyle(FRenderStyle style, float alpha, int translation, uint32_t color, FDynamicColormap *&basecolormap);
DrawerFunc R_GetTransMaskDrawer();
void R_UpdateFuzzPos();
// Sets dc_colormap and dc_light to their appropriate values depending on the output format (pal vs true color)
@ -188,12 +184,36 @@ namespace swrenderer
void R_SetSpanTexture(FTexture *tex);
void R_SetSpanColormap(FDynamicColormap *colormap, int shade);
void R_DrawMaskedColumn(int x, fixed_t iscale, FTexture *texture, fixed_t column, double spryscale, double sprtopscreen, bool sprflipvert, const short *mfloorclip, const short *mceilingclip, bool unmasked = false);
void R_DrawMaskedColumnBgra(int x, fixed_t iscale, FTexture *tex, fixed_t column, double spryscale, double sprtopscreen, bool sprflipvert, const short *mfloorclip, const short *mceilingclip, bool unmasked);
class DrawerStyle
{
public:
DrawerStyle()
{
colfunc = &SWPixelFormatDrawers::DrawColumn;
basecolfunc = &SWPixelFormatDrawers::DrawColumn;
fuzzcolfunc = &SWPixelFormatDrawers::DrawFuzzColumn;
transcolfunc = &SWPixelFormatDrawers::DrawTranslatedColumn;
spanfunc = &SWPixelFormatDrawers::DrawSpan;
}
extern DrawerFunc colfunc;
extern DrawerFunc basecolfunc;
extern DrawerFunc fuzzcolfunc;
extern DrawerFunc transcolfunc;
extern DrawerFunc spanfunc;
bool SetPatchStyle(FRenderStyle style, fixed_t alpha, int translation, uint32_t color, FDynamicColormap *&basecolormap);
bool SetPatchStyle(FRenderStyle style, float alpha, int translation, uint32_t color, FDynamicColormap *&basecolormap);
void SetSpanStyle(bool masked, bool additive, fixed_t alpha);
void DrawMaskedColumn(int x, fixed_t iscale, FTexture *texture, fixed_t column, double spryscale, double sprtopscreen, bool sprflipvert, const short *mfloorclip, const short *mceilingclip, bool unmasked = false);
DrawerFunc GetTransMaskDrawer();
DrawerFunc colfunc;
DrawerFunc basecolfunc;
DrawerFunc fuzzcolfunc;
DrawerFunc transcolfunc;
DrawerFunc spanfunc;
private:
void DrawMaskedColumnBgra(int x, fixed_t iscale, FTexture *tex, fixed_t column, double spryscale, double sprtopscreen, bool sprflipvert, const short *mfloorclip, const short *mceilingclip, bool unmasked);
bool SetBlendFunc(int op, fixed_t fglevel, fixed_t bglevel, int flags);
static fixed_t GetAlpha(int type, fixed_t alpha);
};
}

View File

@ -1045,8 +1045,9 @@ namespace swrenderer
rw_offset = -rw_offset;
}
DrawerStyle drawerstyle;
RenderWallPart renderWallpart;
renderWallpart.Render(frontsector, curline, WallC, rw_pic, x1, x2, walltop.ScreenY, wallbottom.ScreenY, rw_midtexturemid, walltexcoords.VStep, walltexcoords.UPos, yscale, MAX(rw_frontcz1, rw_frontcz2), MIN(rw_frontfz1, rw_frontfz2), false, wallshade, rw_offset, rw_light, rw_lightstep, light_list, foggy, basecolormap);
renderWallpart.Render(drawerstyle, frontsector, curline, WallC, rw_pic, x1, x2, walltop.ScreenY, wallbottom.ScreenY, rw_midtexturemid, walltexcoords.VStep, walltexcoords.UPos, yscale, MAX(rw_frontcz1, rw_frontcz2), MIN(rw_frontfz1, rw_frontfz2), false, wallshade, rw_offset, rw_light, rw_lightstep, light_list, foggy, basecolormap);
}
fillshort(ceilingclip + x1, x2 - x1, viewheight);
fillshort(floorclip + x1, x2 - x1, 0xffff);
@ -1082,8 +1083,9 @@ namespace swrenderer
rw_offset = -rw_offset;
}
DrawerStyle drawerstyle;
RenderWallPart renderWallpart;
renderWallpart.Render(frontsector, curline, WallC, rw_pic, x1, x2, walltop.ScreenY, wallupper.ScreenY, rw_toptexturemid, walltexcoords.VStep, walltexcoords.UPos, yscale, MAX(rw_frontcz1, rw_frontcz2), MIN(rw_backcz1, rw_backcz2), false, wallshade, rw_offset, rw_light, rw_lightstep, light_list, foggy, basecolormap);
renderWallpart.Render(drawerstyle, frontsector, curline, WallC, rw_pic, x1, x2, walltop.ScreenY, wallupper.ScreenY, rw_toptexturemid, walltexcoords.VStep, walltexcoords.UPos, yscale, MAX(rw_frontcz1, rw_frontcz2), MIN(rw_backcz1, rw_backcz2), false, wallshade, rw_offset, rw_light, rw_lightstep, light_list, foggy, basecolormap);
}
memcpy(ceilingclip + x1, wallupper.ScreenY + x1, (x2 - x1) * sizeof(short));
}
@ -1122,8 +1124,9 @@ namespace swrenderer
rw_offset = -rw_offset;
}
DrawerStyle drawerstyle;
RenderWallPart renderWallpart;
renderWallpart.Render(frontsector, curline, WallC, rw_pic, x1, x2, walllower.ScreenY, wallbottom.ScreenY, rw_bottomtexturemid, walltexcoords.VStep, walltexcoords.UPos, yscale, MAX(rw_backfz1, rw_backfz2), MIN(rw_frontfz1, rw_frontfz2), false, wallshade, rw_offset, rw_light, rw_lightstep, light_list, foggy, basecolormap);
renderWallpart.Render(drawerstyle, frontsector, curline, WallC, rw_pic, x1, x2, walllower.ScreenY, wallbottom.ScreenY, rw_bottomtexturemid, walltexcoords.VStep, walltexcoords.UPos, yscale, MAX(rw_backfz1, rw_backfz2), MIN(rw_frontfz1, rw_frontfz2), false, wallshade, rw_offset, rw_light, rw_lightstep, light_list, foggy, basecolormap);
}
memcpy(floorclip + x1, walllower.ScreenY + x1, (x2 - x1) * sizeof(short));
}

View File

@ -67,7 +67,8 @@ namespace swrenderer
curline = ds->curline;
FDynamicColormap *patchstylecolormap = nullptr;
bool visible = R_SetPatchStyle(LegacyRenderStyles[curline->linedef->flags & ML_ADDTRANS ? STYLE_Add : STYLE_Translucent],
DrawerStyle drawerstyle;
bool visible = drawerstyle.SetPatchStyle(LegacyRenderStyles[curline->linedef->flags & ML_ADDTRANS ? STYLE_Add : STYLE_Translucent],
(float)MIN(curline->linedef->alpha, 1.), 0, 0, patchstylecolormap);
if (!visible && !ds->bFogBoundary && !ds->bFakeBoundary)
@ -282,7 +283,7 @@ namespace swrenderer
else
sprtopscreen = CenterY - texturemid * spryscale;
R_DrawMaskedColumn(x, iscale, tex, maskedtexturecol[x], spryscale, sprtopscreen, sprflipvert, mfloorclip, mceilingclip);
drawerstyle.DrawMaskedColumn(x, iscale, tex, maskedtexturecol[x], spryscale, sprtopscreen, sprflipvert, mfloorclip, mceilingclip);
rw_light += rw_lightstep;
spryscale += rw_scalestep;
@ -348,7 +349,7 @@ namespace swrenderer
GetMaskedWallTopBottom(ds, top, bot);
RenderWallPart renderWallpart;
renderWallpart.Render(frontsector, curline, WallC, rw_pic, x1, x2, mceilingclip, mfloorclip, texturemid, MaskedSWall, maskedtexturecol, ds->yscale, top, bot, true, wallshade, rw_offset, rw_light, rw_lightstep, nullptr, ds->foggy, basecolormap);
renderWallpart.Render(drawerstyle, frontsector, curline, WallC, rw_pic, x1, x2, mceilingclip, mfloorclip, texturemid, MaskedSWall, maskedtexturecol, ds->yscale, top, bot, true, wallshade, rw_offset, rw_light, rw_lightstep, nullptr, ds->foggy, basecolormap);
}
clearfog:
@ -382,7 +383,8 @@ namespace swrenderer
double yscale;
fixed_t Alpha = Scale(rover->alpha, OPAQUE, 255);
bool visible = R_SetPatchStyle(LegacyRenderStyles[rover->flags & FF_ADDITIVETRANS ? STYLE_Add : STYLE_Translucent],
DrawerStyle drawerstyle;
bool visible = drawerstyle.SetPatchStyle(LegacyRenderStyles[rover->flags & FF_ADDITIVETRANS ? STYLE_Add : STYLE_Translucent],
Alpha, 0, 0, basecolormap);
if (!visible)
@ -479,7 +481,7 @@ namespace swrenderer
GetMaskedWallTopBottom(ds, top, bot);
RenderWallPart renderWallpart;
renderWallpart.Render(frontsector, curline, WallC, rw_pic, x1, x2, wallupper.ScreenY, walllower.ScreenY, texturemid, MaskedSWall, walltexcoords.UPos, yscale, top, bot, true, wallshade, rw_offset, rw_light, rw_lightstep, nullptr, ds->foggy, basecolormap);
renderWallpart.Render(drawerstyle, frontsector, curline, WallC, rw_pic, x1, x2, wallupper.ScreenY, walllower.ScreenY, texturemid, MaskedSWall, walltexcoords.UPos, yscale, top, bot, true, wallshade, rw_offset, rw_light, rw_lightstep, nullptr, ds->foggy, basecolormap);
}
// kg3D - walls of fake floors

View File

@ -392,7 +392,7 @@ namespace swrenderer
void RenderWallPart::ProcessTranslucentWall(const short *uwal, const short *dwal, double texturemid, float *swal, fixed_t *lwal)
{
DrawerFunc drawcol1 = R_GetTransMaskDrawer();
DrawerFunc drawcol1 = drawerstyle.GetTransMaskDrawer();
if (drawcol1 == nullptr)
{
// The current translucency is unsupported, so draw with regular ProcessMaskedWall instead.
@ -445,7 +445,7 @@ namespace swrenderer
{
if (mask)
{
if (colfunc == basecolfunc)
if (drawerstyle.colfunc == drawerstyle.basecolfunc)
{
ProcessMaskedWall(uwal, dwal, texturemid, swal, lwal);
}
@ -540,8 +540,9 @@ namespace swrenderer
}
}
void RenderWallPart::Render(sector_t *frontsector, seg_t *curline, const FWallCoords &WallC, FTexture *pic, int x1, int x2, const short *walltop, const short *wallbottom, double texturemid, float *swall, fixed_t *lwall, double yscale, double top, double bottom, bool mask, int wallshade, fixed_t xoffset, float light, float lightstep, FLightNode *light_list, bool foggy, FDynamicColormap *basecolormap)
void RenderWallPart::Render(const DrawerStyle &drawerstyle, sector_t *frontsector, seg_t *curline, const FWallCoords &WallC, FTexture *pic, int x1, int x2, const short *walltop, const short *wallbottom, double texturemid, float *swall, fixed_t *lwall, double yscale, double top, double bottom, bool mask, int wallshade, fixed_t xoffset, float light, float lightstep, FLightNode *light_list, bool foggy, FDynamicColormap *basecolormap)
{
this->drawerstyle = drawerstyle;
this->x1 = x1;
this->x2 = x2;
this->frontsector = frontsector;

View File

@ -34,6 +34,7 @@ namespace swrenderer
{
public:
void Render(
const DrawerStyle &drawerstyle,
sector_t *frontsector,
seg_t *curline,
const FWallCoords &WallC,
@ -83,6 +84,8 @@ namespace swrenderer
FDynamicColormap *basecolormap = nullptr;
FLightNode *light_list = nullptr;
bool mask = false;
DrawerStyle drawerstyle;
};
struct WallSampler

View File

@ -125,61 +125,7 @@ namespace swrenderer
planeshade = LIGHT2SHADE(pl->lightlevel);
}
if (spanfunc != &SWPixelFormatDrawers::FillSpan)
{
if (masked)
{
if (alpha < OPAQUE || additive)
{
if (!additive)
{
spanfunc = &SWPixelFormatDrawers::DrawSpanMaskedTranslucent;
dc_srcblend = Col2RGB8[alpha >> 10];
dc_destblend = Col2RGB8[(OPAQUE - alpha) >> 10];
dc_srcalpha = alpha;
dc_destalpha = OPAQUE - alpha;
}
else
{
spanfunc = &SWPixelFormatDrawers::DrawSpanMaskedAddClamp;
dc_srcblend = Col2RGB8_LessPrecision[alpha >> 10];
dc_destblend = Col2RGB8_LessPrecision[FRACUNIT >> 10];
dc_srcalpha = alpha;
dc_destalpha = FRACUNIT;
}
}
else
{
spanfunc = &SWPixelFormatDrawers::DrawSpanMasked;
}
}
else
{
if (alpha < OPAQUE || additive)
{
if (!additive)
{
spanfunc = &SWPixelFormatDrawers::DrawSpanTranslucent;
dc_srcblend = Col2RGB8[alpha >> 10];
dc_destblend = Col2RGB8[(OPAQUE - alpha) >> 10];
dc_srcalpha = alpha;
dc_destalpha = OPAQUE - alpha;
}
else
{
spanfunc = &SWPixelFormatDrawers::DrawSpanAddClamp;
dc_srcblend = Col2RGB8_LessPrecision[alpha >> 10];
dc_destblend = Col2RGB8_LessPrecision[FRACUNIT >> 10];
dc_srcalpha = alpha;
dc_destalpha = FRACUNIT;
}
}
else
{
spanfunc = &SWPixelFormatDrawers::DrawSpan;
}
}
}
drawerstyle.SetSpanStyle(masked, additive, alpha);
light_list = pl->lights;
@ -309,7 +255,7 @@ namespace swrenderer
ds_x1 = x1;
ds_x2 = x2;
(R_Drawers()->*spanfunc)();
(R_Drawers()->*drawerstyle.spanfunc)();
}
void RenderFlatPlane::StepColumn()

View File

@ -14,6 +14,7 @@
#pragma once
#include "r_planerenderer.h"
#include "swrenderer/drawers/r_draw.h"
namespace swrenderer
{
@ -41,6 +42,8 @@ namespace swrenderer
double basexfrac, baseyfrac;
VisiblePlaneLight *light_list;
DrawerStyle drawerstyle;
static float yslope[MAXHEIGHT];
};

View File

@ -141,9 +141,6 @@ namespace swrenderer
NetUpdate();
colfunc = basecolfunc;
spanfunc = &SWPixelFormatDrawers::DrawSpan;
RenderPortal::Instance()->SetMainPortal();
this->dontmaplines = dontmaplines;

View File

@ -282,7 +282,8 @@ namespace swrenderer
{
int x = x1;
bool visible = R_SetPatchStyle(decal->RenderStyle, (float)decal->Alpha, decal->Translation, decal->AlphaColor, basecolormap);
DrawerStyle drawerstyle;
bool visible = drawerstyle.SetPatchStyle(decal->RenderStyle, (float)decal->Alpha, decal->Translation, decal->AlphaColor, basecolormap);
// R_SetPatchStyle can modify basecolormap.
if (rereadcolormap)
@ -298,7 +299,7 @@ namespace swrenderer
{ // calculate lighting
R_SetColorMapLight(usecolormap, light, wallshade);
}
DrawColumn(x, WallSpriteTile, walltexcoords, texturemid, maskedScaleY, sprflipvert, mfloorclip, mceilingclip);
DrawColumn(drawerstyle, x, WallSpriteTile, walltexcoords, texturemid, maskedScaleY, sprflipvert, mfloorclip, mceilingclip);
light += lightstep;
x++;
}
@ -311,13 +312,11 @@ namespace swrenderer
mfloorclip = wallbottom;
} while (needrepeat--);
colfunc = basecolfunc;
done:
WallC = savecoord;
}
void RenderDecal::DrawColumn(int x, FTexture *WallSpriteTile, const ProjectedWallTexcoords &walltexcoords, double texturemid, float maskedScaleY, bool sprflipvert, const short *mfloorclip, const short *mceilingclip)
void RenderDecal::DrawColumn(DrawerStyle &drawerstyle, int x, FTexture *WallSpriteTile, const ProjectedWallTexcoords &walltexcoords, double texturemid, float maskedScaleY, bool sprflipvert, const short *mfloorclip, const short *mceilingclip)
{
float iscale = walltexcoords.VStep[x] * maskedScaleY;
double spryscale = 1 / iscale;
@ -327,6 +326,6 @@ namespace swrenderer
else
sprtopscreen = CenterY - texturemid * spryscale;
R_DrawMaskedColumn(x, FLOAT2FIXED(iscale), WallSpriteTile, walltexcoords.UPos[x], spryscale, sprtopscreen, sprflipvert, mfloorclip, mceilingclip);
drawerstyle.DrawMaskedColumn(x, FLOAT2FIXED(iscale), WallSpriteTile, walltexcoords.UPos[x], spryscale, sprtopscreen, sprflipvert, mfloorclip, mceilingclip);
}
}

View File

@ -20,6 +20,7 @@ namespace swrenderer
{
struct DrawSegment;
class ProjectedWallTexcoords;
class DrawerStyle;
class RenderDecal
{
@ -28,6 +29,6 @@ namespace swrenderer
private:
static void Render(side_t *wall, DBaseDecal *first, DrawSegment *clipper, int wallshade, float lightleft, float lightstep, seg_t *curline, FWallCoords wallC, bool foggy, FDynamicColormap *basecolormap, const short *walltop, const short *wallbottom, int pass);
static void DrawColumn(int x, FTexture *WallSpriteTile, const ProjectedWallTexcoords &walltexcoords, double texturemid, float maskedScaleY, bool sprflipvert, const short *mfloorclip, const short *mceilingclip);
static void DrawColumn(DrawerStyle &drawerstyle, int x, FTexture *WallSpriteTile, const ProjectedWallTexcoords &walltexcoords, double texturemid, float maskedScaleY, bool sprflipvert, const short *mfloorclip, const short *mceilingclip);
};
}

View File

@ -591,7 +591,8 @@ namespace swrenderer
FDynamicColormap *basecolormap = static_cast<FDynamicColormap*>(Light.BaseColormap);
bool visible = R_SetPatchStyle(RenderStyle, Alpha, Translation, FillColor, basecolormap);
DrawerStyle drawerstyle;
bool visible = drawerstyle.SetPatchStyle(RenderStyle, Alpha, Translation, FillColor, basecolormap);
if (RenderStyle == LegacyRenderStyles[STYLE_Shaded])
{ // For shaded sprites, R_SetPatchStyle sets a dc_colormap to an alpha table, but
@ -628,7 +629,7 @@ namespace swrenderer
fixed_t frac = startfrac;
for (int x = x1; x < x2; x++)
{
R_DrawMaskedColumn(x, iscale, pic, frac, spryscale, sprtopscreen, sprflipvert, mfloorclip, mceilingclip, false);
drawerstyle.DrawMaskedColumn(x, iscale, pic, frac, spryscale, sprtopscreen, sprflipvert, mfloorclip, mceilingclip, false);
frac += xiscale;
}

View File

@ -250,7 +250,8 @@ namespace swrenderer
FDynamicColormap *basecolormap = static_cast<FDynamicColormap*>(vis->Light.BaseColormap);
bool visible = R_SetPatchStyle(vis->RenderStyle, vis->Alpha, vis->Translation, vis->FillColor, basecolormap);
DrawerStyle drawerstyle;
bool visible = drawerstyle.SetPatchStyle(vis->RenderStyle, vis->Alpha, vis->Translation, vis->FillColor, basecolormap);
if (vis->RenderStyle == LegacyRenderStyles[STYLE_Shaded])
{ // For shaded sprites, R_SetPatchStyle sets a dc_colormap to an alpha table, but
@ -293,7 +294,7 @@ namespace swrenderer
while (x < x2)
{
if (!translucentPass->ClipSpriteColumnWithPortals(x, vis))
R_DrawMaskedColumn(x, iscale, tex, frac, spryscale, sprtopscreen, sprflipvert, mfloorclip, mceilingclip, false);
drawerstyle.DrawMaskedColumn(x, iscale, tex, frac, spryscale, sprtopscreen, sprflipvert, mfloorclip, mceilingclip, false);
x++;
frac += xiscale;
}

View File

@ -188,7 +188,8 @@ namespace swrenderer
R_SetColorMapLight(sprite->Light.BaseColormap, 0, sprite->Light.ColormapNum << FRACBITS);
bool visible = R_SetPatchStyle(sprite->RenderStyle, sprite->Alpha, sprite->Translation, sprite->FillColor, basecolormap);
DrawerStyle drawerstyle;
bool visible = drawerstyle.SetPatchStyle(sprite->RenderStyle, sprite->Alpha, sprite->Translation, sprite->FillColor, basecolormap);
if (!visible)
return;

View File

@ -213,7 +213,8 @@ namespace swrenderer
FDynamicColormap *basecolormap = static_cast<FDynamicColormap*>(spr->Light.BaseColormap);
bool visible = R_SetPatchStyle(spr->RenderStyle, spr->Alpha, spr->Translation, spr->FillColor, basecolormap);
DrawerStyle drawerstyle;
bool visible = drawerstyle.SetPatchStyle(spr->RenderStyle, spr->Alpha, spr->Translation, spr->FillColor, basecolormap);
// R_SetPatchStyle can modify basecolormap.
if (rereadcolormap)
@ -236,14 +237,14 @@ namespace swrenderer
R_SetColorMapLight(usecolormap, light, shade);
}
if (!translucentPass->ClipSpriteColumnWithPortals(x, spr))
DrawColumn(x, WallSpriteTile, walltexcoords, texturemid, maskedScaleY, sprflipvert, mfloorclip, mceilingclip);
DrawColumn(drawerstyle, x, WallSpriteTile, walltexcoords, texturemid, maskedScaleY, sprflipvert, mfloorclip, mceilingclip);
light += lightstep;
x++;
}
}
}
void RenderWallSprite::DrawColumn(int x, FTexture *WallSpriteTile, const ProjectedWallTexcoords &walltexcoords, double texturemid, float maskedScaleY, bool sprflipvert, const short *mfloorclip, const short *mceilingclip)
void RenderWallSprite::DrawColumn(DrawerStyle &drawerstyle, int x, FTexture *WallSpriteTile, const ProjectedWallTexcoords &walltexcoords, double texturemid, float maskedScaleY, bool sprflipvert, const short *mfloorclip, const short *mceilingclip)
{
float iscale = walltexcoords.VStep[x] * maskedScaleY;
double spryscale = 1 / iscale;
@ -253,6 +254,6 @@ namespace swrenderer
else
sprtopscreen = CenterY - texturemid * spryscale;
R_DrawMaskedColumn(x, FLOAT2FIXED(iscale), WallSpriteTile, walltexcoords.UPos[x], spryscale, sprtopscreen, sprflipvert, mfloorclip, mceilingclip);
drawerstyle.DrawMaskedColumn(x, FLOAT2FIXED(iscale), WallSpriteTile, walltexcoords.UPos[x], spryscale, sprtopscreen, sprflipvert, mfloorclip, mceilingclip);
}
}

View File

@ -18,6 +18,7 @@
namespace swrenderer
{
class ProjectedWallTexcoords;
class DrawerStyle;
class RenderWallSprite : public VisibleSprite
{
@ -29,7 +30,7 @@ namespace swrenderer
void Render(short *cliptop, short *clipbottom, int minZ, int maxZ) override;
private:
static void DrawColumn(int x, FTexture *WallSpriteTile, const ProjectedWallTexcoords &walltexcoords, double texturemid, float maskedScaleY, bool sprflipvert, const short *mfloorclip, const short *mceilingclip);
static void DrawColumn(DrawerStyle &drawerstyle, int x, FTexture *WallSpriteTile, const ProjectedWallTexcoords &walltexcoords, double texturemid, float maskedScaleY, bool sprflipvert, const short *mfloorclip, const short *mceilingclip);
FWallCoords wallc;
uint32_t Translation = 0;

View File

@ -200,10 +200,11 @@ void DCanvas::DrawTextureParms(FTexture *img, DrawParms &parms)
CameraLight::Instance()->fixedcolormap = dc_fcolormap;
bool visible;
FDynamicColormap *basecolormap = nullptr;
DrawerStyle drawerstyle;
if (r_swtruecolor)
visible = R_SetPatchStyle(parms.style, parms.Alpha, -1, parms.fillcolor, basecolormap);
visible = drawerstyle.SetPatchStyle(parms.style, parms.Alpha, -1, parms.fillcolor, basecolormap);
else
visible = R_SetPatchStyle(parms.style, parms.Alpha, 0, parms.fillcolor, basecolormap);
visible = drawerstyle.SetPatchStyle(parms.style, parms.Alpha, 0, parms.fillcolor, basecolormap);
BYTE *destorgsave = dc_destorg;
int destheightsave = dc_destheight;
@ -291,7 +292,7 @@ void DCanvas::DrawTextureParms(FTexture *img, DrawParms &parms)
while (x < x2_i)
{
R_DrawMaskedColumn(x, iscale, img, frac, spryscale, sprtopscreen, sprflipvert, mfloorclip, mceilingclip, !parms.masked);
drawerstyle.DrawMaskedColumn(x, iscale, img, frac, spryscale, sprtopscreen, sprflipvert, mfloorclip, mceilingclip, !parms.masked);
x++;
frac += xiscale_i;
}