Move wall drawer args into functions

This commit is contained in:
Magnus Norddahl 2017-02-02 11:16:18 +01:00
parent 226e5238fc
commit f3d968cf41
17 changed files with 112 additions and 90 deletions

View file

@ -98,17 +98,17 @@ namespace swrenderer
{
PalWall1Command::PalWall1Command(const WallDrawerArgs &args)
{
_iscale = args.dc_iscale;
_texturefrac = args.dc_texturefrac;
_iscale = args.TextureVStep();
_texturefrac = args.TextureVPos();
_colormap = args.Colormap();
_count = args.dc_count;
_source = args.dc_source;
_count = args.Count();
_source = args.TexturePixels();
_dest = args.Dest();
_dest_y = args.DestY();
_fracbits = args.dc_wall_fracbits;
_fracbits = args.TextureFracBits();
_pitch = RenderViewport::Instance()->RenderTarget->GetPitch();
_srcblend = args.dc_srcblend;
_destblend = args.dc_destblend;
_srcblend = args.SrcBlend();
_destblend = args.DestBlend();
_dynlights = args.dc_lights;
_num_dynlights = args.dc_num_lights;
_viewpos_z = args.dc_viewpos.Z;

View file

@ -187,13 +187,13 @@ namespace swrenderer
args.dest = (uint32_t*)drawerargs.Dest();
args.dest_y = drawerargs.DestY();
args.pitch = RenderViewport::Instance()->RenderTarget->GetPitch();
args.count = drawerargs.dc_count;
args.texturefrac[0] = drawerargs.dc_texturefrac;
args.texturefracx[0] = drawerargs.dc_texturefracx;
args.iscale[0] = drawerargs.dc_iscale;
args.textureheight[0] = drawerargs.dc_textureheight;
args.source[0] = (const uint32 *)drawerargs.dc_source;
args.source2[0] = (const uint32 *)drawerargs.dc_source2;
args.count = drawerargs.Count();
args.texturefrac[0] = drawerargs.TextureVPos();
args.texturefracx[0] = drawerargs.TextureUPos();
args.iscale[0] = drawerargs.TextureVStep();
args.textureheight[0] = drawerargs.TextureHeight();
args.source[0] = (const uint32 *)drawerargs.TexturePixels();
args.source2[0] = (const uint32 *)drawerargs.TexturePixels2();
args.light[0] = LightBgra::calc_light_multiplier(drawerargs.Light());
args.light_red = shade_constants.light_red;
args.light_green = shade_constants.light_green;
@ -204,8 +204,8 @@ namespace swrenderer
args.fade_blue = shade_constants.fade_blue;
args.fade_alpha = shade_constants.fade_alpha;
args.desaturate = shade_constants.desaturate;
args.srcalpha = drawerargs.dc_srcalpha >> (FRACBITS - 8);
args.destalpha = drawerargs.dc_destalpha >> (FRACBITS - 8);
args.srcalpha = drawerargs.SrcAlpha() >> (FRACBITS - 8);
args.destalpha = drawerargs.DestAlpha() >> (FRACBITS - 8);
args.flags = 0;
if (shade_constants.simple_shade)
args.flags |= DrawWallArgs::simple_shade;

View file

@ -63,7 +63,7 @@ namespace swrenderer
spanfunc = &SWPixelFormatDrawers::DrawSpan;
}
void DrawerArgs::SetColorMapLight(FSWColormap *base_colormap, float light, int shade)
void DrawerArgs::SetLight(FSWColormap *base_colormap, float light, int shade)
{
mBaseColormap = base_colormap;
mTranslation = nullptr;
@ -542,11 +542,11 @@ namespace swrenderer
{
fixed_t shade = shadedlightshade;
if (shade == 0) FIXEDLIGHT2SHADE(cameraLight->fixedlightlev);
SetColorMapLight(basecolormap, 0, shade);
SetLight(basecolormap, 0, shade);
}
else
{
SetColorMapLight(basecolormap, 0, shadedlightshade);
SetLight(basecolormap, 0, shadedlightshade);
}
return true;
}
@ -573,7 +573,7 @@ namespace swrenderer
// 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;
SetColorMapLight(&identitycolormap, 0, 0);
SetLight(&identitycolormap, 0, 0);
}
if (!SpriteDrawerArgs::SetBlendFunc(style.BlendOp, fglevel, bglevel, style.Flags))

