diff --git a/src/gl/renderer/gl_renderer.h b/src/gl/renderer/gl_renderer.h index 1bfa4a82c..b383537c6 100644 --- a/src/gl/renderer/gl_renderer.h +++ b/src/gl/renderer/gl_renderer.h @@ -19,7 +19,6 @@ class FCanvasTexture; class FFlatVertexBuffer; class FSkyVertexBuffer; class OpenGLFrameBuffer; -struct FDrawInfo; class FShaderManager; class HWPortal; class FLightBuffer; @@ -105,6 +104,7 @@ public: private: + void DrawScene(HWDrawInfo *di, int drawmode); bool QuadStereoCheckInitialRenderContextState(); void PresentAnaglyph(bool r, bool g, bool b); void PresentSideBySide(); diff --git a/src/gl/scene/gl_drawinfo.h b/src/gl/scene/gl_drawinfo.h index afdbb7185..b4e8020e6 100644 --- a/src/gl/scene/gl_drawinfo.h +++ b/src/gl/scene/gl_drawinfo.h @@ -1,3 +1,4 @@ +/* #ifndef __GL_DRAWINFO_H #define __GL_DRAWINFO_H @@ -13,6 +14,6 @@ struct FDrawInfo : public HWDrawInfo { - void DrawScene(int drawmode) override; }; #endif +*/ \ No newline at end of file diff --git a/src/gl/scene/gl_scene.cpp b/src/gl/scene/gl_scene.cpp index f8b48d3ae..92e083391 100644 --- a/src/gl/scene/gl_scene.cpp +++ b/src/gl/scene/gl_scene.cpp @@ -83,11 +83,11 @@ EXTERN_CVAR (Bool, r_drawvoxels) // //----------------------------------------------------------------------------- -void FDrawInfo::DrawScene(int drawmode) +void FGLRenderer::DrawScene(HWDrawInfo *di, int drawmode) { static int recursion=0; static int ssao_portals_available = 0; - const auto &vp = Viewpoint; + const auto &vp = di->Viewpoint; bool applySSAO = false; if (drawmode == DM_MAINVIEW) @@ -108,36 +108,36 @@ void FDrawInfo::DrawScene(int drawmode) if (vp.camera != nullptr) { ActorRenderFlags savedflags = vp.camera->renderflags; - CreateScene(); + di->CreateScene(); vp.camera->renderflags = savedflags; } else { - CreateScene(); + di->CreateScene(); } glDepthMask(true); - if (!gl_no_skyclear) screen->mPortalState->RenderFirstSkyPortal(recursion, this, gl_RenderState); + if (!gl_no_skyclear) screen->mPortalState->RenderFirstSkyPortal(recursion, di, gl_RenderState); - RenderScene(gl_RenderState); + di->RenderScene(gl_RenderState); if (applySSAO && gl_RenderState.GetPassType() == GBUFFER_PASS) { gl_RenderState.EnableDrawBuffers(1); - GLRenderer->AmbientOccludeScene(VPUniforms.mProjectionMatrix.get()[5]); + GLRenderer->AmbientOccludeScene(di->VPUniforms.mProjectionMatrix.get()[5]); glViewport(screen->mSceneViewport.left, screen->mSceneViewport.top, screen->mSceneViewport.width, screen->mSceneViewport.height); GLRenderer->mBuffers->BindSceneFB(true); gl_RenderState.EnableDrawBuffers(gl_RenderState.GetPassDrawBufferCount()); gl_RenderState.Apply(); - screen->mViewpoints->Bind(gl_RenderState, vpIndex); + screen->mViewpoints->Bind(gl_RenderState, di->vpIndex); } // Handle all portals after rendering the opaque objects but before // doing all translucent stuff recursion++; - screen->mPortalState->EndFrame(this, gl_RenderState); + screen->mPortalState->EndFrame(di, gl_RenderState); recursion--; - RenderTranslucent(gl_RenderState); + di->RenderTranslucent(gl_RenderState); } //----------------------------------------------------------------------------- @@ -170,7 +170,7 @@ sector_t * FGLRenderer::RenderViewpoint (FRenderViewpoint &mainvp, AActor * came } - FDrawInfo *di = static_cast(HWDrawInfo::StartDrawInfo(nullptr, mainvp, nullptr)); + auto di = HWDrawInfo::StartDrawInfo(nullptr, mainvp, nullptr); auto &vp = di->Viewpoint; di->Set3DViewport(gl_RenderState); @@ -184,7 +184,10 @@ sector_t * FGLRenderer::RenderViewpoint (FRenderViewpoint &mainvp, AActor * came vp.Pos += eye.GetViewShift(vp.HWAngles.Yaw.Degrees); di->SetupView(gl_RenderState, vp.Pos.X, vp.Pos.Y, vp.Pos.Z, false, false); - di->ProcessScene(toscreen); + // std::function until this can be done better in a cross-API fashion. + di->ProcessScene(toscreen, [&](HWDrawInfo *di, int mode) { + DrawScene(di, mode); + }); if (mainview) { diff --git a/src/gl/system/gl_framebuffer.cpp b/src/gl/system/gl_framebuffer.cpp index d31f11c78..47965d9e4 100644 --- a/src/gl/system/gl_framebuffer.cpp +++ b/src/gl/system/gl_framebuffer.cpp @@ -379,11 +379,6 @@ IDataBuffer *OpenGLFrameBuffer::CreateDataBuffer(int bindingpoint, bool ssbo) return new GLDataBuffer(bindingpoint, ssbo); } -HWDrawInfo *OpenGLFrameBuffer::CreateDrawInfo() -{ - return new FDrawInfo; -} - void OpenGLFrameBuffer::TextureFilterChanged() { if (GLRenderer != NULL && GLRenderer->mSamplerManager != NULL) GLRenderer->mSamplerManager->SetTextureFilterMode(); diff --git a/src/gl/system/gl_framebuffer.h b/src/gl/system/gl_framebuffer.h index 59f2fd30e..582e0ed70 100644 --- a/src/gl/system/gl_framebuffer.h +++ b/src/gl/system/gl_framebuffer.h @@ -43,7 +43,6 @@ public: IVertexBuffer *CreateVertexBuffer() override; IIndexBuffer *CreateIndexBuffer() override; IDataBuffer *CreateDataBuffer(int bindingpoint, bool ssbo) override; - HWDrawInfo *CreateDrawInfo() override; // Retrieves a buffer containing image data for a screenshot. // Hint: Pitch can be negative for upside-down images, in which case buffer diff --git a/src/hwrenderer/scene/hw_drawinfo.cpp b/src/hwrenderer/scene/hw_drawinfo.cpp index 5801bab8c..56f3ddfbb 100644 --- a/src/hwrenderer/scene/hw_drawinfo.cpp +++ b/src/hwrenderer/scene/hw_drawinfo.cpp @@ -97,11 +97,12 @@ HWDrawInfo *FDrawInfoList::GetNew() mList.Pop(di); return di; } - return screen->CreateDrawInfo(); + return new HWDrawInfo; } void FDrawInfoList::Release(HWDrawInfo * di) { + di->DrawScene = nullptr; di->ClearBuffers(); mList.Push(di); } @@ -115,6 +116,7 @@ void FDrawInfoList::Release(HWDrawInfo * di) HWDrawInfo *HWDrawInfo::StartDrawInfo(HWDrawInfo *parent, FRenderViewpoint &parentvp, HWViewpointUniforms *uniforms) { HWDrawInfo *di = di_list.GetNew(); + if (parent) di->DrawScene = parent->DrawScene; di->StartScene(parentvp, uniforms); return di; } @@ -674,14 +676,13 @@ void HWDrawInfo::Set3DViewport(FRenderState &state) // //----------------------------------------------------------------------------- -void HWDrawInfo::ProcessScene(bool toscreen) +void HWDrawInfo::ProcessScene(bool toscreen, const std::function &drawScene) { screen->mPortalState->BeginScene(); int mapsection = R_PointInSubsector(Viewpoint.Pos)->mapsection; CurrentMapSections.Set(mapsection); - DrawScene(toscreen ? DM_MAINVIEW : DM_OFFSCREEN); + DrawScene = drawScene; + DrawScene(this, toscreen ? DM_MAINVIEW : DM_OFFSCREEN); } - - diff --git a/src/hwrenderer/scene/hw_drawinfo.h b/src/hwrenderer/scene/hw_drawinfo.h index bb4cdb4c3..9c0f906a8 100644 --- a/src/hwrenderer/scene/hw_drawinfo.h +++ b/src/hwrenderer/scene/hw_drawinfo.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include "vectors.h" #include "r_defs.h" #include "r_utility.h" @@ -178,6 +179,7 @@ struct HWDrawInfo area_t in_area; fixed_t viewx, viewy; // since the nodes are still fixed point, keeping the view position also fixed point for node traversal is faster. + std::function DrawScene = nullptr; private: // For ProcessLowerMiniseg @@ -190,7 +192,6 @@ private: sector_t fakesec; // this is a struct member because it gets used in recursively called functions so it cannot be put on the stack. - void UnclipSubsector(subsector_t *sub); void AddLine(seg_t *seg, bool portalclip); void PolySubsector(subsector_t * sub); @@ -271,7 +272,7 @@ public: void EndDrawScene(sector_t * viewsector, FRenderState &state); void DrawEndScene2D(sector_t * viewsector, FRenderState &state); void Set3DViewport(FRenderState &state); - void ProcessScene(bool toscreen); + void ProcessScene(bool toscreen, const std::function &drawScene); bool DoOneSectorUpper(subsector_t * subsec, float planez, area_t in_area); bool DoOneSectorLower(subsector_t * subsec, float planez, area_t in_area); @@ -329,7 +330,5 @@ public: GLDecal *AddDecal(bool onmirror); - - virtual void DrawScene(int drawmode) = 0; }; diff --git a/src/hwrenderer/scene/hw_portal.h b/src/hwrenderer/scene/hw_portal.h index 31064d5f9..35629b89a 100644 --- a/src/hwrenderer/scene/hw_portal.h +++ b/src/hwrenderer/scene/hw_portal.h @@ -328,7 +328,7 @@ public: { if (mScene->Setup(di, state, di->mClipper)) { - di->DrawScene(DM_PORTAL); + di->DrawScene(di, DM_PORTAL); mScene->Shutdown(di, state); } else state.ClearScreen(); diff --git a/src/v_video.h b/src/v_video.h index 8d7356013..75db34bf2 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -469,7 +469,6 @@ public: virtual IVertexBuffer *CreateVertexBuffer() { return nullptr; } virtual IIndexBuffer *CreateIndexBuffer() { return nullptr; } virtual IDataBuffer *CreateDataBuffer(int bindingpoint, bool ssbo) { return nullptr; } - virtual HWDrawInfo *CreateDrawInfo() { return nullptr; } bool BuffersArePersistent() { return !!(hwcaps & RFL_BUFFER_STORAGE); } // Begin/End 2D drawing operations.