From d91e6ccece5749b80c5c415b07b020326b263a82 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Wed, 1 Feb 2017 22:24:34 +0100 Subject: [PATCH] Remove dc_destorg and ylookup --- src/swrenderer/drawers/r_draw.cpp | 1 - src/swrenderer/drawers/r_draw.h | 1 - src/swrenderer/drawers/r_draw_pal.cpp | 32 ++++++++++++------------- src/swrenderer/drawers/r_draw_pal.h | 8 +++---- src/swrenderer/drawers/r_draw_rgba.cpp | 26 ++++++++++---------- src/swrenderer/drawers/r_draw_rgba.h | 8 +++---- src/swrenderer/drawers/r_drawerargs.cpp | 9 +++---- src/swrenderer/scene/r_viewport.cpp | 21 ++++++++-------- src/swrenderer/scene/r_viewport.h | 2 +- src/swrenderer/things/r_particle.cpp | 4 ++-- src/v_draw.cpp | 17 ------------- 11 files changed, 53 insertions(+), 76 deletions(-) diff --git a/src/swrenderer/drawers/r_draw.cpp b/src/swrenderer/drawers/r_draw.cpp index 2625db1a0..2e0539204 100644 --- a/src/swrenderer/drawers/r_draw.cpp +++ b/src/swrenderer/drawers/r_draw.cpp @@ -57,7 +57,6 @@ CVAR(Bool, r_dynlights, 1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG); namespace swrenderer { - int ylookup[MAXHEIGHT]; uint8_t shadetables[NUMCOLORMAPS * 16 * 256]; FDynamicColormap ShadeFakeColormap[16]; uint8_t identitymap[256]; diff --git a/src/swrenderer/drawers/r_draw.h b/src/swrenderer/drawers/r_draw.h index d6ec7a149..e813acaae 100644 --- a/src/swrenderer/drawers/r_draw.h +++ b/src/swrenderer/drawers/r_draw.h @@ -25,7 +25,6 @@ namespace swrenderer class SpanDrawerArgs; class SpriteDrawerArgs; - extern int ylookup[MAXHEIGHT]; extern uint8_t shadetables[/*NUMCOLORMAPS*16*256*/]; extern FDynamicColormap ShadeFakeColormap[16]; extern uint8_t identitymap[256]; diff --git a/src/swrenderer/drawers/r_draw_pal.cpp b/src/swrenderer/drawers/r_draw_pal.cpp index f5b6e51ef..539baedfd 100644 --- a/src/swrenderer/drawers/r_draw_pal.cpp +++ b/src/swrenderer/drawers/r_draw_pal.cpp @@ -1767,7 +1767,7 @@ namespace swrenderer _yl = args.dc_yl; _yh = args.dc_yh; _x = args.dc_x; - _destorg = RenderViewport::Instance()->dc_destorg; + _destorg = RenderViewport::Instance()->GetDest(0, 0); _pitch = RenderViewport::Instance()->RenderTarget->GetPitch(); _fuzzpos = fuzzpos; _fuzzviewheight = fuzzviewheight; @@ -1786,7 +1786,7 @@ namespace swrenderer uint8_t *map = &NormalLight.Maps[6 * 256]; - uint8_t *dest = thread->dest_for_thread(yl, _pitch, ylookup[yl] + _x + _destorg); + uint8_t *dest = thread->dest_for_thread(yl, _pitch, yl * _pitch + _x + _destorg); int pitch = _pitch * thread->num_cores; int fuzzstep = thread->num_cores; @@ -1858,7 +1858,7 @@ namespace swrenderer _y = args.DestY(); _x1 = args.DestX1(); _x2 = args.DestX2(); - _destorg = RenderViewport::Instance()->dc_destorg; + _dest = RenderViewport::Instance()->GetDest(_x1, _y); _xstep = args.TextureUStep(); _ystep = args.TextureVStep(); _xbits = args.TextureWidthBits(); @@ -1942,7 +1942,7 @@ namespace swrenderer xfrac = _xfrac; yfrac = _yfrac; - dest = ylookup[_y] + _x1 + _destorg; + dest = _dest; count = _x2 - _x1 + 1; @@ -2030,7 +2030,7 @@ namespace swrenderer xfrac = _xfrac; yfrac = _yfrac; - dest = ylookup[_y] + _x1 + _destorg; + dest = _dest; count = _x2 - _x1 + 1; @@ -2104,7 +2104,7 @@ namespace swrenderer xfrac = _xfrac; yfrac = _yfrac; - dest = ylookup[_y] + _x1 + _destorg; + dest = _dest; count = _x2 - _x1 + 1; @@ -2227,7 +2227,7 @@ namespace swrenderer xfrac = _xfrac; yfrac = _yfrac; - dest = ylookup[_y] + _x1 + _destorg; + dest = _dest; count = _x2 - _x1 + 1; @@ -2368,7 +2368,7 @@ namespace swrenderer xfrac = _xfrac; yfrac = _yfrac; - dest = ylookup[_y] + _x1 + _destorg; + dest = _dest; count = _x2 - _x1 + 1; @@ -2491,7 +2491,7 @@ namespace swrenderer xfrac = _xfrac; yfrac = _yfrac; - dest = ylookup[_y] + _x1 + _destorg; + dest = _dest; count = _x2 - _x1 + 1; @@ -2619,7 +2619,7 @@ namespace swrenderer if (thread->line_skipped_by_thread(_y)) return; - memset(ylookup[_y] + _x1 + _destorg, _color, _x2 - _x1 + 1); + memset(_dest, _color, _x2 - _x1 + 1); } ///////////////////////////////////////////////////////////////////////// @@ -2628,7 +2628,7 @@ namespace swrenderer : y(y), x1(x1), x2(x2), plane_sz(plane_sz), plane_su(plane_su), plane_sv(plane_sv), plane_shade(plane_shade), planeshade(planeshade), planelightfloat(planelightfloat), pviewx(pviewx), pviewy(pviewy) { _colormap = args.Colormap(); - _destorg = RenderViewport::Instance()->dc_destorg; + _dest = RenderViewport::Instance()->GetDest(x1, y); _ybits = args.TextureHeightBits(); _xbits = args.TextureWidthBits(); _source = args.TexturePixels(); @@ -2668,7 +2668,7 @@ namespace swrenderer uz = plane_su[2] + plane_su[1] * (centery - y) + plane_su[0] * (x1 - centerx); vz = plane_sv[2] + plane_sv[1] * (centery - y) + plane_sv[0] * (x1 - centerx); - fb = ylookup[y] + x1 + _destorg; + fb = _dest; uint8_t vshift = 32 - _ybits; uint8_t ushift = vshift - _xbits; @@ -2873,7 +2873,7 @@ namespace swrenderer DrawColoredSpanPalCommand::DrawColoredSpanPalCommand(const SpanDrawerArgs &args, int y, int x1, int x2) : PalSpanCommand(args), y(y), x1(x1), x2(x2) { color = args.SolidColor(); - destorg = RenderViewport::Instance()->dc_destorg; + dest = RenderViewport::Instance()->GetDest(x1, y); } void DrawColoredSpanPalCommand::Execute(DrawerThread *thread) @@ -2881,7 +2881,7 @@ namespace swrenderer if (thread->line_skipped_by_thread(y)) return; - memset(ylookup[y] + x1 + destorg, color, x2 - x1 + 1); + memset(_dest, color, x2 - x1 + 1); } ///////////////////////////////////////////////////////////////////////// @@ -2889,7 +2889,7 @@ namespace swrenderer DrawFogBoundaryLinePalCommand::DrawFogBoundaryLinePalCommand(const SpanDrawerArgs &args, int y, int x1, int x2) : PalSpanCommand(args), y(y), x1(x1), x2(x2) { _colormap = args.Colormap(); - _destorg = RenderViewport::Instance()->dc_destorg; + _dest = RenderViewport::Instance()->GetDest(x1, y); } void DrawFogBoundaryLinePalCommand::Execute(DrawerThread *thread) @@ -2898,7 +2898,7 @@ namespace swrenderer return; const uint8_t *colormap = _colormap; - uint8_t *dest = ylookup[y] + _destorg; + uint8_t *dest = _dest; int x = x1; do { diff --git a/src/swrenderer/drawers/r_draw_pal.h b/src/swrenderer/drawers/r_draw_pal.h index ca99f1849..f28007e73 100644 --- a/src/swrenderer/drawers/r_draw_pal.h +++ b/src/swrenderer/drawers/r_draw_pal.h @@ -140,7 +140,7 @@ namespace swrenderer int _y; int _x1; int _x2; - uint8_t *_destorg; + uint8_t *_dest; dsfixed_t _xstep; dsfixed_t _ystep; int _xbits; @@ -187,7 +187,7 @@ namespace swrenderer fixed_t pviewy; const uint8_t *_colormap; - uint8_t *_destorg; + uint8_t *_dest; int _ybits; int _xbits; const uint8_t *_source; @@ -206,7 +206,7 @@ namespace swrenderer int x1; int x2; int color; - uint8_t *destorg; + uint8_t *dest; }; class DrawFogBoundaryLinePalCommand : public PalSpanCommand @@ -218,7 +218,7 @@ namespace swrenderer private: int y, x1, x2; const uint8_t *_colormap; - uint8_t *_destorg; + uint8_t *_dest; }; class DrawParticleColumnPalCommand : public DrawerCommand diff --git a/src/swrenderer/drawers/r_draw_rgba.cpp b/src/swrenderer/drawers/r_draw_rgba.cpp index 9d3a15ad8..4162f2f92 100644 --- a/src/swrenderer/drawers/r_draw_rgba.cpp +++ b/src/swrenderer/drawers/r_draw_rgba.cpp @@ -72,7 +72,7 @@ namespace swrenderer args.y = drawerargs.DestY(); args.xbits = drawerargs.TextureWidthBits(); args.ybits = drawerargs.TextureHeightBits(); - args.destorg = (uint32_t*)RenderViewport::Instance()->dc_destorg; + args.destorg = (uint32_t*)RenderViewport::Instance()->GetDest(0, 0); args.destpitch = RenderViewport::Instance()->RenderTarget->GetPitch(); args.source = (const uint32_t*)drawerargs.TexturePixels(); args.light = LightBgra::calc_light_multiplier(drawerargs.Light()); @@ -331,7 +331,7 @@ namespace swrenderer _x = drawerargs.dc_x; _yl = drawerargs.dc_yl; _yh = drawerargs.dc_yh; - _destorg = RenderViewport::Instance()->dc_destorg; + _destorg = RenderViewport::Instance()->GetDest(0, 0); _pitch = RenderViewport::Instance()->RenderTarget->GetPitch(); _fuzzpos = fuzzpos; _fuzzviewheight = fuzzviewheight; @@ -348,7 +348,7 @@ namespace swrenderer if (count <= 0) return; - uint32_t *dest = thread->dest_for_thread(yl, _pitch, ylookup[yl] + _x + (uint32_t*)_destorg); + uint32_t *dest = thread->dest_for_thread(yl, _pitch, _pitch * yl + _x + (uint32_t*)_destorg); int pitch = _pitch * thread->num_cores; int fuzzstep = thread->num_cores; @@ -439,7 +439,7 @@ namespace swrenderer _x1 = drawerargs.DestX1(); _x2 = drawerargs.DestX2(); _y = drawerargs.DestY(); - _destorg = RenderViewport::Instance()->dc_destorg; + _dest = RenderViewport::Instance()->GetDest(_x1, _y); _light = drawerargs.Light(); _color = drawerargs.SolidColor(); } @@ -449,7 +449,7 @@ namespace swrenderer if (thread->line_skipped_by_thread(_y)) return; - uint32_t *dest = ylookup[_y] + _x1 + (uint32_t*)_destorg; + uint32_t *dest = (uint32_t*)_dest; int count = (_x2 - _x1 + 1); uint32_t light = LightBgra::calc_light_multiplier(_light); uint32_t color = LightBgra::shade_pal_index_simple(_color, light); @@ -470,7 +470,7 @@ namespace swrenderer _x = x; _x2 = x2; - _destorg = RenderViewport::Instance()->dc_destorg; + _line = RenderViewport::Instance()->GetDest(0, y); _light = drawerargs.Light(); _shade_constants = drawerargs.ColormapConstants(); } @@ -484,7 +484,7 @@ namespace swrenderer int x = _x; int x2 = _x2; - uint32_t *dest = ylookup[y] + (uint32_t*)_destorg; + uint32_t *dest = (uint32_t*)_line; uint32_t light = LightBgra::calc_light_multiplier(_light); ShadeConstants constants = _shade_constants; @@ -537,7 +537,7 @@ namespace swrenderer _x1 = x1; _x2 = x2; _y = y; - _destorg = RenderViewport::Instance()->dc_destorg; + _dest = RenderViewport::Instance()->GetDest(_x1, _y); _light = drawerargs.Light(); _shade_constants = drawerargs.ColormapConstants(); _plane_sz = plane_sz; @@ -568,7 +568,7 @@ namespace swrenderer int source_width = 1 << _xbits; int source_height = 1 << _ybits; - uint32_t *dest = ylookup[_y] + _x1 + (uint32_t*)_destorg; + uint32_t *dest = (uint32_t*)_dest; int count = _x2 - _x1 + 1; // Depth (Z) change across the span @@ -672,7 +672,7 @@ namespace swrenderer _x1 = x1; _x2 = x2; - _destorg = RenderViewport::Instance()->dc_destorg; + _dest = RenderViewport::Instance()->GetDest(_x1, _y); _light = drawerargs.Light(); _color = drawerargs.SolidColor(); } @@ -686,7 +686,7 @@ namespace swrenderer int x1 = _x1; int x2 = _x2; - uint32_t *dest = ylookup[y] + x1 + (uint32_t*)_destorg; + uint32_t *dest = (uint32_t*)_dest; int count = (x2 - x1 + 1); uint32_t light = LightBgra::calc_light_multiplier(_light); uint32_t color = LightBgra::shade_pal_index_simple(_color, light); @@ -709,7 +709,7 @@ namespace swrenderer _color = color; _a = a; - _destorg = RenderViewport::Instance()->dc_destorg; + _destorg = RenderViewport::Instance()->GetDest(0, 0); _pitch = RenderViewport::Instance()->RenderTarget->GetPitch(); } @@ -738,7 +738,7 @@ namespace swrenderer fg_blue *= alpha; int spacing = _pitch * thread->num_cores; - uint32_t *dest = thread->dest_for_thread(y1, _pitch, ylookup[y1] + x + (uint32_t*)_destorg); + uint32_t *dest = thread->dest_for_thread(y1, _pitch, _pitch * y1 + x + (uint32_t*)_destorg); for (int y = 0; y < ycount; y++) { diff --git a/src/swrenderer/drawers/r_draw_rgba.h b/src/swrenderer/drawers/r_draw_rgba.h index 37ae0e25d..33c9ebcab 100644 --- a/src/swrenderer/drawers/r_draw_rgba.h +++ b/src/swrenderer/drawers/r_draw_rgba.h @@ -211,7 +211,7 @@ namespace swrenderer int _x1; int _x2; int _y; - uint8_t * RESTRICT _destorg; + uint8_t * RESTRICT _dest; fixed_t _light; int _color; @@ -226,7 +226,7 @@ namespace swrenderer int _y; int _x; int _x2; - uint8_t * RESTRICT _destorg; + uint8_t * RESTRICT _line; fixed_t _light; ShadeConstants _shade_constants; @@ -241,7 +241,7 @@ namespace swrenderer int _x1; int _x2; int _y; - uint8_t * RESTRICT _destorg; + uint8_t * RESTRICT _dest; fixed_t _light; ShadeConstants _shade_constants; FVector3 _plane_sz; @@ -267,7 +267,7 @@ namespace swrenderer int _y; int _x1; int _x2; - uint8_t * RESTRICT _destorg; + uint8_t * RESTRICT _dest; fixed_t _light; int _color; diff --git a/src/swrenderer/drawers/r_drawerargs.cpp b/src/swrenderer/drawers/r_drawerargs.cpp index e29c127c0..7bf3e0419 100644 --- a/src/swrenderer/drawers/r_drawerargs.cpp +++ b/src/swrenderer/drawers/r_drawerargs.cpp @@ -591,8 +591,7 @@ namespace swrenderer void WallDrawerArgs::SetDest(int x, int y) { auto viewport = RenderViewport::Instance(); - int pixelsize = viewport->RenderTarget->IsBgra() ? 4 : 1; - dc_dest = viewport->dc_destorg + (ylookup[y] + x) * pixelsize; + dc_dest = viewport->GetDest(x, y); dc_dest_y = y; } @@ -726,8 +725,7 @@ namespace swrenderer void SkyDrawerArgs::SetDest(int x, int y) { auto viewport = RenderViewport::Instance(); - int pixelsize = viewport->RenderTarget->IsBgra() ? 4 : 1; - dc_dest = viewport->dc_destorg + (ylookup[y] + x) * pixelsize; + dc_dest = viewport->GetDest(x, y); dc_dest_y = y; } @@ -772,8 +770,7 @@ namespace swrenderer void SpriteDrawerArgs::SetDest(int x, int y) { auto viewport = RenderViewport::Instance(); - int pixelsize = viewport->RenderTarget->IsBgra() ? 4 : 1; - dc_dest = viewport->dc_destorg + (ylookup[y] + x) * pixelsize; + dc_dest = viewport->GetDest(x, y); dc_dest_y = y; } } diff --git a/src/swrenderer/scene/r_viewport.cpp b/src/swrenderer/scene/r_viewport.cpp index 89f758ad9..1fc4494a8 100644 --- a/src/swrenderer/scene/r_viewport.cpp +++ b/src/swrenderer/scene/r_viewport.cpp @@ -126,19 +126,18 @@ namespace swrenderer void RenderViewport::SetupBuffer() { + R_InitFuzzTable(RenderTarget->GetPitch()); + R_InitParticleTexture(); + } + + uint8_t *RenderViewport::GetDest(int x, int y) + { + x += viewwindowx; + y += viewwindowy; + int pitch = RenderTarget->GetPitch(); int pixelsize = RenderTarget->IsBgra() ? 4 : 1; - BYTE *lineptr = RenderTarget->GetBuffer() + (viewwindowy*pitch + viewwindowx) * pixelsize; - - R_InitFuzzTable(pitch); - - dc_destorg = lineptr; - for (int i = 0; i < RenderTarget->GetHeight(); i++) - { - ylookup[i] = i * pitch; - } - - R_InitParticleTexture(); + return RenderTarget->GetBuffer() + (x + y * pitch) * pixelsize; } void RenderViewport::InitTextureMapping() diff --git a/src/swrenderer/scene/r_viewport.h b/src/swrenderer/scene/r_viewport.h index e2daba8bb..ea5436980 100644 --- a/src/swrenderer/scene/r_viewport.h +++ b/src/swrenderer/scene/r_viewport.h @@ -44,7 +44,7 @@ namespace swrenderer // from clipangle to -clipangle. angle_t xtoviewangle[MAXWIDTH + 1]; - uint8_t *dc_destorg = nullptr; + uint8_t *GetDest(int x, int y); bool RenderingToCanvas() const { return RenderTarget != screen; } diff --git a/src/swrenderer/things/r_particle.cpp b/src/swrenderer/things/r_particle.cpp index 6d47fc164..8ee6df916 100644 --- a/src/swrenderer/things/r_particle.cpp +++ b/src/swrenderer/things/r_particle.cpp @@ -245,7 +245,7 @@ namespace swrenderer { if (translucentPass->ClipSpriteColumnWithPortals(x, vis)) continue; - uint32_t *dest = ylookup[yl] + x + (uint32_t*)viewport->dc_destorg; + uint32_t *dest = (uint32_t*)viewport->GetDest(x, yl); DrawerCommandQueue::QueueCommand(dest, yl, spacing, ycount, fg, alpha, fracposx); } } @@ -255,7 +255,7 @@ namespace swrenderer { if (translucentPass->ClipSpriteColumnWithPortals(x, vis)) continue; - uint8_t *dest = ylookup[yl] + x + viewport->dc_destorg; + uint8_t *dest = viewport->GetDest(x, yl); DrawerCommandQueue::QueueCommand(dest, yl, spacing, ycount, fg, alpha, fracposx); } } diff --git a/src/v_draw.cpp b/src/v_draw.cpp index 1e284c738..7e5469fb3 100644 --- a/src/v_draw.cpp +++ b/src/v_draw.cpp @@ -203,13 +203,6 @@ void DCanvas::DrawTextureParms(FTexture *img, DrawParms &parms) else visible = drawerargs.SetPatchStyle(parms.style, parms.Alpha, 0, parms.fillcolor, basecolormap); - BYTE *destorgsave = viewport->dc_destorg; - viewport->dc_destorg = screen->GetBuffer(); - if (viewport->dc_destorg == NULL) - { - I_FatalError("Attempt to write to buffer of hardware canvas"); - } - double x0 = parms.x - parms.left * parms.destwidth / parms.texwidth; double y0 = parms.y - parms.top * parms.destheight / parms.texheight; @@ -295,8 +288,6 @@ void DCanvas::DrawTextureParms(FTexture *img, DrawParms &parms) viewport->CenterY = centeryback; } - viewport->dc_destorg = destorgsave; - if (ticdup != 0 && menuactive == MENU_Off) { NetUpdate(); @@ -1369,13 +1360,6 @@ void DCanvas::FillSimplePoly(FTexture *tex, FVector2 *points, int npoints, auto viewport = RenderViewport::Instance(); - BYTE *destorgsave = viewport->dc_destorg; - viewport->dc_destorg = screen->GetBuffer(); - if (viewport->dc_destorg == NULL) - { - I_FatalError("Attempt to write to buffer of hardware canvas"); - } - scalex /= tex->Scale.X; scaley /= tex->Scale.Y; @@ -1498,7 +1482,6 @@ void DCanvas::FillSimplePoly(FTexture *tex, FVector2 *points, int npoints, pt1 = pt2; pt2--; if (pt2 < 0) pt2 = npoints; } while (pt1 != botpt); - viewport->dc_destorg = destorgsave; #endif }