View file

@ -24,7 +24,7 @@ namespace swrenderer
class DrawerArgs
{
public:
void SetColorMapLight(FSWColormap *base_colormap, float light, int shade);
void SetLight(FSWColormap *base_colormap, float light, int shade);
void SetTranslationMap(lighttable_t *translation);
uint8_t *Colormap() const;
@ -70,7 +70,7 @@ namespace swrenderer
const uint8_t *FrontTexturePixels() const { return dc_source; }
const uint8_t *BackTexturePixels() const { return dc_source2; }
int FrontTextureHeight() const { return dc_sourceheight; }
int BackTextureHeight() const { return dc_sourceheight; }
int BackTextureHeight() const { return dc_sourceheight2; }
void DrawSingleSkyColumn();
void DrawDoubleSkyColumn();
@ -164,6 +164,17 @@ namespace swrenderer
public:
void SetStyle(bool masked, bool additive, fixed_t alpha);
void SetDest(int x, int y);
void SetCount(int count) { dc_count = count; }
void SetTexture(const uint8_t *pixels, const uint8_t *pixels2, int height)
{
dc_source = pixels;
dc_source2 = pixels2;
dc_textureheight = height;
}
void SetTextureFracBits(int bits) { dc_wall_fracbits = bits; }
void SetTextureUPos(uint32_t pos) { dc_texturefracx = pos; }
void SetTextureVPos(fixed_t pos) { dc_texturefrac = pos; }
void SetTextureVStep(fixed_t step) { dc_iscale = step; }
bool IsMaskedDrawer() const;
@ -171,21 +182,22 @@ namespace swrenderer
uint8_t *Dest() const { return dc_dest; }
int DestY() const { return dc_dest_y; }
int Count() const { return dc_count; }
uint32_t *dc_srcblend;
uint32_t *dc_destblend;
fixed_t dc_srcalpha;
fixed_t dc_destalpha;
uint32_t *SrcBlend() const { return dc_srcblend; }
uint32_t *DestBlend() const { return dc_destblend; }
fixed_t SrcAlpha() const { return dc_srcalpha; }
fixed_t DestAlpha() const { return dc_destalpha; }
fixed_t dc_iscale;
fixed_t dc_texturefrac;
uint32_t dc_texturefracx;
uint32_t dc_textureheight;
const uint8_t *dc_source;
const uint8_t *dc_source2;
int dc_count;
int dc_wall_fracbits;
uint32_t TextureUPos() const { return dc_texturefracx; }
fixed_t TextureVPos() const { return dc_texturefrac; }
fixed_t TextureVStep() const { return dc_iscale; }
uint32_t TextureHeight() const { return dc_textureheight; }
const uint8_t *TexturePixels() const { return dc_source; }
const uint8_t *TexturePixels2() const { return dc_source2; }
int TextureFracBits() const { return dc_wall_fracbits; }
FVector3 dc_normal;
FVector3 dc_viewpos;
@ -196,6 +208,20 @@ namespace swrenderer
private:
uint8_t *dc_dest = nullptr;
int dc_dest_y = 0;
int dc_count;
fixed_t dc_iscale;
fixed_t dc_texturefrac;
uint32_t dc_texturefracx;
uint32_t dc_textureheight;
const uint8_t *dc_source;
const uint8_t *dc_source2;
int dc_wall_fracbits;
uint32_t *dc_srcblend;
uint32_t *dc_destblend;
fixed_t dc_srcalpha;
fixed_t dc_destalpha;
typedef void(SWPixelFormatDrawers::*WallDrawerFunc)(const WallDrawerArgs &args);
WallDrawerFunc wallfunc = nullptr;

View file

@ -64,7 +64,7 @@ namespace swrenderer
fillshort(spanend + t2, b2 - t2, x);
}
drawerargs.SetColorMapLight(basecolormap, (float)light, wallshade);
drawerargs.SetLight(basecolormap, (float)light, wallshade);
uint8_t *fake_dc_colormap = basecolormap->Maps + (GETPALOOKUP(light, wallshade) << COLORMAPSHIFT);
@ -91,7 +91,7 @@ namespace swrenderer
fillshort(spanend + t2, b2 - t2, x);
}
rcolormap = lcolormap;
drawerargs.SetColorMapLight(basecolormap, (float)light, wallshade);
drawerargs.SetLight(basecolormap, (float)light, wallshade);
fake_dc_colormap = basecolormap->Maps + (GETPALOOKUP(light, wallshade) << COLORMAPSHIFT);
}
else

