Clean up the SpanDrawerArgs interface a bit

This commit is contained in:
Magnus Norddahl 2017-01-30 12:46:17 +01:00
parent c574b0ad3f
commit 98fa2976fa
7 changed files with 130 additions and 104 deletions

View file

@ -1848,23 +1848,23 @@ namespace swrenderer
PalSpanCommand::PalSpanCommand(const SpanDrawerArgs &args) PalSpanCommand::PalSpanCommand(const SpanDrawerArgs &args)
{ {
_source = args.ds_source; _source = args.TexturePixels();
_colormap = args.Colormap(); _colormap = args.Colormap();
_xfrac = args.ds_xfrac; _xfrac = args.TextureUPos();
_yfrac = args.ds_yfrac; _yfrac = args.TextureVPos();
_y = args.ds_y; _y = args.DestY();
_x1 = args.ds_x1; _x1 = args.DestX1();
_x2 = args.ds_x2; _x2 = args.DestX2();
_destorg = dc_destorg; _destorg = dc_destorg;
_xstep = args.ds_xstep; _xstep = args.TextureUStep();
_ystep = args.ds_ystep; _ystep = args.TextureVStep();
_xbits = args.ds_xbits; _xbits = args.TextureWidthBits();
_ybits = args.ds_ybits; _ybits = args.TextureHeightBits();
_srcblend = args.dc_srcblend; _srcblend = args.SrcBlend();
_destblend = args.dc_destblend; _destblend = args.DestBlend();
_color = args.ds_color; _color = args.SolidColor();
_srcalpha = args.dc_srcalpha; _srcalpha = args.SrcAlpha();
_destalpha = args.dc_destalpha; _destalpha = args.DestAlpha();
_dynlights = args.dc_lights; _dynlights = args.dc_lights;
_num_dynlights = args.dc_num_lights; _num_dynlights = args.dc_num_lights;
_viewpos_x = args.dc_viewpos.X; _viewpos_x = args.dc_viewpos.X;
@ -2626,9 +2626,9 @@ namespace swrenderer
{ {
_colormap = args.Colormap(); _colormap = args.Colormap();
_destorg = dc_destorg; _destorg = dc_destorg;
_ybits = args.ds_ybits; _ybits = args.TextureHeightBits();
_xbits = args.ds_xbits; _xbits = args.TextureWidthBits();
_source = args.ds_source; _source = args.TexturePixels();
basecolormapdata = basecolormap->Maps; basecolormapdata = basecolormap->Maps;
} }
@ -2869,7 +2869,7 @@ namespace swrenderer
DrawColoredSpanPalCommand::DrawColoredSpanPalCommand(const SpanDrawerArgs &args, int y, int x1, int x2) : PalSpanCommand(args), y(y), x1(x1), x2(x2) DrawColoredSpanPalCommand::DrawColoredSpanPalCommand(const SpanDrawerArgs &args, int y, int x1, int x2) : PalSpanCommand(args), y(y), x1(x1), x2(x2)
{ {
color = args.ds_color; color = args.SolidColor();
destorg = dc_destorg; destorg = dc_destorg;
} }

View file

@ -63,18 +63,18 @@ namespace swrenderer
DrawSpanLLVMCommand::DrawSpanLLVMCommand(const SpanDrawerArgs &drawerargs) DrawSpanLLVMCommand::DrawSpanLLVMCommand(const SpanDrawerArgs &drawerargs)
{ {
auto shade_constants = drawerargs.ColormapConstants(); auto shade_constants = drawerargs.ColormapConstants();
args.xfrac = drawerargs.ds_xfrac; args.xfrac = drawerargs.TextureUPos();
args.yfrac = drawerargs.ds_yfrac; args.yfrac = drawerargs.TextureVPos();
args.xstep = drawerargs.ds_xstep; args.xstep = drawerargs.TextureUStep();
args.ystep = drawerargs.ds_ystep; args.ystep = drawerargs.TextureVStep();
args.x1 = drawerargs.ds_x1; args.x1 = drawerargs.DestX1();
args.x2 = drawerargs.ds_x2; args.x2 = drawerargs.DestX2();
args.y = drawerargs.ds_y; args.y = drawerargs.DestY();
args.xbits = drawerargs.ds_xbits; args.xbits = drawerargs.TextureWidthBits();
args.ybits = drawerargs.ds_ybits; args.ybits = drawerargs.TextureHeightBits();
args.destorg = (uint32_t*)dc_destorg; args.destorg = (uint32_t*)dc_destorg;
args.destpitch = dc_pitch; args.destpitch = dc_pitch;
args.source = (const uint32_t*)drawerargs.ds_source; args.source = (const uint32_t*)drawerargs.TexturePixels();
args.light = LightBgra::calc_light_multiplier(drawerargs.Light()); args.light = LightBgra::calc_light_multiplier(drawerargs.Light());
args.light_red = shade_constants.light_red; args.light_red = shade_constants.light_red;
args.light_green = shade_constants.light_green; args.light_green = shade_constants.light_green;
@ -85,12 +85,12 @@ namespace swrenderer
args.fade_blue = shade_constants.fade_blue; args.fade_blue = shade_constants.fade_blue;
args.fade_alpha = shade_constants.fade_alpha; args.fade_alpha = shade_constants.fade_alpha;
args.desaturate = shade_constants.desaturate; args.desaturate = shade_constants.desaturate;
args.srcalpha = drawerargs.dc_srcalpha >> (FRACBITS - 8); args.srcalpha = drawerargs.SrcAlpha() >> (FRACBITS - 8);
args.destalpha = drawerargs.dc_destalpha >> (FRACBITS - 8); args.destalpha = drawerargs.DestAlpha() >> (FRACBITS - 8);
args.flags = 0; args.flags = 0;
if (shade_constants.simple_shade) if (shade_constants.simple_shade)
args.flags |= DrawSpanArgs::simple_shade; args.flags |= DrawSpanArgs::simple_shade;
if (!sampler_setup(drawerargs.ds_lod, args.source, args.xbits, args.ybits, drawerargs.ds_source_mipmapped)) if (!sampler_setup(drawerargs.TextureLOD(), args.source, args.xbits, args.ybits, drawerargs.MipmappedTexture()))
args.flags |= DrawSpanArgs::nearest_filter; args.flags |= DrawSpanArgs::nearest_filter;
args.viewpos_x = drawerargs.dc_viewpos.X; args.viewpos_x = drawerargs.dc_viewpos.X;
@ -436,12 +436,12 @@ namespace swrenderer
FillSpanRGBACommand::FillSpanRGBACommand(const SpanDrawerArgs &drawerargs) FillSpanRGBACommand::FillSpanRGBACommand(const SpanDrawerArgs &drawerargs)
{ {
_x1 = drawerargs.ds_x1; _x1 = drawerargs.DestX1();
_x2 = drawerargs.ds_x2; _x2 = drawerargs.DestX2();
_y = drawerargs.ds_y; _y = drawerargs.DestY();
_destorg = dc_destorg; _destorg = dc_destorg;
_light = drawerargs.Light(); _light = drawerargs.Light();
_color = drawerargs.ds_color; _color = drawerargs.SolidColor();
} }
void FillSpanRGBACommand::Execute(DrawerThread *thread) void FillSpanRGBACommand::Execute(DrawerThread *thread)
@ -548,9 +548,9 @@ namespace swrenderer
_planelightfloat = planelightfloat; _planelightfloat = planelightfloat;
_pviewx = pviewx; _pviewx = pviewx;
_pviewy = pviewy; _pviewy = pviewy;
_source = (const uint32_t*)drawerargs.ds_source; _source = (const uint32_t*)drawerargs.TexturePixels();
_xbits = drawerargs.ds_xbits; _xbits = drawerargs.TextureWidthBits();
_ybits = drawerargs.ds_ybits; _ybits = drawerargs.TextureHeightBits();
} }
void DrawTiltedSpanRGBACommand::Execute(DrawerThread *thread) void DrawTiltedSpanRGBACommand::Execute(DrawerThread *thread)
@ -674,7 +674,7 @@ namespace swrenderer
_destorg = dc_destorg; _destorg = dc_destorg;
_light = drawerargs.Light(); _light = drawerargs.Light();
_color = drawerargs.ds_color; _color = drawerargs.SolidColor();
} }
void DrawColoredSpanRGBACommand::Execute(DrawerThread *thread) void DrawColoredSpanRGBACommand::Execute(DrawerThread *thread)

