diff --git a/src/d_main.cpp b/src/d_main.cpp index 2241c35c5e..dc2248d193 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -694,8 +694,6 @@ void D_Display () } } - RenderTarget = screen; - // change the view size if needed if (setsizeneeded && StatusBar != NULL) { diff --git a/src/polyrenderer/poly_renderer.cpp b/src/polyrenderer/poly_renderer.cpp index ceabfceffc..6e2e54be3d 100644 --- a/src/polyrenderer/poly_renderer.cpp +++ b/src/polyrenderer/poly_renderer.cpp @@ -53,6 +53,8 @@ void PolyRenderer::RenderView(player_t *player) { using namespace swrenderer; + swrenderer::RenderTarget = screen; + bool saved_swtruecolor = r_swtruecolor; r_swtruecolor = screen->IsBgra(); @@ -82,7 +84,7 @@ void PolyRenderer::RenderViewToCanvas(AActor *actor, DCanvas *canvas, int x, int const bool savedoutputformat = swrenderer::r_swtruecolor; viewwidth = width; - RenderTarget = canvas; + swrenderer::RenderTarget = canvas; swrenderer::bRenderingToCanvas = true; R_SetWindow(12, width, height, height, true); swrenderer::R_SWRSetWindow(12, width, height, height, WidescreenRatio); @@ -97,7 +99,7 @@ void PolyRenderer::RenderViewToCanvas(AActor *actor, DCanvas *canvas, int x, int canvas->Unlock(); - RenderTarget = screen; + swrenderer::RenderTarget = screen; swrenderer::bRenderingToCanvas = false; R_ExecuteSetViewSize(); float trueratio; @@ -153,8 +155,8 @@ void PolyRenderer::RenderRemainingPlayerSprites() void PolyRenderer::ClearBuffers() { PolyVertexBuffer::Clear(); - PolyStencilBuffer::Instance()->Clear(RenderTarget->GetWidth(), RenderTarget->GetHeight(), 0); - PolySubsectorGBuffer::Instance()->Resize(RenderTarget->GetPitch(), RenderTarget->GetHeight()); + PolyStencilBuffer::Instance()->Clear(swrenderer::RenderTarget->GetWidth(), swrenderer::RenderTarget->GetHeight(), 0); + PolySubsectorGBuffer::Instance()->Resize(swrenderer::RenderTarget->GetPitch(), swrenderer::RenderTarget->GetHeight()); NextStencilValue = 0; SeenLinePortals.clear(); SeenMirrors.clear(); @@ -162,6 +164,8 @@ void PolyRenderer::ClearBuffers() void PolyRenderer::SetSceneViewport() { + using namespace swrenderer; + if (RenderTarget == screen) // Rendering to screen { int height; diff --git a/src/polyrenderer/scene/poly_playersprite.cpp b/src/polyrenderer/scene/poly_playersprite.cpp index a3b29fa300..e9665c8576 100644 --- a/src/polyrenderer/scene/poly_playersprite.cpp +++ b/src/polyrenderer/scene/poly_playersprite.cpp @@ -165,12 +165,12 @@ void RenderPolyPlayerSprites::RenderSprite(DPSprite *sprite, AActor *owner, floa double texturemid = (BaseYCenter - sy) * tex->Scale.Y + tex->TopOffset; // Adjust PSprite for fullscreen views - if (camera->player && (RenderTarget != screen || viewheight == RenderTarget->GetHeight() || (RenderTarget->GetWidth() > (BaseXCenter * 2) && !st_scale))) + if (camera->player && (swrenderer::RenderTarget != screen || viewheight == swrenderer::RenderTarget->GetHeight() || (swrenderer::RenderTarget->GetWidth() > (BaseXCenter * 2) && !st_scale))) { AWeapon *weapon = dyn_cast(sprite->GetCaller()); if (weapon != nullptr && weapon->YAdjust != 0) { - if (RenderTarget != screen || viewheight == RenderTarget->GetHeight()) + if (swrenderer::RenderTarget != screen || viewheight == swrenderer::RenderTarget->GetHeight()) { texturemid -= weapon->YAdjust; } @@ -338,7 +338,7 @@ void RenderPolyPlayerSprites::RenderSprite(DPSprite *sprite, AActor *owner, floa // Check for hardware-assisted 2D. If it's available, and this sprite is not // fuzzy, don't draw it until after the switch to 2D mode. - if (!noaccel && RenderTarget == screen && (DFrameBuffer *)screen->Accel2D) + if (!noaccel && swrenderer::RenderTarget == screen && (DFrameBuffer *)screen->Accel2D) { FRenderStyle style = visstyle.RenderStyle; style.CheckFuzz(); diff --git a/src/r_utility.cpp b/src/r_utility.cpp index 29119754b5..34ad10a6e5 100644 --- a/src/r_utility.cpp +++ b/src/r_utility.cpp @@ -100,8 +100,6 @@ CUSTOM_CVAR(Float, r_quakeintensity, 1.0f, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) else if (self > 1.f) self = 1.f; } -DCanvas *RenderTarget; // [RH] canvas to render to - int viewwindowx; int viewwindowy; @@ -908,7 +906,7 @@ void R_SetupFrame (AActor *actor) validcount++; - if (RenderTarget == screen && r_clearbuffer != 0) + if (r_clearbuffer != 0) { int color; int hom = r_clearbuffer; diff --git a/src/r_utility.h b/src/r_utility.h index 488d456720..ac31a6f5b5 100644 --- a/src/r_utility.h +++ b/src/r_utility.h @@ -12,8 +12,6 @@ class FSerializer; // There a 0-31, i.e. 32 LUT in the COLORMAP lump. #define NUMCOLORMAPS 32 -extern DCanvas *RenderTarget; - extern DVector3 ViewPos; extern DVector3 ViewActorPos; extern DAngle ViewAngle; diff --git a/src/swrenderer/r_swrenderer.cpp b/src/swrenderer/r_swrenderer.cpp index 85131c9757..e64b7f0b75 100644 --- a/src/swrenderer/r_swrenderer.cpp +++ b/src/swrenderer/r_swrenderer.cpp @@ -244,18 +244,7 @@ void FSoftwareRenderer::OnModeSet () void FSoftwareRenderer::ClearBuffer(int color) { - if (!r_swtruecolor) - { - memset(RenderTarget->GetBuffer(), color, RenderTarget->GetPitch() * RenderTarget->GetHeight()); - } - else - { - uint32_t bgracolor = GPalette.BaseColors[color].d; - int size = RenderTarget->GetPitch() * RenderTarget->GetHeight(); - uint32_t *dest = (uint32_t *)RenderTarget->GetBuffer(); - for (int i = 0; i < size; i++) - dest[i] = bgracolor; - } + RenderScene::Instance()->SetClearColor(color); } void FSoftwareRenderer::RenderTextureView (FCanvasTexture *tex, AActor *viewpoint, int fov) diff --git a/src/swrenderer/scene/r_scene.cpp b/src/swrenderer/scene/r_scene.cpp index 77b0edf142..2dee1eb274 100644 --- a/src/swrenderer/scene/r_scene.cpp +++ b/src/swrenderer/scene/r_scene.cpp @@ -49,6 +49,7 @@ #include "swrenderer/r_memory.h" EXTERN_CVAR(Bool, r_shadercolormaps) +EXTERN_CVAR(Int, r_clearbuffer) namespace swrenderer { @@ -60,8 +61,15 @@ namespace swrenderer return &instance; } + void RenderScene::SetClearColor(int color) + { + clearcolor = color; + } + void RenderScene::RenderView(player_t *player) { + RenderTarget = screen; + int width = SCREENWIDTH; int height = SCREENHEIGHT; int stHeight = ST_Y; @@ -75,6 +83,22 @@ namespace swrenderer R_InitColumnDrawers(); } + if (r_clearbuffer != 0) + { + if (!r_swtruecolor) + { + memset(RenderTarget->GetBuffer(), clearcolor, RenderTarget->GetPitch() * RenderTarget->GetHeight()); + } + else + { + uint32_t bgracolor = GPalette.BaseColors[clearcolor].d; + int size = RenderTarget->GetPitch() * RenderTarget->GetHeight(); + uint32_t *dest = (uint32_t *)RenderTarget->GetBuffer(); + for (int i = 0; i < size; i++) + dest[i] = bgracolor; + } + } + R_BeginDrawerCommands(); RenderActorView(player->mo); diff --git a/src/swrenderer/scene/r_scene.h b/src/swrenderer/scene/r_scene.h index 8432838134..31e074c08c 100644 --- a/src/swrenderer/scene/r_scene.h +++ b/src/swrenderer/scene/r_scene.h @@ -31,6 +31,8 @@ namespace swrenderer void Init(); void ScreenResized(); void Deinit(); + + void SetClearColor(int color); void RenderActorView(AActor *actor, bool dontmaplines = false); void RenderView(player_t *player); @@ -40,5 +42,6 @@ namespace swrenderer private: bool dontmaplines = false; + int clearcolor = 0; }; } diff --git a/src/swrenderer/scene/r_viewport.cpp b/src/swrenderer/scene/r_viewport.cpp index 8d79237d25..b45a7ccd61 100644 --- a/src/swrenderer/scene/r_viewport.cpp +++ b/src/swrenderer/scene/r_viewport.cpp @@ -44,6 +44,7 @@ namespace swrenderer double FocalLengthX; double FocalLengthY; + DCanvas *RenderTarget; bool bRenderingToCanvas; double globaluclip, globaldclip; double CenterX, CenterY; diff --git a/src/swrenderer/scene/r_viewport.h b/src/swrenderer/scene/r_viewport.h index 6638a85922..3cf3ad0ef5 100644 --- a/src/swrenderer/scene/r_viewport.h +++ b/src/swrenderer/scene/r_viewport.h @@ -18,6 +18,7 @@ namespace swrenderer { + extern DCanvas *RenderTarget; extern bool bRenderingToCanvas; extern fixed_t viewingrangerecip; extern double FocalLengthX;