View file

@ -936,9 +936,9 @@ namespace swrenderer
CameraLight *cameraLight = CameraLight::Instance();
if (cameraLight->fixedlightlev >= 0)
drawerargs.SetColorMapLight((r_fullbrightignoresectorcolor) ? &FullNormalLight : basecolormap, 0, FIXEDLIGHT2SHADE(cameraLight->fixedlightlev));
drawerargs.SetLight((r_fullbrightignoresectorcolor) ? &FullNormalLight : basecolormap, 0, FIXEDLIGHT2SHADE(cameraLight->fixedlightlev));
else if (cameraLight->fixedcolormap != nullptr)
drawerargs.SetColorMapLight(cameraLight->fixedcolormap, 0, 0);
drawerargs.SetLight(cameraLight->fixedcolormap, 0, 0);
// clip wall to the floor and ceiling
auto ceilingclip = RenderOpaquePass::Instance()->ceilingclip;

View file

@ -149,13 +149,13 @@ namespace swrenderer
if (cameraLight->fixedlightlev >= 0)
{
walldrawerargs.SetColorMapLight((r_fullbrightignoresectorcolor) ? &FullNormalLight : basecolormap, 0, FIXEDLIGHT2SHADE(cameraLight->fixedlightlev));
columndrawerargs.SetColorMapLight((r_fullbrightignoresectorcolor) ? &FullNormalLight : basecolormap, 0, FIXEDLIGHT2SHADE(cameraLight->fixedlightlev));
walldrawerargs.SetLight((r_fullbrightignoresectorcolor) ? &FullNormalLight : basecolormap, 0, FIXEDLIGHT2SHADE(cameraLight->fixedlightlev));
columndrawerargs.SetLight((r_fullbrightignoresectorcolor) ? &FullNormalLight : basecolormap, 0, FIXEDLIGHT2SHADE(cameraLight->fixedlightlev));
}
else if (cameraLight->fixedcolormap != nullptr)
{
walldrawerargs.SetColorMapLight(cameraLight->fixedcolormap, 0, 0);
columndrawerargs.SetColorMapLight(cameraLight->fixedcolormap, 0, 0);
walldrawerargs.SetLight(cameraLight->fixedcolormap, 0, 0);
columndrawerargs.SetLight(cameraLight->fixedcolormap, 0, 0);
}
// find positioning
@ -285,7 +285,7 @@ namespace swrenderer
{
if (cameraLight->fixedcolormap == nullptr && cameraLight->fixedlightlev < 0)
{
columndrawerargs.SetColorMapLight(basecolormap, rw_light, wallshade);
columndrawerargs.SetLight(basecolormap, rw_light, wallshade);
}
fixed_t iscale = xs_Fix<16>::ToFix(MaskedSWall[x] * MaskedScaleY);
@ -456,9 +456,9 @@ namespace swrenderer
CameraLight *cameraLight = CameraLight::Instance();
if (cameraLight->fixedlightlev >= 0)
drawerargs.SetColorMapLight((r_fullbrightignoresectorcolor) ? &FullNormalLight : basecolormap, 0, FIXEDLIGHT2SHADE(cameraLight->fixedlightlev));
drawerargs.SetLight((r_fullbrightignoresectorcolor) ? &FullNormalLight : basecolormap, 0, FIXEDLIGHT2SHADE(cameraLight->fixedlightlev));
else if (cameraLight->fixedcolormap != nullptr)
drawerargs.SetColorMapLight(cameraLight->fixedcolormap, 0, 0);
drawerargs.SetLight(cameraLight->fixedcolormap, 0, 0);
WallC.sz1 = ds->sz1;
WallC.sz2 = ds->sz2;

View file

@ -244,14 +244,12 @@ namespace swrenderer
{
int count = y2 - y1;
drawerargs.dc_source = sampler.source;
drawerargs.dc_source2 = sampler.source2;
drawerargs.dc_texturefracx = sampler.texturefracx;
drawerargs.SetTexture(sampler.source, sampler.source2, sampler.height);
drawerargs.SetTextureUPos(sampler.texturefracx);
drawerargs.SetDest(x, y1);
drawerargs.dc_count = count;
drawerargs.dc_iscale = sampler.uv_step;
drawerargs.dc_texturefrac = sampler.uv_pos;
drawerargs.dc_textureheight = sampler.height;
drawerargs.SetCount(count);
drawerargs.SetTextureVStep(sampler.uv_step);
drawerargs.SetTextureVPos(sampler.uv_pos);
drawerargs.DrawColumn();
uint64_t step64 = sampler.uv_step;
@ -264,13 +262,12 @@ namespace swrenderer
{
int count = y2 - y1;
drawerargs.dc_source = sampler.source;
drawerargs.dc_source2 = sampler.source2;
drawerargs.dc_texturefracx = sampler.texturefracx;
drawerargs.SetTexture(sampler.source, sampler.source2, sampler.height);
drawerargs.SetTextureUPos(sampler.texturefracx);
drawerargs.SetDest(x, y1);
drawerargs.dc_count = count;
drawerargs.dc_iscale = sampler.uv_step;
drawerargs.dc_texturefrac = sampler.uv_pos;
drawerargs.SetCount(count);
drawerargs.SetTextureVStep(sampler.uv_step);
drawerargs.SetTextureVPos(sampler.uv_pos);
drawerargs.DrawColumn();
uint64_t step64 = sampler.uv_step;
@ -290,13 +287,12 @@ namespace swrenderer
next_uv_wrap++;
uint32_t count = MIN(left, next_uv_wrap);
drawerargs.dc_source = sampler.source;
drawerargs.dc_source2 = sampler.source2;
drawerargs.dc_texturefracx = sampler.texturefracx;
drawerargs.SetTexture(sampler.source, sampler.source2, sampler.height);
drawerargs.SetTextureUPos(sampler.texturefracx);
drawerargs.SetDest(x, y1);
drawerargs.dc_count = count;
drawerargs.dc_iscale = sampler.uv_step;
drawerargs.dc_texturefrac = uv_pos;
drawerargs.SetCount(count);
drawerargs.SetTextureVStep(sampler.uv_step);
drawerargs.SetTextureVPos(uv_pos);
drawerargs.DrawColumn();
left -= count;
@ -324,15 +320,15 @@ namespace swrenderer
texturemid = 0;
}
drawerargs.dc_wall_fracbits = RenderViewport::Instance()->RenderTarget->IsBgra() ? FRACBITS : fracbits;
drawerargs.SetTextureFracBits(RenderViewport::Instance()->RenderTarget->IsBgra() ? FRACBITS : fracbits);
CameraLight *cameraLight = CameraLight::Instance();
bool fixed = (cameraLight->fixedcolormap != NULL || cameraLight->fixedlightlev >= 0);
if (cameraLight->fixedcolormap)
drawerargs.SetColorMapLight(cameraLight->fixedcolormap, 0, 0);
drawerargs.SetLight(cameraLight->fixedcolormap, 0, 0);
else
drawerargs.SetColorMapLight(basecolormap, 0, 0);
drawerargs.SetLight(basecolormap, 0, 0);
float dx = WallC.tright.X - WallC.tleft.X;
float dy = WallC.tright.Y - WallC.tleft.Y;
@ -351,7 +347,7 @@ namespace swrenderer
continue;
if (!fixed)
drawerargs.SetColorMapLight(basecolormap, light, wallshade);
drawerargs.SetLight(basecolormap, light, wallshade);
if (x + 1 < x2) xmagnitude = fabs(FIXED2DBL(lwal[x + 1]) - FIXED2DBL(lwal[x]));

View file

@ -114,12 +114,12 @@ namespace swrenderer
CameraLight *cameraLight = CameraLight::Instance();
if (cameraLight->fixedlightlev >= 0)
{
drawerargs.SetColorMapLight(basecolormap, 0, FIXEDLIGHT2SHADE(cameraLight->fixedlightlev));
drawerargs.SetLight(basecolormap, 0, FIXEDLIGHT2SHADE(cameraLight->fixedlightlev));
plane_shade = false;
}
else if (cameraLight->fixedcolormap)
{
drawerargs.SetColorMapLight(cameraLight->fixedcolormap, 0, 0);
drawerargs.SetLight(cameraLight->fixedcolormap, 0, 0);
plane_shade = false;
}
else
@ -188,7 +188,7 @@ namespace swrenderer
if (plane_shade)
{
// Determine lighting based on the span's distance from the viewer.
drawerargs.SetColorMapLight(basecolormap, (float)(GlobVis * fabs(viewport->CenterY - y)), planeshade);
drawerargs.SetLight(basecolormap, (float)(GlobVis * fabs(viewport->CenterY - y)), planeshade);
}
if (r_dynlights)

View file

@ -151,13 +151,13 @@ namespace swrenderer
CameraLight *cameraLight = CameraLight::Instance();
if (cameraLight->fixedcolormap)
{
drawerargs.SetColorMapLight(cameraLight->fixedcolormap, 0, 0);
drawerargs.SetLight(cameraLight->fixedcolormap, 0, 0);
}
else
{
fakefixed = true;
cameraLight->fixedcolormap = &NormalLight;
drawerargs.SetColorMapLight(cameraLight->fixedcolormap, 0, 0);
drawerargs.SetLight(cameraLight->fixedcolormap, 0, 0);
}
DrawSky(pl);

View file

@ -156,17 +156,17 @@ namespace swrenderer
CameraLight *cameraLight = CameraLight::Instance();
if (cameraLight->fixedlightlev >= 0)
{
drawerargs.SetColorMapLight(basecolormap, 0, FIXEDLIGHT2SHADE(cameraLight->fixedlightlev));
drawerargs.SetLight(basecolormap, 0, FIXEDLIGHT2SHADE(cameraLight->fixedlightlev));
plane_shade = false;
}
else if (cameraLight->fixedcolormap)
{
drawerargs.SetColorMapLight(cameraLight->fixedcolormap, 0, 0);
drawerargs.SetLight(cameraLight->fixedcolormap, 0, 0);
plane_shade = false;
}
else
{
drawerargs.SetColorMapLight(basecolormap, 0, 0);
drawerargs.SetLight(basecolormap, 0, 0);
plane_shade = true;
planeshade = LIGHT2SHADE(pl->lightlevel);
}

View file

@ -277,11 +277,11 @@ namespace swrenderer
SpriteDrawerArgs drawerargs;
if (cameraLight->fixedlightlev >= 0)
drawerargs.SetColorMapLight((r_fullbrightignoresectorcolor) ? &FullNormalLight : usecolormap, 0, FIXEDLIGHT2SHADE(cameraLight->fixedlightlev));
drawerargs.SetLight((r_fullbrightignoresectorcolor) ? &FullNormalLight : usecolormap, 0, FIXEDLIGHT2SHADE(cameraLight->fixedlightlev));
else if (cameraLight->fixedcolormap != NULL)
drawerargs.SetColorMapLight(cameraLight->fixedcolormap, 0, 0);
drawerargs.SetLight(cameraLight->fixedcolormap, 0, 0);
else if (!foggy && (decal->RenderFlags & RF_FULLBRIGHT))
drawerargs.SetColorMapLight((r_fullbrightignoresectorcolor) ? &FullNormalLight : usecolormap, 0, 0);
drawerargs.SetLight((r_fullbrightignoresectorcolor) ? &FullNormalLight : usecolormap, 0, 0);
else
calclighting = true;
@ -299,7 +299,7 @@ namespace swrenderer
{
if (calclighting)
{ // calculate lighting
drawerargs.SetColorMapLight(usecolormap, light, wallshade);
drawerargs.SetLight(usecolormap, light, wallshade);
}
DrawColumn(drawerargs, x, WallSpriteTile, walltexcoords, texturemid, maskedScaleY, sprflipvert, mfloorclip, mceilingclip);
light += lightstep;

View file

@ -592,7 +592,7 @@ namespace swrenderer
}
SpriteDrawerArgs drawerargs;
drawerargs.SetColorMapLight(Light.BaseColormap, 0, Light.ColormapNum << FRACBITS);
drawerargs.SetLight(Light.BaseColormap, 0, Light.ColormapNum << FRACBITS);
FDynamicColormap *basecolormap = static_cast<FDynamicColormap*>(Light.BaseColormap);

View file

@ -248,7 +248,7 @@ namespace swrenderer
}
SpriteDrawerArgs drawerargs;
drawerargs.SetColorMapLight(vis->Light.BaseColormap, 0, vis->Light.ColormapNum << FRACBITS);
drawerargs.SetLight(vis->Light.BaseColormap, 0, vis->Light.ColormapNum << FRACBITS);
FDynamicColormap *basecolormap = static_cast<FDynamicColormap*>(vis->Light.BaseColormap);

View file

@ -189,7 +189,7 @@ namespace swrenderer
FDynamicColormap *basecolormap = static_cast<FDynamicColormap*>(sprite->Light.BaseColormap);
SpriteDrawerArgs drawerargs;
drawerargs.SetColorMapLight(sprite->Light.BaseColormap, 0, sprite->Light.ColormapNum << FRACBITS);
drawerargs.SetLight(sprite->Light.BaseColormap, 0, sprite->Light.ColormapNum << FRACBITS);
bool visible = drawerargs.SetPatchStyle(sprite->RenderStyle, sprite->Alpha, sprite->Translation, sprite->FillColor, basecolormap);
if (!visible)

View file

@ -188,11 +188,11 @@ namespace swrenderer
float light = lightleft + (x1 - spr->wallc.sx1) * lightstep;
CameraLight *cameraLight = CameraLight::Instance();
if (cameraLight->fixedlightlev >= 0)
drawerargs.SetColorMapLight(usecolormap, 0, FIXEDLIGHT2SHADE(cameraLight->fixedlightlev));
drawerargs.SetLight(usecolormap, 0, FIXEDLIGHT2SHADE(cameraLight->fixedlightlev));
else if (cameraLight->fixedcolormap != NULL)
drawerargs.SetColorMapLight(cameraLight->fixedcolormap, 0, 0);
drawerargs.SetLight(cameraLight->fixedcolormap, 0, 0);
else if (!spr->foggy && (spr->renderflags & RF_FULLBRIGHT))
drawerargs.SetColorMapLight((r_fullbrightignoresectorcolor) ? &FullNormalLight : usecolormap, 0, 0);
drawerargs.SetLight((r_fullbrightignoresectorcolor) ? &FullNormalLight : usecolormap, 0, 0);
else
calclighting = true;
@ -235,7 +235,7 @@ namespace swrenderer
{
if (calclighting)
{ // calculate lighting
drawerargs.SetColorMapLight(usecolormap, light, shade);
drawerargs.SetLight(usecolormap, light, shade);
}
if (!translucentPass->ClipSpriteColumnWithPortals(x, spr))
DrawColumn(drawerargs, x, WallSpriteTile, walltexcoords, texturemid, maskedScaleY, sprflipvert, mfloorclip, mceilingclip);

View file

@ -1371,9 +1371,9 @@ void DCanvas::FillSimplePoly(FTexture *tex, FVector2 *points, int npoints,
SpanDrawerArgs drawerargs;
drawerargs.SetTexture(tex);
if (colormap)
drawerargs.SetColorMapLight(colormap, 0, clamp(shade >> FRACBITS, 0, NUMCOLORMAPS - 1));
drawerargs.SetLight(colormap, 0, clamp(shade >> FRACBITS, 0, NUMCOLORMAPS - 1));
else
drawerargs.SetColorMapLight(&identitycolormap, 0, 0);
drawerargs.SetLight(&identitycolormap, 0, 0);
if (drawerargs.TextureWidthBits() != 0)
{
scalex = double(1u << (32 - drawerargs.TextureWidthBits())) / scalex;