View file

@ -124,7 +124,7 @@ namespace swrenderer
return shadeConstants; return shadeConstants;
} }
void SpanDrawerArgs::SetSpanTexture(FTexture *tex) void SpanDrawerArgs::SetTexture(FTexture *tex)
{ {
tex->GetWidth(); tex->GetWidth();
ds_xbits = tex->WidthBits; ds_xbits = tex->WidthBits;
@ -596,7 +596,7 @@ namespace swrenderer
(Drawers()->*wallfunc)(*this); (Drawers()->*wallfunc)(*this);
} }
void SpanDrawerArgs::SetSpanStyle(bool masked, bool additive, fixed_t alpha) void SpanDrawerArgs::SetStyle(bool masked, bool additive, fixed_t alpha)
{ {
if (masked) if (masked)
{ {

View file

@ -71,33 +71,40 @@ namespace swrenderer
public: public:
SpanDrawerArgs(); SpanDrawerArgs();
void SetSpanStyle(bool masked, bool additive, fixed_t alpha); void SetStyle(bool masked, bool additive, fixed_t alpha);
void SetSpanTexture(FTexture *tex); void SetDestY(int y) { ds_y = y; }
void SetDestX1(int x) { ds_x1 = x; }
void SetDestX2(int x) { ds_x2 = x; }
void SetTexture(FTexture *tex);
void SetTextureLOD(double lod) { ds_lod = lod; }
void SetTextureUPos(dsfixed_t xfrac) { ds_xfrac = xfrac; }
void SetTextureVPos(dsfixed_t yfrac) { ds_yfrac = yfrac; }
void SetTextureUStep(dsfixed_t xstep) { ds_xstep = xstep; }
void SetTextureVStep(dsfixed_t vstep) { ds_ystep = vstep; }
void SetSolidColor(int colorIndex) { ds_color = colorIndex; }
void DrawSpan(); void DrawSpan();
void DrawTiltedSpan(int y, int x1, int x2, const FVector3 &plane_sz, const FVector3 &plane_su, const FVector3 &plane_sv, bool plane_shade, int planeshade, float planelightfloat, fixed_t pviewx, fixed_t pviewy, FDynamicColormap *basecolormap); void DrawTiltedSpan(int y, int x1, int x2, const FVector3 &plane_sz, const FVector3 &plane_su, const FVector3 &plane_sv, bool plane_shade, int planeshade, float planelightfloat, fixed_t pviewx, fixed_t pviewy, FDynamicColormap *basecolormap);
void DrawColoredSpan(int y, int x1, int x2); void DrawColoredSpan(int y, int x1, int x2);
void DrawFogBoundaryLine(int y, int x1, int x2); void DrawFogBoundaryLine(int y, int x1, int x2);
uint32_t *dc_srcblend; uint32_t *SrcBlend() const { return dc_srcblend; }
uint32_t *dc_destblend; uint32_t *DestBlend() const { return dc_destblend; }
fixed_t dc_srcalpha; fixed_t SrcAlpha() const { return dc_srcalpha; }
fixed_t dc_destalpha; fixed_t DestAlpha() const { return dc_destalpha; }
int DestY() const { return ds_y; }
int ds_y; int DestX1() const { return ds_x1; }
int ds_x1; int DestX2() const { return ds_x2; }
int ds_x2; dsfixed_t TextureUPos() const { return ds_xfrac; }
dsfixed_t ds_xfrac; dsfixed_t TextureVPos() const { return ds_yfrac; }
dsfixed_t ds_yfrac; dsfixed_t TextureUStep() const { return ds_xstep; }
dsfixed_t ds_xstep; dsfixed_t TextureVStep() const { return ds_xstep; }
dsfixed_t ds_ystep; int SolidColor() const { return ds_color; }
int ds_xbits; int TextureWidthBits() const { return ds_xbits; }
int ds_ybits; int TextureHeightBits() const { return ds_ybits; }
fixed_t ds_alpha; const uint8_t *TexturePixels() const { return ds_source; }
double ds_lod; bool MipmappedTexture() const { return ds_source_mipmapped; }
const uint8_t *ds_source; double TextureLOD() const { return ds_lod; }
bool ds_source_mipmapped;
int ds_color = 0;
FVector3 dc_normal; FVector3 dc_normal;
FVector3 dc_viewpos; FVector3 dc_viewpos;
@ -108,6 +115,24 @@ namespace swrenderer
private: private:
typedef void(SWPixelFormatDrawers::*SpanDrawerFunc)(const SpanDrawerArgs &args); typedef void(SWPixelFormatDrawers::*SpanDrawerFunc)(const SpanDrawerArgs &args);
SpanDrawerFunc spanfunc; SpanDrawerFunc spanfunc;
int ds_y;
int ds_x1;
int ds_x2;
int ds_xbits;
int ds_ybits;
const uint8_t *ds_source;
bool ds_source_mipmapped;
dsfixed_t ds_xfrac;
dsfixed_t ds_yfrac;
dsfixed_t ds_xstep;
dsfixed_t ds_ystep;
uint32_t *dc_srcblend;
uint32_t *dc_destblend;
fixed_t dc_srcalpha;
fixed_t dc_destalpha;
int ds_color = 0;
double ds_lod;
}; };
class WallDrawerArgs : public DrawerArgs class WallDrawerArgs : public DrawerArgs

View file

@ -51,15 +51,15 @@ namespace swrenderer
return; return;
} }
drawerargs.ds_color = 3; drawerargs.SetSolidColor(3);
drawerargs.SetSpanTexture(texture); drawerargs.SetTexture(texture);
double planeang = (pl->xform.Angle + pl->xform.baseAngle).Radians(); double planeang = (pl->xform.Angle + pl->xform.baseAngle).Radians();
double xstep, ystep, leftxfrac, leftyfrac, rightxfrac, rightyfrac; double xstep, ystep, leftxfrac, leftyfrac, rightxfrac, rightyfrac;
double x; double x;
xscale = xs_ToFixed(32 - drawerargs.ds_xbits, _xscale); xscale = xs_ToFixed(32 - drawerargs.TextureWidthBits(), _xscale);
yscale = xs_ToFixed(32 - drawerargs.ds_ybits, _yscale); yscale = xs_ToFixed(32 - drawerargs.TextureHeightBits(), _yscale);
if (planeang != 0) if (planeang != 0)
{ {
double cosine = cos(planeang), sine = sin(planeang); double cosine = cos(planeang), sine = sin(planeang);
@ -126,7 +126,7 @@ namespace swrenderer
planeshade = LIGHT2SHADE(pl->lightlevel); planeshade = LIGHT2SHADE(pl->lightlevel);
} }
drawerargs.SetSpanStyle(masked, additive, alpha); drawerargs.SetStyle(masked, additive, alpha);
light_list = pl->lights; light_list = pl->lights;
@ -149,25 +149,26 @@ namespace swrenderer
distance = planeheight * yslope[y]; distance = planeheight * yslope[y];
if (drawerargs.ds_xbits != 0) if (drawerargs.TextureWidthBits() != 0)
{ {
drawerargs.ds_xstep = xs_ToFixed(32 - drawerargs.ds_xbits, distance * xstepscale); drawerargs.SetTextureUStep(xs_ToFixed(32 - drawerargs.TextureWidthBits(), distance * xstepscale));
drawerargs.ds_xfrac = xs_ToFixed(32 - drawerargs.ds_xbits, distance * basexfrac) + pviewx; drawerargs.SetTextureUPos(xs_ToFixed(32 - drawerargs.TextureWidthBits(), distance * basexfrac) + pviewx);
} }
else else
{ {
drawerargs.ds_xstep = 0; drawerargs.SetTextureUStep(0);
drawerargs.ds_xfrac = 0; drawerargs.SetTextureUPos(0);
} }
if (drawerargs.ds_ybits != 0)
if (drawerargs.TextureHeightBits() != 0)
{ {
drawerargs.ds_ystep = xs_ToFixed(32 - drawerargs.ds_ybits, distance * ystepscale); drawerargs.SetTextureVStep(xs_ToFixed(32 - drawerargs.TextureHeightBits(), distance * ystepscale));
drawerargs.ds_yfrac = xs_ToFixed(32 - drawerargs.ds_ybits, distance * baseyfrac) + pviewy; drawerargs.SetTextureVPos(xs_ToFixed(32 - drawerargs.TextureHeightBits(), distance * baseyfrac) + pviewy);
} }
else else
{ {
drawerargs.ds_ystep = 0; drawerargs.SetTextureVStep(0);
drawerargs.ds_yfrac = 0; drawerargs.SetTextureVPos(0);
} }
if (r_swtruecolor) if (r_swtruecolor)
@ -177,7 +178,7 @@ namespace swrenderer
double ymagnitude = fabs(xstepscale * (distance2 - distance) * FocalLengthX); double ymagnitude = fabs(xstepscale * (distance2 - distance) * FocalLengthX);
double magnitude = MAX(ymagnitude, xmagnitude); double magnitude = MAX(ymagnitude, xmagnitude);
double min_lod = -1000.0; double min_lod = -1000.0;
drawerargs.ds_lod = MAX(log2(magnitude) + r_lod_bias, min_lod); drawerargs.SetTextureLOD(MAX(log2(magnitude) + r_lod_bias, min_lod));
} }
if (plane_shade) if (plane_shade)
@ -250,9 +251,9 @@ namespace swrenderer
drawerargs.dc_num_lights = 0; drawerargs.dc_num_lights = 0;
} }
drawerargs.ds_y = y; drawerargs.SetDestY(y);
drawerargs.ds_x1 = x1; drawerargs.SetDestX1(x1);
drawerargs.ds_x2 = x2; drawerargs.SetDestX2(x2);
drawerargs.DrawSpan(); drawerargs.DrawSpan();
} }

