From d8c6f9acfd8dfb15b2bac849f041980f71dea830 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Thu, 2 Feb 2017 13:51:41 +0100 Subject: [PATCH] Limit access to sprite drawer variables --- src/swrenderer/drawers/r_draw.cpp | 4 +- src/swrenderer/drawers/r_draw_pal.cpp | 26 +++++----- src/swrenderer/drawers/r_draw_rgba.cpp | 28 +++++------ src/swrenderer/drawers/r_drawerargs.h | 68 +++++++++++++++++--------- src/swrenderer/things/r_voxel.cpp | 4 +- 5 files changed, 77 insertions(+), 53 deletions(-) diff --git a/src/swrenderer/drawers/r_draw.cpp b/src/swrenderer/drawers/r_draw.cpp index 2e0539204d..890b394df0 100644 --- a/src/swrenderer/drawers/r_draw.cpp +++ b/src/swrenderer/drawers/r_draw.cpp @@ -157,8 +157,8 @@ namespace swrenderer void R_UpdateFuzzPos(const SpriteDrawerArgs &args) { - int yl = MAX(args.dc_yl, 1); - int yh = MIN(args.dc_yh, fuzzviewheight); + int yl = MAX(args.FuzzY1(), 1); + int yh = MIN(args.FuzzY2(), fuzzviewheight); if (yl <= yh) fuzzpos = (fuzzpos + yh - yl + 1) % FUZZTABLE; } diff --git a/src/swrenderer/drawers/r_draw_pal.cpp b/src/swrenderer/drawers/r_draw_pal.cpp index 81f7999d17..856c5b7b77 100644 --- a/src/swrenderer/drawers/r_draw_pal.cpp +++ b/src/swrenderer/drawers/r_draw_pal.cpp @@ -867,21 +867,21 @@ namespace swrenderer PalColumnCommand::PalColumnCommand(const SpriteDrawerArgs &args) { - _count = args.dc_count; + _count = args.Count(); _dest = args.Dest(); _dest_y = args.DestY(); _pitch = RenderViewport::Instance()->RenderTarget->GetPitch(); - _iscale = args.dc_iscale; - _texturefrac = args.dc_texturefrac; + _iscale = args.TextureVStep(); + _texturefrac = args.TextureVPos(); _colormap = args.Colormap(); - _source = args.dc_source; + _source = args.TexturePixels(); _translation = args.TranslationMap(); - _color = args.dc_color; - _srcblend = args.dc_srcblend; - _destblend = args.dc_destblend; - _srccolor = args.dc_srccolor; - _srcalpha = args.dc_srcalpha; - _destalpha = args.dc_destalpha; + _color = args.SolidColor(); + _srcblend = args.SrcBlend(); + _destblend = args.DestBlend(); + _srccolor = args.SrcColorIndex(); + _srcalpha = args.SrcAlpha(); + _destalpha = args.DestAlpha(); } void DrawColumnPalCommand::Execute(DrawerThread *thread) @@ -1764,9 +1764,9 @@ namespace swrenderer DrawFuzzColumnPalCommand::DrawFuzzColumnPalCommand(const SpriteDrawerArgs &args) { - _yl = args.dc_yl; - _yh = args.dc_yh; - _x = args.dc_x; + _yl = args.FuzzY1(); + _yh = args.FuzzY2(); + _x = args.FuzzX(); _destorg = RenderViewport::Instance()->GetDest(0, 0); _pitch = RenderViewport::Instance()->RenderTarget->GetPitch(); _fuzzpos = fuzzpos; diff --git a/src/swrenderer/drawers/r_draw_rgba.cpp b/src/swrenderer/drawers/r_draw_rgba.cpp index 0c5d9ec820..9806c6d8c2 100644 --- a/src/swrenderer/drawers/r_draw_rgba.cpp +++ b/src/swrenderer/drawers/r_draw_rgba.cpp @@ -251,23 +251,23 @@ namespace swrenderer auto shade_constants = drawerargs.ColormapConstants(); args.dest = (uint32_t*)drawerargs.Dest(); - args.source = drawerargs.dc_source; - args.source2 = drawerargs.dc_source2; + args.source = drawerargs.TexturePixels(); + args.source2 = drawerargs.TexturePixels2(); args.colormap = drawerargs.Colormap(); args.translation = drawerargs.TranslationMap(); args.basecolors = (const uint32_t *)GPalette.BaseColors; args.pitch = RenderViewport::Instance()->RenderTarget->GetPitch(); - args.count = drawerargs.dc_count; + args.count = drawerargs.Count(); args.dest_y = drawerargs.DestY(); - args.iscale = drawerargs.dc_iscale; - args.texturefracx = drawerargs.dc_texturefracx; - args.textureheight = drawerargs.dc_textureheight; - args.texturefrac = drawerargs.dc_texturefrac; + args.iscale = drawerargs.TextureVStep(); + args.texturefracx = drawerargs.TextureUPos(); + args.textureheight = drawerargs.TextureHeight(); + args.texturefrac = drawerargs.TextureVPos(); args.light = LightBgra::calc_light_multiplier(drawerargs.Light()); - args.color = LightBgra::shade_pal_index_simple(drawerargs.dc_color, args.light); - args.srccolor = drawerargs.dc_srccolor_bgra; - args.srcalpha = drawerargs.dc_srcalpha >> (FRACBITS - 8); - args.destalpha = drawerargs.dc_destalpha >> (FRACBITS - 8); + args.color = LightBgra::shade_pal_index_simple(drawerargs.SolidColor(), args.light); + args.srccolor = drawerargs.SrcColorBgra(); + args.srcalpha = drawerargs.SrcAlpha() >> (FRACBITS - 8); + args.destalpha = drawerargs.DestAlpha() >> (FRACBITS - 8); args.light_red = shade_constants.light_red; args.light_green = shade_constants.light_green; args.light_blue = shade_constants.light_blue; @@ -328,9 +328,9 @@ namespace swrenderer DrawFuzzColumnRGBACommand::DrawFuzzColumnRGBACommand(const SpriteDrawerArgs &drawerargs) { - _x = drawerargs.dc_x; - _yl = drawerargs.dc_yl; - _yh = drawerargs.dc_yh; + _x = drawerargs.FuzzX(); + _yl = drawerargs.FuzzY1(); + _yh = drawerargs.FuzzY2(); _destorg = RenderViewport::Instance()->GetDest(0, 0); _pitch = RenderViewport::Instance()->RenderTarget->GetPitch(); _fuzzpos = fuzzpos; diff --git a/src/swrenderer/drawers/r_drawerargs.h b/src/swrenderer/drawers/r_drawerargs.h index 56e7c6afed..481792edc7 100644 --- a/src/swrenderer/drawers/r_drawerargs.h +++ b/src/swrenderer/drawers/r_drawerargs.h @@ -192,11 +192,11 @@ namespace swrenderer 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; } - + uint32_t TextureHeight() const { return dc_textureheight; } + int TextureFracBits() const { return dc_wall_fracbits; } FVector3 dc_normal; @@ -234,35 +234,37 @@ namespace swrenderer bool SetPatchStyle(FRenderStyle style, fixed_t alpha, int translation, uint32_t color, FDynamicColormap *&basecolormap, fixed_t shadedlightshade = 0); bool SetPatchStyle(FRenderStyle style, float alpha, int translation, uint32_t color, FDynamicColormap *&basecolormap, fixed_t shadedlightshade = 0); + void SetDest(int x, int y); + void SetCount(int count) { dc_count = count; } + void SetSolidColor(int color) { dc_color = color; } 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); void FillColumn(); - void SetDest(int x, int y); - uint8_t *Dest() const { return dc_dest; } int DestY() const { return dc_dest_y; } + int Count() const { return dc_count; } - int dc_x; - int dc_yl; - int dc_yh; + int FuzzX() const { return dc_x; } + int FuzzY1() const { return dc_yl; } + int FuzzY2() const { return dc_yh; } - 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; + uint32_t TextureUPos() const { return dc_texturefracx; } + fixed_t TextureVPos() const { return dc_texturefrac; } + fixed_t TextureVStep() const { return dc_iscale; } - int dc_color = 0; - uint32_t dc_srccolor; - uint32_t dc_srccolor_bgra; + int SolidColor() const { return dc_color; } + uint32_t SrcColorIndex() const { return dc_srccolor; } + uint32_t SrcColorBgra() const { return dc_srccolor_bgra; } - uint32_t *dc_srcblend; - uint32_t *dc_destblend; - fixed_t dc_srcalpha; - fixed_t dc_destalpha; + const uint8_t *TexturePixels() const { return dc_source; } + const uint8_t *TexturePixels2() const { return dc_source2; } + uint32_t TextureHeight() const { return dc_textureheight; } + + 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; } private: bool SetBlendFunc(int op, fixed_t fglevel, fixed_t bglevel, int flags); @@ -271,8 +273,30 @@ namespace swrenderer uint8_t *dc_dest = nullptr; int dc_dest_y = 0; + int dc_count = 0; + + fixed_t dc_iscale; + fixed_t dc_texturefrac; + uint32_t dc_texturefracx; + + uint32_t dc_textureheight = 0; + const uint8_t *dc_source = nullptr; + const uint8_t *dc_source2 = nullptr; bool drawer_needs_pal_input = false; + uint32_t *dc_srcblend = nullptr; + uint32_t *dc_destblend = nullptr; + fixed_t dc_srcalpha = OPAQUE; + fixed_t dc_destalpha = 0; + + int dc_x = 0; + int dc_yl = 0; + int dc_yh = 0; + + int dc_color = 0; + uint32_t dc_srccolor = 0; + uint32_t dc_srccolor_bgra = 0; + typedef void(SWPixelFormatDrawers::*SpriteDrawerFunc)(const SpriteDrawerArgs &args); SpriteDrawerFunc colfunc; }; diff --git a/src/swrenderer/things/r_voxel.cpp b/src/swrenderer/things/r_voxel.cpp index b188368a33..21006b1466 100644 --- a/src/swrenderer/things/r_voxel.cpp +++ b/src/swrenderer/things/r_voxel.cpp @@ -342,8 +342,8 @@ namespace swrenderer if (columnY1 < columnY2) { drawerargs.SetDest(x, columnY1); - drawerargs.dc_color = color; - drawerargs.dc_count = columnY2 - columnY1; + drawerargs.SetSolidColor(color); + drawerargs.SetCount(columnY2 - columnY1); drawerargs.FillColumn(); } }