diff --git a/src/swrenderer/viewport/r_drawerargs.cpp b/src/swrenderer/viewport/r_drawerargs.cpp index d54afad6bf..65477cd55f 100644 --- a/src/swrenderer/viewport/r_drawerargs.cpp +++ b/src/swrenderer/viewport/r_drawerargs.cpp @@ -13,25 +13,9 @@ #include #include "r_drawerargs.h" -#include "swrenderer/drawers/r_draw_pal.h" -#include "swrenderer/drawers/r_draw_rgba.h" namespace swrenderer { - SWPixelFormatDrawers *DrawerArgs::Drawers() - { - if (RenderViewport::Instance()->RenderTarget->IsBgra()) - { - static SWTruecolorDrawers tc_drawers; - return &tc_drawers; - } - else - { - static SWPalDrawers pal_drawers; - return &pal_drawers; - } - } - void DrawerArgs::SetLight(FSWColormap *base_colormap, float light, int shade) { mBaseColormap = base_colormap; diff --git a/src/swrenderer/viewport/r_drawerargs.h b/src/swrenderer/viewport/r_drawerargs.h index d36bc61a5b..3172a54401 100644 --- a/src/swrenderer/viewport/r_drawerargs.h +++ b/src/swrenderer/viewport/r_drawerargs.h @@ -33,9 +33,6 @@ namespace swrenderer ShadeConstants ColormapConstants() const; fixed_t Light() const { return LIGHTSCALE(mLight, mShade); } - protected: - static SWPixelFormatDrawers *Drawers(); - private: FSWColormap *mBaseColormap = nullptr; float mLight = 0.0f; diff --git a/src/swrenderer/viewport/r_skydrawer.cpp b/src/swrenderer/viewport/r_skydrawer.cpp index 922324f641..70a64e651e 100644 --- a/src/swrenderer/viewport/r_skydrawer.cpp +++ b/src/swrenderer/viewport/r_skydrawer.cpp @@ -18,12 +18,12 @@ namespace swrenderer { void SkyDrawerArgs::DrawSingleSkyColumn() { - Drawers()->DrawSingleSkyColumn(*this); + RenderViewport::Instance()->Drawers()->DrawSingleSkyColumn(*this); } void SkyDrawerArgs::DrawDoubleSkyColumn() { - Drawers()->DrawDoubleSkyColumn(*this); + RenderViewport::Instance()->Drawers()->DrawDoubleSkyColumn(*this); } void SkyDrawerArgs::SetDest(int x, int y) diff --git a/src/swrenderer/viewport/r_spandrawer.cpp b/src/swrenderer/viewport/r_spandrawer.cpp index 7d14886271..3c0acaab09 100644 --- a/src/swrenderer/viewport/r_spandrawer.cpp +++ b/src/swrenderer/viewport/r_spandrawer.cpp @@ -98,21 +98,21 @@ namespace swrenderer void SpanDrawerArgs::DrawSpan() { - (Drawers()->*spanfunc)(*this); + (RenderViewport::Instance()->Drawers()->*spanfunc)(*this); } void SpanDrawerArgs::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) { - Drawers()->DrawTiltedSpan(*this, y, x1, x2, plane_sz, plane_su, plane_sv, plane_shade, planeshade, planelightfloat, pviewx, pviewy, basecolormap); + RenderViewport::Instance()->Drawers()->DrawTiltedSpan(*this, y, x1, x2, plane_sz, plane_su, plane_sv, plane_shade, planeshade, planelightfloat, pviewx, pviewy, basecolormap); } void SpanDrawerArgs::DrawFogBoundaryLine(int y, int x1, int x2) { - Drawers()->DrawFogBoundaryLine(*this, y, x1, x2); + RenderViewport::Instance()->Drawers()->DrawFogBoundaryLine(*this, y, x1, x2); } void SpanDrawerArgs::DrawColoredSpan(int y, int x1, int x2) { - Drawers()->DrawColoredSpan(*this, y, x1, x2); + RenderViewport::Instance()->Drawers()->DrawColoredSpan(*this, y, x1, x2); } } diff --git a/src/swrenderer/viewport/r_spritedrawer.cpp b/src/swrenderer/viewport/r_spritedrawer.cpp index 06532ff131..fee87e67e5 100644 --- a/src/swrenderer/viewport/r_spritedrawer.cpp +++ b/src/swrenderer/viewport/r_spritedrawer.cpp @@ -115,7 +115,7 @@ namespace swrenderer else if (dc_iscale < 0) dc_count = MIN(dc_count, (dc_texturefrac - dc_iscale) / (-dc_iscale)); - (Drawers()->*colfunc)(*this); + (RenderViewport::Instance()->Drawers()->*colfunc)(*this); } span++; } @@ -230,7 +230,7 @@ namespace swrenderer double v = ((dc_yl + 0.5 - sprtopscreen) / spryscale) / tex->GetHeight(); dc_texturefrac = (uint32_t)(v * (1 << 30)); - (Drawers()->*colfunc)(*this); + (RenderViewport::Instance()->Drawers()->*colfunc)(*this); } span++; } @@ -490,7 +490,7 @@ namespace swrenderer void SpriteDrawerArgs::FillColumn() { - Drawers()->FillColumn(*this); + RenderViewport::Instance()->Drawers()->FillColumn(*this); } void SpriteDrawerArgs::SetDest(int x, int y) diff --git a/src/swrenderer/viewport/r_viewport.cpp b/src/swrenderer/viewport/r_viewport.cpp index 62edf110e1..5cafc6f99f 100644 --- a/src/swrenderer/viewport/r_viewport.cpp +++ b/src/swrenderer/viewport/r_viewport.cpp @@ -33,6 +33,8 @@ #include "swrenderer/drawers/r_draw.h" #include "swrenderer/things/r_playersprite.h" #include "swrenderer/plane/r_flatplane.h" +#include "swrenderer/drawers/r_draw_pal.h" +#include "swrenderer/drawers/r_draw_rgba.h" CVAR(String, r_viewsize, "", CVAR_NOSET) @@ -44,6 +46,24 @@ namespace swrenderer return &instance; } + RenderViewport::RenderViewport() + { + tc_drawers = std::make_unique(); + pal_drawers = std::make_unique(); + } + + RenderViewport::~RenderViewport() + { + } + + SWPixelFormatDrawers *RenderViewport::Drawers() + { + if (RenderTarget->IsBgra()) + return tc_drawers.get(); + else + return pal_drawers.get(); + } + void RenderViewport::SetViewport(int fullWidth, int fullHeight, float trueratio) { int virtheight, virtwidth, virtwidth2, virtheight2; diff --git a/src/swrenderer/viewport/r_viewport.h b/src/swrenderer/viewport/r_viewport.h index d89dbec6ec..a61709d611 100644 --- a/src/swrenderer/viewport/r_viewport.h +++ b/src/swrenderer/viewport/r_viewport.h @@ -14,15 +14,23 @@ #pragma once #include +#include #include "r_defs.h" namespace swrenderer { + class SWPixelFormatDrawers; + class SWTruecolorDrawers; + class SWPalDrawers; + class RenderViewport { public: static RenderViewport *Instance(); + RenderViewport(); + ~RenderViewport(); + void SetViewport(int width, int height, float trueratio); void SetupFreelook(); @@ -54,11 +62,16 @@ namespace swrenderer DVector2 PointWorldToView(const DVector2 &worldPos) const; DVector2 ScaleViewToScreen(const DVector2 &scale, double viewZ, bool pixelstretch = true) const; + + SWPixelFormatDrawers *Drawers(); private: void InitTextureMapping(); void SetupBuffer(); double BaseYaspectMul = 0.0; // yaspectmul without a forced aspect ratio + + std::unique_ptr tc_drawers; + std::unique_ptr pal_drawers; }; } diff --git a/src/swrenderer/viewport/r_walldrawer.cpp b/src/swrenderer/viewport/r_walldrawer.cpp index c30f86ffb6..8672c4cf5d 100644 --- a/src/swrenderer/viewport/r_walldrawer.cpp +++ b/src/swrenderer/viewport/r_walldrawer.cpp @@ -25,7 +25,7 @@ namespace swrenderer void WallDrawerArgs::DrawColumn() { - (Drawers()->*wallfunc)(*this); + (RenderViewport::Instance()->Drawers()->*wallfunc)(*this); } void WallDrawerArgs::SetStyle(bool masked, bool additive, fixed_t alpha)