View file

@ -70,17 +70,17 @@ namespace swrenderer
return; return;
} }
drawerargs.ds_color = 3; drawerargs.SetSolidColor(3);
drawerargs.SetSpanTexture(texture); drawerargs.SetTexture(texture);
lxscale = _xscale * ifloatpow2[drawerargs.ds_xbits]; lxscale = _xscale * ifloatpow2[drawerargs.TextureWidthBits()];
lyscale = _yscale * ifloatpow2[drawerargs.ds_ybits]; lyscale = _yscale * ifloatpow2[drawerargs.TextureHeightBits()];
xscale = 64.f / lxscale; xscale = 64.f / lxscale;
yscale = 64.f / lyscale; yscale = 64.f / lyscale;
zeroheight = pl->height.ZatPoint(ViewPos); zeroheight = pl->height.ZatPoint(ViewPos);
pviewx = xs_ToFixed(32 - drawerargs.ds_xbits, pl->xform.xOffs * pl->xform.xScale); pviewx = xs_ToFixed(32 - drawerargs.TextureWidthBits(), pl->xform.xOffs * pl->xform.xScale);
pviewy = xs_ToFixed(32 - drawerargs.ds_ybits, pl->xform.yOffs * pl->xform.yScale); pviewy = xs_ToFixed(32 - drawerargs.TextureHeightBits(), pl->xform.yOffs * pl->xform.yScale);
planeang = (pl->xform.Angle + pl->xform.baseAngle).Radians(); planeang = (pl->xform.Angle + pl->xform.baseAngle).Radians();
// p is the texture origin in view space // p is the texture origin in view space
@ -170,11 +170,11 @@ namespace swrenderer
} }
// Hack in support for 1 x Z and Z x 1 texture sizes // Hack in support for 1 x Z and Z x 1 texture sizes
if (drawerargs.ds_ybits == 0) if (drawerargs.TextureHeightBits() == 0)
{ {
plane_sv[2] = plane_sv[1] = plane_sv[0] = 0; plane_sv[2] = plane_sv[1] = plane_sv[0] = 0;
} }
if (drawerargs.ds_xbits == 0) if (drawerargs.TextureWidthBits() == 0)
{ {
plane_su[2] = plane_su[1] = plane_su[0] = 0; plane_su[2] = plane_su[1] = plane_su[0] = 0;
} }

