diff --git a/src/polyrenderer/poly_renderer.cpp b/src/polyrenderer/poly_renderer.cpp index 5c00ef4fb..77b59ac4b 100644 --- a/src/polyrenderer/poly_renderer.cpp +++ b/src/polyrenderer/poly_renderer.cpp @@ -50,7 +50,7 @@ PolyRenderer *PolyRenderer::Instance() return &scene; } -PolyRenderer::PolyRenderer() +PolyRenderer::PolyRenderer() : Thread(nullptr) { } diff --git a/src/swrenderer/drawers/r_thread.cpp b/src/swrenderer/drawers/r_thread.cpp index 367783b56..adcee2768 100644 --- a/src/swrenderer/drawers/r_thread.cpp +++ b/src/swrenderer/drawers/r_thread.cpp @@ -282,5 +282,5 @@ DrawerCommandQueue::DrawerCommandQueue(swrenderer::RenderThread *renderthread) : void *DrawerCommandQueue::AllocMemory(size_t size) { - return renderthread->FrameMemory->AllocMemory(size); + return renderthread->FrameMemory->AllocMemory((int)size); } diff --git a/src/swrenderer/r_renderthread.cpp b/src/swrenderer/r_renderthread.cpp index dd14c8902..53b5f62f8 100644 --- a/src/swrenderer/r_renderthread.cpp +++ b/src/swrenderer/r_renderthread.cpp @@ -56,8 +56,9 @@ namespace swrenderer { - RenderThread::RenderThread() + RenderThread::RenderThread(RenderScene *scene) { + Scene = scene; FrameMemory = std::make_unique(); DrawQueue = std::make_shared(this); OpaquePass = std::make_unique(this); @@ -67,7 +68,6 @@ namespace swrenderer Clip3DFloors = std::make_unique(this); PlayerSprites = std::make_unique(this); PlaneList = std::make_unique(this); - Scene = std::make_unique(this); DrawSegments = std::make_unique(this); ClipSegments = std::make_unique(); tc_drawers = std::make_unique(DrawQueue); diff --git a/src/swrenderer/r_renderthread.h b/src/swrenderer/r_renderthread.h index 809fe080d..1d3792fc1 100644 --- a/src/swrenderer/r_renderthread.h +++ b/src/swrenderer/r_renderthread.h @@ -47,9 +47,11 @@ namespace swrenderer class RenderThread { public: - RenderThread(); + RenderThread(RenderScene *scene); ~RenderThread(); + RenderScene *Scene; + std::unique_ptr FrameMemory; std::unique_ptr OpaquePass; std::unique_ptr TranslucentPass; @@ -58,7 +60,6 @@ namespace swrenderer std::unique_ptr Clip3DFloors; std::unique_ptr PlayerSprites; std::unique_ptr PlaneList; - std::unique_ptr Scene; std::unique_ptr DrawSegments; std::unique_ptr ClipSegments; DrawerCommandQueuePtr DrawQueue; diff --git a/src/swrenderer/r_swrenderer.cpp b/src/swrenderer/r_swrenderer.cpp index a12a5ae00..561f0de43 100644 --- a/src/swrenderer/r_swrenderer.cpp +++ b/src/swrenderer/r_swrenderer.cpp @@ -88,7 +88,7 @@ void FSoftwareRenderer::Init() { gl_ParseDefs(); - mMainThread.Scene->Init(); + mScene.Init(); } bool FSoftwareRenderer::UsesColormap() const @@ -178,7 +178,7 @@ void FSoftwareRenderer::RenderView(player_t *player) if (r_polyrenderer) PolyRenderer::Instance()->RenderView(player); else - mMainThread.Scene->RenderView(player); + mScene.RenderView(player); FCanvasTextureInfo::UpdateAll(); } @@ -202,7 +202,7 @@ void FSoftwareRenderer::WriteSavePic (player_t *player, FileWriter *file, int wi if (r_polyrenderer) PolyRenderer::Instance()->RenderViewToCanvas(player->mo, pic, 0, 0, width, height, true); else - mMainThread.Scene->RenderViewToCanvas (player->mo, pic, 0, 0, width, height); + mScene.RenderViewToCanvas (player->mo, pic, 0, 0, width, height); screen->GetFlashedPalette (palette); M_CreatePNG (file, pic->GetBuffer(), palette, SS_PAL, width, height, pic->GetPitch()); pic->Unlock (); @@ -215,7 +215,7 @@ void FSoftwareRenderer::DrawRemainingPlayerSprites() { if (!r_polyrenderer) { - mMainThread.PlayerSprites->RenderRemaining(); + mScene.MainThread()->PlayerSprites->RenderRemaining(); } else { @@ -237,12 +237,12 @@ bool FSoftwareRenderer::RequireGLNodes() void FSoftwareRenderer::OnModeSet () { - mMainThread.Scene->ScreenResized(); + mScene.ScreenResized(); } void FSoftwareRenderer::SetClearColor(int color) { - mMainThread.Scene->SetClearColor(color); + mScene.SetClearColor(color); } void FSoftwareRenderer::RenderTextureView (FCanvasTexture *tex, AActor *viewpoint, int fov) @@ -262,7 +262,7 @@ void FSoftwareRenderer::RenderTextureView (FCanvasTexture *tex, AActor *viewpoin if (r_polyrenderer) PolyRenderer::Instance()->RenderViewToCanvas(viewpoint, Canvas, 0, 0, tex->GetWidth(), tex->GetHeight(), tex->bFirstUpdate); else - mMainThread.Scene->RenderViewToCanvas(viewpoint, Canvas, 0, 0, tex->GetWidth(), tex->GetHeight(), tex->bFirstUpdate); + mScene.RenderViewToCanvas(viewpoint, Canvas, 0, 0, tex->GetWidth(), tex->GetHeight(), tex->bFirstUpdate); R_SetFOV (savedfov); @@ -319,7 +319,7 @@ void FSoftwareRenderer::RenderTextureView (FCanvasTexture *tex, AActor *viewpoin sector_t *FSoftwareRenderer::FakeFlat(sector_t *sec, sector_t *tempsec, int *floorlightlevel, int *ceilinglightlevel) { - return mMainThread.OpaquePass->FakeFlat(sec, tempsec, floorlightlevel, ceilinglightlevel, nullptr, 0, 0, 0, 0); + return mScene.MainThread()->OpaquePass->FakeFlat(sec, tempsec, floorlightlevel, ceilinglightlevel, nullptr, 0, 0, 0, 0); } void FSoftwareRenderer::StateChanged(AActor *actor) diff --git a/src/swrenderer/r_swrenderer.h b/src/swrenderer/r_swrenderer.h index 9cdc0c9be..6d9373879 100644 --- a/src/swrenderer/r_swrenderer.h +++ b/src/swrenderer/r_swrenderer.h @@ -2,7 +2,7 @@ #pragma once #include "r_renderer.h" -#include "r_renderthread.h" +#include "swrenderer/scene/r_scene.h" struct FSoftwareRenderer : public FRenderer { @@ -43,5 +43,5 @@ struct FSoftwareRenderer : public FRenderer private: void PrecacheTexture(FTexture *tex, int cache); - swrenderer::RenderThread mMainThread; + swrenderer::RenderScene mScene; }; diff --git a/src/swrenderer/scene/r_scene.cpp b/src/swrenderer/scene/r_scene.cpp index 371936a69..d784efb4a 100644 --- a/src/swrenderer/scene/r_scene.cpp +++ b/src/swrenderer/scene/r_scene.cpp @@ -56,9 +56,9 @@ namespace swrenderer { cycle_t WallCycles, PlaneCycles, MaskedCycles, WallScanCycles; - RenderScene::RenderScene(RenderThread *thread) + RenderScene::RenderScene() { - Thread = thread; + Threads.push_back(std::make_unique(this)); } void RenderScene::SetClearColor(int color) @@ -98,10 +98,10 @@ namespace swrenderer // Apply special colormap if the target cannot do it if (CameraLight::Instance()->ShaderColormap() && viewport->RenderTarget->IsBgra() && !(r_shadercolormaps && screen->Accel2D)) { - Thread->DrawQueue->Push(CameraLight::Instance()->ShaderColormap(), screen); + MainThread()->DrawQueue->Push(CameraLight::Instance()->ShaderColormap(), screen); } - DrawerThreads::Execute({ Thread->DrawQueue }); + DrawerThreads::Execute({ MainThread()->DrawQueue }); } void RenderScene::RenderActorView(AActor *actor, bool dontmaplines) @@ -111,9 +111,9 @@ namespace swrenderer MaskedCycles.Reset(); WallScanCycles.Reset(); - Thread->FrameMemory->Clear(); + MainThread()->FrameMemory->Clear(); - Clip3DFloors *clip3d = Thread->Clip3DFloors.get(); + Clip3DFloors *clip3d = MainThread()->Clip3DFloors.get(); clip3d->Cleanup(); clip3d->ResetClip(); // reset clips (floor/ceiling) @@ -121,25 +121,25 @@ namespace swrenderer CameraLight::Instance()->SetCamera(actor); RenderViewport::Instance()->SetupFreelook(); - Thread->Portal->CopyStackedViewParameters(); + MainThread()->Portal->CopyStackedViewParameters(); // Clear buffers. - Thread->ClipSegments->Clear(0, viewwidth); - Thread->DrawSegments->Clear(); - Thread->PlaneList->Clear(); - Thread->TranslucentPass->Clear(); + MainThread()->ClipSegments->Clear(0, viewwidth); + MainThread()->DrawSegments->Clear(); + MainThread()->PlaneList->Clear(); + MainThread()->TranslucentPass->Clear(); // opening / clipping determination - Thread->OpaquePass->ClearClip(); + MainThread()->OpaquePass->ClearClip(); NetUpdate(); - Thread->Portal->SetMainPortal(); + MainThread()->Portal->SetMainPortal(); this->dontmaplines = dontmaplines; // [RH] Hack to make windows into underwater areas possible - Thread->OpaquePass->ResetFakingUnderwater(); + MainThread()->OpaquePass->ResetFakingUnderwater(); // [RH] Setup particles for this frame P_FindParticleSubsectors(); @@ -153,8 +153,8 @@ namespace swrenderer } // Link the polyobjects right before drawing the scene to reduce the amounts of calls to this function PO_LinkToSubsectors(); - Thread->OpaquePass->RenderScene(); - Thread->Clip3DFloors->ResetClip(); // reset clips (floor/ceiling) + MainThread()->OpaquePass->RenderScene(); + MainThread()->Clip3DFloors->ResetClip(); // reset clips (floor/ceiling) camera->renderflags = savedflags; WallCycles.Unclock(); @@ -163,16 +163,16 @@ namespace swrenderer if (viewactive) { PlaneCycles.Clock(); - Thread->PlaneList->Render(); - Thread->Portal->RenderPlanePortals(); + MainThread()->PlaneList->Render(); + MainThread()->Portal->RenderPlanePortals(); PlaneCycles.Unclock(); - Thread->Portal->RenderLinePortals(); + MainThread()->Portal->RenderLinePortals(); NetUpdate(); MaskedCycles.Clock(); - Thread->TranslucentPass->Render(); + MainThread()->TranslucentPass->Render(); MaskedCycles.Unclock(); NetUpdate(); @@ -204,7 +204,7 @@ namespace swrenderer RenderActorView(actor, dontmaplines); - DrawerThreads::Execute({ Thread->DrawQueue }); + DrawerThreads::Execute({ MainThread()->DrawQueue }); viewport->RenderTarget = screen; @@ -241,8 +241,8 @@ namespace swrenderer void RenderScene::Deinit() { - Thread->TranslucentPass->Deinit(); - Thread->Clip3DFloors->Cleanup(); + MainThread()->TranslucentPass->Deinit(); + MainThread()->Clip3DFloors->Cleanup(); } ///////////////////////////////////////////////////////////////////////// diff --git a/src/swrenderer/scene/r_scene.h b/src/swrenderer/scene/r_scene.h index 231fd7a4a..a592ae1d3 100644 --- a/src/swrenderer/scene/r_scene.h +++ b/src/swrenderer/scene/r_scene.h @@ -14,6 +14,7 @@ #pragma once #include +#include #include "r_defs.h" #include "d_player.h" @@ -28,7 +29,7 @@ namespace swrenderer class RenderScene { public: - RenderScene(RenderThread *thread); + RenderScene(); void Init(); void ScreenResized(); @@ -41,12 +42,14 @@ namespace swrenderer bool DontMapLines() const { return dontmaplines; } - RenderThread *Thread = nullptr; + RenderThread *MainThread() { return Threads.front().get(); } private: void RenderActorView(AActor *actor, bool dontmaplines = false); bool dontmaplines = false; int clearcolor = 0; + + std::vector> Threads; }; } diff --git a/src/v_draw.cpp b/src/v_draw.cpp index 9a1c841ce..fd00f8241 100644 --- a/src/v_draw.cpp +++ b/src/v_draw.cpp @@ -279,7 +279,7 @@ void DCanvas::DrawTextureParms(FTexture *img, DrawParms &parms) int x2_i = int(x2); fixed_t xiscale_i = FLOAT2FIXED(xiscale); - static RenderThread thread; + static RenderThread thread(nullptr); thread.DrawQueue->ThreadedRender = false; while (x < x2_i) { @@ -1430,7 +1430,7 @@ void DCanvas::FillSimplePoly(FTexture *tex, FVector2 *points, int npoints, pt2++; if (pt2 > npoints) pt2 = 0; } while (pt1 != botpt); - static RenderThread thread; + static RenderThread thread(nullptr); thread.DrawQueue->ThreadedRender = false; // Travel down the left edge and fill it in.