diff --git a/src/gl/renderer/gl_renderer.h b/src/gl/renderer/gl_renderer.h index e223bb9b8..1bfa4a82c 100644 --- a/src/gl/renderer/gl_renderer.h +++ b/src/gl/renderer/gl_renderer.h @@ -94,7 +94,6 @@ public: sector_t *RenderView(player_t *player); void BeginFrame(); - void Set3DViewport(); sector_t *RenderViewpoint (FRenderViewpoint &mainvp, AActor * camera, IntRect * bounds, float fov, float ratio, float fovratio, bool mainview, bool toscreen); diff --git a/src/gl/scene/gl_scene.cpp b/src/gl/scene/gl_scene.cpp index e7fb11eab..efc9f0a3b 100644 --- a/src/gl/scene/gl_scene.cpp +++ b/src/gl/scene/gl_scene.cpp @@ -157,34 +157,6 @@ void FDrawInfo::ProcessScene(bool toscreen) } -//----------------------------------------------------------------------------- -// -// sets 3D viewport and initial state -// -//----------------------------------------------------------------------------- - -void FGLRenderer::Set3DViewport() -{ - // Always clear all buffers with scissor test disabled. - // This is faster on newer hardware because it allows the GPU to skip - // reading from slower memory where the full buffers are stored. - glDisable(GL_SCISSOR_TEST); - glClearColor(screen->mSceneClearColor[0], screen->mSceneClearColor[1], screen->mSceneClearColor[2], screen->mSceneClearColor[3]); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); - - const auto &bounds = screen->mSceneViewport; - glViewport(bounds.left, bounds.top, bounds.width, bounds.height); - glScissor(bounds.left, bounds.top, bounds.width, bounds.height); - - glEnable(GL_SCISSOR_TEST); - - glEnable(GL_MULTISAMPLE); - glEnable(GL_DEPTH_TEST); - glEnable(GL_STENCIL_TEST); - glStencilFunc(GL_ALWAYS,0,~0); // default stencil - glStencilOp(GL_KEEP,GL_KEEP,GL_REPLACE); -} - //----------------------------------------------------------------------------- // // Renders one viewpoint in a scene @@ -214,10 +186,11 @@ sector_t * FGLRenderer::RenderViewpoint (FRenderViewpoint &mainvp, AActor * came gl_RenderState.Apply(); } - Set3DViewport(); FDrawInfo *di = static_cast(HWDrawInfo::StartDrawInfo(mainvp, nullptr)); auto &vp = di->Viewpoint; + + di->Set3DViewport(gl_RenderState); di->SetViewArea(); auto cm = di->SetFullbrightFlags(mainview ? vp.camera->player : nullptr); di->Viewpoint.FieldOfView = fov; // Set the real FOV for the current scene (it's not necessarily the same as the global setting in r_viewpoint) diff --git a/src/hwrenderer/scene/hw_drawinfo.cpp b/src/hwrenderer/scene/hw_drawinfo.cpp index 42c728c7e..f5d970e1d 100644 --- a/src/hwrenderer/scene/hw_drawinfo.cpp +++ b/src/hwrenderer/scene/hw_drawinfo.cpp @@ -645,3 +645,26 @@ void HWDrawInfo::DrawEndScene2D(sector_t * viewsector, FRenderState &state) state.SetScissor(0, 0, -1, -1); } +//----------------------------------------------------------------------------- +// +// sets 3D viewport and initial state +// +//----------------------------------------------------------------------------- + +void HWDrawInfo::Set3DViewport(FRenderState &state) +{ + // Always clear all buffers with scissor test disabled. + // This is faster on newer hardware because it allows the GPU to skip + // reading from slower memory where the full buffers are stored. + state.SetScissor(0, 0, -1, -1); + state.Clear(CT_Color | CT_Depth | CT_Stencil); + + const auto &bounds = screen->mSceneViewport; + state.SetViewport(bounds.left, bounds.top, bounds.width, bounds.height); + state.SetScissor(bounds.left, bounds.top, bounds.width, bounds.height); + state.EnableMultisampling(true); + state.EnableDepthTest(true); + state.EnableStencil(true); + state.SetStencil(0, SOP_Keep, SF_AllOn); +} + diff --git a/src/hwrenderer/scene/hw_drawinfo.h b/src/hwrenderer/scene/hw_drawinfo.h index 649fc69b7..fa248a938 100644 --- a/src/hwrenderer/scene/hw_drawinfo.h +++ b/src/hwrenderer/scene/hw_drawinfo.h @@ -308,6 +308,7 @@ public: void RenderPortal(HWPortal *p, FRenderState &state, bool usestencil); void EndDrawScene(sector_t * viewsector, FRenderState &state); void DrawEndScene2D(sector_t * viewsector, FRenderState &state); + void Set3DViewport(FRenderState &state); bool DoOneSectorUpper(subsector_t * subsec, float planez, area_t in_area); bool DoOneSectorLower(subsector_t * subsec, float planez, area_t in_area); diff --git a/src/hwrenderer/scene/hw_portal.cpp b/src/hwrenderer/scene/hw_portal.cpp index edb347946..dc2c8f4fb 100644 --- a/src/hwrenderer/scene/hw_portal.cpp +++ b/src/hwrenderer/scene/hw_portal.cpp @@ -268,7 +268,7 @@ void HWPortal::RemoveStencil(HWDrawInfo *di, FRenderState &state, bool usestenci auto &vp = di->Viewpoint; if (vp.camera != nullptr) vp.camera->renderflags = (vp.camera->renderflags & ~RF_MAYBEINVISIBLE) | savedvisibility; - state.EnableDepthTest(true); + state.EnableDepthTest(true); if (usestencil) { state.SetEffect(EFF_NONE); diff --git a/src/hwrenderer/scene/hw_renderstate.h b/src/hwrenderer/scene/hw_renderstate.h index bc06e859b..45349497a 100644 --- a/src/hwrenderer/scene/hw_renderstate.h +++ b/src/hwrenderer/scene/hw_renderstate.h @@ -14,9 +14,9 @@ class IIndexBuffer; enum EClearTarget { - CT_Depth, - CT_Stencil, - CT_Color + CT_Depth = 1, + CT_Stencil = 2, + CT_Color = 4 }; enum ERenderEffect