View file

@ -1384,30 +1384,30 @@ void DCanvas::FillSimplePoly(FTexture *tex, FVector2 *points, int npoints,
// Setup constant texture mapping parameters. // Setup constant texture mapping parameters.
SpanDrawerArgs drawerargs; SpanDrawerArgs drawerargs;
drawerargs.SetSpanTexture(tex); drawerargs.SetTexture(tex);
if (colormap) if (colormap)
drawerargs.SetColorMapLight(colormap, 0, clamp(shade >> FRACBITS, 0, NUMCOLORMAPS - 1)); drawerargs.SetColorMapLight(colormap, 0, clamp(shade >> FRACBITS, 0, NUMCOLORMAPS - 1));
else else
drawerargs.SetColorMapLight(&identitycolormap, 0, 0); drawerargs.SetColorMapLight(&identitycolormap, 0, 0);
if (drawerargs.ds_xbits != 0) if (drawerargs.TextureWidthBits() != 0)
{ {
scalex = double(1u << (32 - drawerargs.ds_xbits)) / scalex; scalex = double(1u << (32 - drawerargs.TextureWidthBits())) / scalex;
drawerargs.ds_xstep = xs_RoundToInt(cosrot * scalex); drawerargs.SetTextureUStep(xs_RoundToInt(cosrot * scalex));
} }
else else
{ // Texture is one pixel wide. { // Texture is one pixel wide.
scalex = 0; scalex = 0;
drawerargs.ds_xstep = 0; drawerargs.SetTextureUStep(0);
} }
if (drawerargs.ds_ybits != 0) if (drawerargs.TextureHeightBits() != 0)
{ {
scaley = double(1u << (32 - drawerargs.ds_ybits)) / scaley; scaley = double(1u << (32 - drawerargs.TextureHeightBits())) / scaley;
drawerargs.ds_ystep = xs_RoundToInt(sinrot * scaley); drawerargs.SetTextureVStep(xs_RoundToInt(sinrot * scaley));
} }
else else
{ // Texture is one pixel tall. { // Texture is one pixel tall.
scaley = 0; scaley = 0;
drawerargs.ds_ystep = 0; drawerargs.SetTextureVStep(0);
} }
// Travel down the right edge and create an outline of that edge. // Travel down the right edge and create an outline of that edge.
@ -1473,9 +1473,9 @@ void DCanvas::FillSimplePoly(FTexture *tex, FVector2 *points, int npoints,
#if 0 #if 0
memset(this->Buffer + y * this->Pitch + x1, (int)tex, x2 - x1); memset(this->Buffer + y * this->Pitch + x1, (int)tex, x2 - x1);
#else #else
drawerargs.ds_y = y; drawerargs.SetDestY(y);
drawerargs.ds_x1 = x1; drawerargs.SetDestX1(x1);
drawerargs.ds_x2 = x2 - 1; drawerargs.SetDestX2(x2 - 1);
DVector2 tex(x1 - originx, y - originy); DVector2 tex(x1 - originx, y - originy);
if (dorotate) if (dorotate)
@ -1484,8 +1484,8 @@ void DCanvas::FillSimplePoly(FTexture *tex, FVector2 *points, int npoints,
tex.X = t * cosrot - tex.Y * sinrot; tex.X = t * cosrot - tex.Y * sinrot;
tex.Y = tex.Y * cosrot + t * sinrot; tex.Y = tex.Y * cosrot + t * sinrot;
} }
drawerargs.ds_xfrac = xs_RoundToInt(tex.X * scalex); drawerargs.SetTextureUPos(xs_RoundToInt(tex.X * scalex));
drawerargs.ds_yfrac = xs_RoundToInt(tex.Y * scaley); drawerargs.SetTextureVPos(xs_RoundToInt(tex.Y * scaley));
drawerargs.DrawSpan(); drawerargs.DrawSpan();
#endif #endif