From 6177ed153d27c2f1ea30501d9f564d4658bdacf2 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 25 Apr 2020 10:51:45 +0200 Subject: [PATCH] - consolidated the 3 RenderViewpoint variants and took the function out of the framebuffer class. --- src/rendering/gl/renderer/gl_renderer.h | 3 - src/rendering/gl/renderer/gl_renderstate.h | 5 +- src/rendering/gl/renderer/gl_scene.cpp | 79 +++++------------- src/rendering/gl/system/gl_framebuffer.cpp | 28 ++++++- src/rendering/gl/system/gl_framebuffer.h | 7 +- .../hwrenderer/scene/hw_drawinfo.cpp | 4 + src/rendering/hwrenderer/scene/hw_drawinfo.h | 1 + .../hwrenderer/scene/hw_renderstate.h | 2 +- src/rendering/hwrenderer/utility/hw_cvars.h | 2 +- .../polyrenderer/backend/poly_framebuffer.cpp | 74 +---------------- .../polyrenderer/backend/poly_framebuffer.h | 4 +- .../polyrenderer/backend/poly_renderstate.cpp | 2 +- .../polyrenderer/backend/poly_renderstate.h | 2 +- src/rendering/swrenderer/r_swscene.cpp | 4 +- src/rendering/v_video.h | 6 +- .../vulkan/renderer/vk_renderstate.cpp | 2 +- .../vulkan/renderer/vk_renderstate.h | 2 +- .../vulkan/system/vk_framebuffer.cpp | 81 ++----------------- src/rendering/vulkan/system/vk_framebuffer.h | 6 +- 19 files changed, 85 insertions(+), 229 deletions(-) diff --git a/src/rendering/gl/renderer/gl_renderer.h b/src/rendering/gl/renderer/gl_renderer.h index 84448bfc37..ea8aaf44ae 100644 --- a/src/rendering/gl/renderer/gl_renderer.h +++ b/src/rendering/gl/renderer/gl_renderer.h @@ -91,9 +91,6 @@ public: void Draw2D(F2DDrawer *data); void BeginFrame(); - sector_t *RenderViewpoint (FRenderViewpoint &mainvp, AActor * camera, IntRect * bounds, float fov, float ratio, float fovratio, bool mainview, bool toscreen); - - bool StartOffscreen(); void EndOffscreen(); void UpdateShadowMap(); diff --git a/src/rendering/gl/renderer/gl_renderstate.h b/src/rendering/gl/renderer/gl_renderstate.h index 9a52a1d149..a366f75d04 100644 --- a/src/rendering/gl/renderer/gl_renderstate.h +++ b/src/rendering/gl/renderer/gl_renderstate.h @@ -40,7 +40,7 @@ namespace OpenGLRenderer class FShader; struct HWSectorPlane; -class FGLRenderState : public FRenderState +class FGLRenderState final : public FRenderState { uint8_t mLastDepthClamp : 1; @@ -108,7 +108,7 @@ public: mSpecularLevel = specularLevel; } - void EnableDrawBuffers(int count) override + void EnableDrawBuffers(int count, bool apply = false) override { count = MIN(count, 3); if (mNumDrawBuffers != count) @@ -117,6 +117,7 @@ public: glDrawBuffers(count, buffers); mNumDrawBuffers = count; } + if (apply) Apply(); } void ToggleState(int state, bool on); diff --git a/src/rendering/gl/renderer/gl_scene.cpp b/src/rendering/gl/renderer/gl_scene.cpp index 4f99f2e2a7..55f3730990 100644 --- a/src/rendering/gl/renderer/gl_scene.cpp +++ b/src/rendering/gl/renderer/gl_scene.cpp @@ -29,53 +29,20 @@ #include "gi.h" #include "m_png.h" #include "doomstat.h" -#include "g_level.h" #include "r_data/r_interpolate.h" #include "r_utility.h" #include "d_player.h" -#include "p_effect.h" -#include "sbar.h" -#include "po_man.h" -#include "p_local.h" -#include "serializer.h" -#include "g_levellocals.h" -#include "actorinlines.h" -#include "r_data/models/models.h" #include "hwrenderer/dynlights/hw_dynlightdata.h" #include "hwrenderer/utility/hw_clock.h" #include "hwrenderer/data/flatvertices.h" #include "hwrenderer/dynlights/hw_lightbuffer.h" -#include "gl_interface.h" -#include "gl/system/gl_framebuffer.h" -#include "gl/system/gl_debug.h" #include "hwrenderer/utility/hw_cvars.h" -#include "gl/renderer/gl_renderstate.h" -#include "gl/renderer/gl_renderbuffers.h" #include "hwrenderer/data/hw_viewpointbuffer.h" #include "hwrenderer/scene/hw_clipper.h" #include "hwrenderer/scene/hw_portal.h" #include "hwrenderer/utility/hw_vrmodes.h" -#include "gl/renderer/gl_renderer.h" -#include "gl/system/gl_buffers.h" -//========================================================================== -// -// CVARs -// -//========================================================================== -CVAR(Bool, gl_texture, true, 0) -CVAR(Float, gl_mask_threshold, 0.5f,CVAR_ARCHIVE|CVAR_GLOBALCONFIG) -CVAR(Float, gl_mask_sprite_threshold, 0.5f,CVAR_ARCHIVE|CVAR_GLOBALCONFIG) - -EXTERN_CVAR (Bool, cl_capfps) -EXTERN_CVAR (Bool, r_deathcamera) -EXTERN_CVAR (Float, r_visibility) -EXTERN_CVAR (Bool, r_drawvoxels) - - -namespace OpenGLRenderer -{ //----------------------------------------------------------------------------- // @@ -83,75 +50,71 @@ namespace OpenGLRenderer // //----------------------------------------------------------------------------- -sector_t * FGLRenderer::RenderViewpoint (FRenderViewpoint &mainvp, AActor * camera, IntRect * bounds, float fov, float ratio, float fovratio, bool mainview, bool toscreen) +sector_t* RenderViewpoint(FRenderViewpoint& mainvp, AActor* camera, IntRect* bounds, float fov, float ratio, float fovratio, bool mainview, bool toscreen) { - R_SetupFrame (mainvp, r_viewwindow, camera); + auto& RenderState = *screen->RenderState(); + + R_SetupFrame(mainvp, r_viewwindow, camera); if (mainview && toscreen) - UpdateShadowMap(); + screen->UpdateShadowMap(); // Update the attenuation flag of all light defaults for each viewpoint. // This function will only do something if the setting differs. FLightDefaults::SetAttenuationForLevel(!!(camera->Level->flags3 & LEVEL3_ATTENUATE)); - // Render (potentially) multiple views for stereo 3d + // Render (potentially) multiple views for stereo 3d // Fixme. The view offsetting should be done with a static table and not require setup of the entire render state for the mode. auto vrmode = VRMode::GetVRMode(mainview && toscreen); const int eyeCount = vrmode->mEyeCount; - mBuffers->CurrentEye() = 0; // always begin at zero, in case eye count changed + screen->FirstEye(); for (int eye_ix = 0; eye_ix < eyeCount; ++eye_ix) { - const auto &eye = vrmode->mEyes[mBuffers->CurrentEye()]; + const auto& eye = vrmode->mEyes[eye_ix]; screen->SetViewportRects(bounds); if (mainview) // Bind the scene frame buffer and turn on draw buffers used by ssao { bool useSSAO = (gl_ssao != 0); - mBuffers->BindSceneFB(useSSAO); - gl_RenderState.SetPassType(useSSAO ? GBUFFER_PASS : NORMAL_PASS); - gl_RenderState.EnableDrawBuffers(gl_RenderState.GetPassDrawBufferCount()); - gl_RenderState.Apply(); + screen->SetSceneRenderTarget(useSSAO); + RenderState.SetPassType(useSSAO ? GBUFFER_PASS : NORMAL_PASS); + RenderState.EnableDrawBuffers(RenderState.GetPassDrawBufferCount(), true); } - auto di = HWDrawInfo::StartDrawInfo(mainvp.ViewLevel, nullptr, mainvp, nullptr); - auto &vp = di->Viewpoint; + auto& vp = di->Viewpoint; - di->Set3DViewport(gl_RenderState); + di->Set3DViewport(RenderState); di->SetViewArea(); - auto cm = di->SetFullbrightFlags(mainview ? vp.camera->player : nullptr); + 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) // Stereo mode specific perspective projection di->VPUniforms.mProjectionMatrix = eye.GetProjection(fov, ratio, fovratio); // Stereo mode specific viewpoint adjustment vp.Pos += eye.GetViewShift(vp.HWAngles.Yaw.Degrees); - di->SetupView(gl_RenderState, vp.Pos.X, vp.Pos.Y, vp.Pos.Z, false, false); + di->SetupView(RenderState, vp.Pos.X, vp.Pos.Y, vp.Pos.Z, false, false); di->ProcessScene(toscreen); if (mainview) { PostProcess.Clock(); - if (toscreen) di->EndDrawScene(mainvp.sector, gl_RenderState); // do not call this for camera textures. + if (toscreen) di->EndDrawScene(mainvp.sector, RenderState); // do not call this for camera textures. - if (gl_RenderState.GetPassType() == GBUFFER_PASS) // Turn off ssao draw buffers + if (RenderState.GetPassType() == GBUFFER_PASS) // Turn off ssao draw buffers { - gl_RenderState.SetPassType(NORMAL_PASS); - gl_RenderState.EnableDrawBuffers(1); + RenderState.SetPassType(NORMAL_PASS); + RenderState.EnableDrawBuffers(1); } - mBuffers->BlitSceneToTexture(); // Copy the resulting scene to the current post process texture - - PostProcessScene(cm, [&]() { di->DrawEndScene2D(mainvp.sector, gl_RenderState); }); + screen->PostProcessScene(false, cm, [&]() { di->DrawEndScene2D(mainvp.sector, RenderState); }); PostProcess.Unclock(); } di->EndDrawInfo(); if (eyeCount - eye_ix > 1) - mBuffers->NextEye(eyeCount); + screen->NextEye(eyeCount); } return mainvp.sector; } - -} diff --git a/src/rendering/gl/system/gl_framebuffer.cpp b/src/rendering/gl/system/gl_framebuffer.cpp index d85a4b3515..8eed568693 100644 --- a/src/rendering/gl/system/gl_framebuffer.cpp +++ b/src/rendering/gl/system/gl_framebuffer.cpp @@ -226,7 +226,7 @@ void OpenGLFrameBuffer::WriteSavePic(player_t *player, FileWriter *file, int wid // This shouldn't overwrite the global viewpoint even for a short time. FRenderViewpoint savevp; - sector_t* viewsector = GLRenderer->RenderViewpoint(savevp, players[consoleplayer].camera, &bounds, r_viewpoint.FieldOfView.Degrees, 1.6f, 1.6f, true, false); + sector_t* viewsector = RenderViewpoint(savevp, players[consoleplayer].camera, &bounds, r_viewpoint.FieldOfView.Degrees, 1.6f, 1.6f, true, false); glDisable(GL_STENCIL_TEST); gl_RenderState.SetNoSoftLightLevel(); GLRenderer->CopyToBackbuffer(&bounds, false); @@ -268,7 +268,7 @@ void OpenGLFrameBuffer::RenderTextureView(FCanvasTexture* tex, AActor* Viewpoint bounds.height = FHardwareTexture::GetTexDimension(tex->GetHeight()); FRenderViewpoint texvp; - GLRenderer->RenderViewpoint(texvp, Viewpoint, &bounds, FOV, ratio, ratio, false, false); + RenderViewpoint(texvp, Viewpoint, &bounds, FOV, ratio, ratio, false, false); GLRenderer->EndOffscreen(); @@ -344,7 +344,7 @@ sector_t *OpenGLFrameBuffer::RenderView(player_t *player) fovratio = ratio; } - retsec = GLRenderer->RenderViewpoint(r_viewpoint, player->camera, NULL, r_viewpoint.FieldOfView.Degrees, ratio, fovratio, true, true); + retsec = RenderViewpoint(r_viewpoint, player->camera, NULL, r_viewpoint.FieldOfView.Degrees, ratio, fovratio, true, true); } All.Unclock(); return retsec; @@ -529,6 +529,25 @@ void OpenGLFrameBuffer::AmbientOccludeScene(float m5) gl_RenderState.Apply(); } +void OpenGLFrameBuffer::FirstEye() +{ + GLRenderer->mBuffers->CurrentEye() = 0; // always begin at zero, in case eye count changed +} + +void OpenGLFrameBuffer::NextEye(int eyecount) +{ + GLRenderer->mBuffers->NextEye(eyecount); +} + +void OpenGLFrameBuffer::SetSceneRenderTarget(bool useSSAO) +{ + GLRenderer->mBuffers->BindSceneFB(useSSAO); +} + +void OpenGLFrameBuffer::UpdateShadowMap() +{ + GLRenderer->UpdateShadowMap(); +} //=========================================================================== // @@ -610,8 +629,9 @@ void OpenGLFrameBuffer::Draw2D() } } -void OpenGLFrameBuffer::PostProcessScene(int fixedcm, const std::function &afterBloomDrawEndScene2D) +void OpenGLFrameBuffer::PostProcessScene(bool swscene, int fixedcm, const std::function &afterBloomDrawEndScene2D) { + if (!swscene) GLRenderer->mBuffers->BlitSceneToTexture(); // Copy the resulting scene to the current post process texture GLRenderer->PostProcessScene(fixedcm, afterBloomDrawEndScene2D); } diff --git a/src/rendering/gl/system/gl_framebuffer.h b/src/rendering/gl/system/gl_framebuffer.h index 1875abdbd7..a6286fcb3b 100644 --- a/src/rendering/gl/system/gl_framebuffer.h +++ b/src/rendering/gl/system/gl_framebuffer.h @@ -28,6 +28,11 @@ public: void Update() override; void AmbientOccludeScene(float m5) override; + void FirstEye() override; + void NextEye(int eyecount) override; + void SetSceneRenderTarget(bool useSSAO) override; + void UpdateShadowMap() override; + FRenderState* RenderState() override; void CleanForRestart() override; void UpdatePalette() override; @@ -58,7 +63,7 @@ public: void SetVSync(bool vsync); void Draw2D() override; - void PostProcessScene(int fixedcm, const std::function &afterBloomDrawEndScene2D) override; + void PostProcessScene(bool swscene, int fixedcm, const std::function &afterBloomDrawEndScene2D) override; bool HWGammaActive = false; // Are we using hardware or software gamma? std::shared_ptr mDebug; // Debug API diff --git a/src/rendering/hwrenderer/scene/hw_drawinfo.cpp b/src/rendering/hwrenderer/scene/hw_drawinfo.cpp index 15c5ab290a..b1cad03a1e 100644 --- a/src/rendering/hwrenderer/scene/hw_drawinfo.cpp +++ b/src/rendering/hwrenderer/scene/hw_drawinfo.cpp @@ -49,6 +49,10 @@ CVAR(Bool, gl_bandedswlight, false, CVAR_ARCHIVE) CVAR(Bool, gl_sort_textures, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) CVAR(Bool, gl_no_skyclear, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) +CVAR(Bool, gl_texture, true, 0) +CVAR(Float, gl_mask_threshold, 0.5f, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) +CVAR(Float, gl_mask_sprite_threshold, 0.5f, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) + sector_t * hw_FakeFlat(sector_t * sec, sector_t * dest, area_t in_area, bool back); //========================================================================== diff --git a/src/rendering/hwrenderer/scene/hw_drawinfo.h b/src/rendering/hwrenderer/scene/hw_drawinfo.h index 9b86ecf378..27db44e828 100644 --- a/src/rendering/hwrenderer/scene/hw_drawinfo.h +++ b/src/rendering/hwrenderer/scene/hw_drawinfo.h @@ -329,3 +329,4 @@ public: }; +sector_t* RenderViewpoint(FRenderViewpoint& mainvp, AActor* camera, IntRect* bounds, float fov, float ratio, float fovratio, bool mainview, bool toscreen); diff --git a/src/rendering/hwrenderer/scene/hw_renderstate.h b/src/rendering/hwrenderer/scene/hw_renderstate.h index f7caed8335..d5399ad712 100644 --- a/src/rendering/hwrenderer/scene/hw_renderstate.h +++ b/src/rendering/hwrenderer/scene/hw_renderstate.h @@ -672,7 +672,7 @@ public: virtual void EnableDepthTest(bool on) = 0; // used by 2D, portals and render hacks. virtual void EnableMultisampling(bool on) = 0; // only active for 2D virtual void EnableLineSmooth(bool on) = 0; // constant setting for each 2D drawer operation - virtual void EnableDrawBuffers(int count) = 0; // Used by SSAO and EnableDrawBufferAttachments + virtual void EnableDrawBuffers(int count, bool apply = false) = 0; // Used by SSAO and EnableDrawBufferAttachments void SetColorMask(bool on) { diff --git a/src/rendering/hwrenderer/utility/hw_cvars.h b/src/rendering/hwrenderer/utility/hw_cvars.h index 8d184206dd..79c97b6827 100644 --- a/src/rendering/hwrenderer/utility/hw_cvars.h +++ b/src/rendering/hwrenderer/utility/hw_cvars.h @@ -4,9 +4,9 @@ #include "r_defs.h" #include "c_cvars.h" + EXTERN_CVAR(Bool,gl_enhanced_nightvision) EXTERN_CVAR(Int, screenblocks); -EXTERN_CVAR(Bool, gl_texture) EXTERN_CVAR(Int, gl_texture_filter) EXTERN_CVAR(Float, gl_texture_filter_anisotropic) EXTERN_CVAR(Int, gl_texture_format) diff --git a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp index 658b31a804..427e24ffe8 100644 --- a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp +++ b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp @@ -296,78 +296,6 @@ sector_t *PolyFrameBuffer::RenderView(player_t *player) return retsec; } -sector_t *PolyFrameBuffer::RenderViewpoint(FRenderViewpoint &mainvp, AActor * camera, IntRect * bounds, float fov, float ratio, float fovratio, bool mainview, bool toscreen) -{ - // To do: this is virtually identical to FGLRenderer::RenderViewpoint and should be merged. - - R_SetupFrame(mainvp, r_viewwindow, camera); - - if (mainview && toscreen) - UpdateShadowMap(); - - // Update the attenuation flag of all light defaults for each viewpoint. - // This function will only do something if the setting differs. - FLightDefaults::SetAttenuationForLevel(!!(camera->Level->flags3 & LEVEL3_ATTENUATE)); - - // Render (potentially) multiple views for stereo 3d - // Fixme. The view offsetting should be done with a static table and not require setup of the entire render state for the mode. - auto vrmode = VRMode::GetVRMode(mainview && toscreen); - for (int eye_ix = 0; eye_ix < vrmode->mEyeCount; ++eye_ix) - { - const auto &eye = vrmode->mEyes[eye_ix]; - SetViewportRects(bounds); - - if (mainview) // Bind the scene frame buffer and turn on draw buffers used by ssao - { - //mRenderState->SetRenderTarget(GetBuffers()->SceneColor.View.get(), GetBuffers()->SceneDepthStencil.View.get(), GetBuffers()->GetWidth(), GetBuffers()->GetHeight(), Poly_FORMAT_R16G16B16A16_SFLOAT, GetBuffers()->GetSceneSamples()); - bool useSSAO = (gl_ssao != 0); - GetRenderState()->SetPassType(useSSAO ? GBUFFER_PASS : NORMAL_PASS); - GetRenderState()->EnableDrawBuffers(GetRenderState()->GetPassDrawBufferCount()); - } - - auto di = HWDrawInfo::StartDrawInfo(mainvp.ViewLevel, nullptr, mainvp, nullptr); - auto &vp = di->Viewpoint; - - di->Set3DViewport(*GetRenderState()); - 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) - - // Stereo mode specific perspective projection - di->VPUniforms.mProjectionMatrix = eye.GetProjection(fov, ratio, fovratio); - // Stereo mode specific viewpoint adjustment - vp.Pos += eye.GetViewShift(vp.HWAngles.Yaw.Degrees); - di->SetupView(*GetRenderState(), vp.Pos.X, vp.Pos.Y, vp.Pos.Z, false, false); - - di->ProcessScene(toscreen); - - if (mainview) - { - PostProcess.Clock(); - if (toscreen) di->EndDrawScene(mainvp.sector, *GetRenderState()); // do not call this for camera textures. - - if (GetRenderState()->GetPassType() == GBUFFER_PASS) // Turn off ssao draw buffers - { - GetRenderState()->SetPassType(NORMAL_PASS); - GetRenderState()->EnableDrawBuffers(1); - } - - //mPostprocess->BlitSceneToPostprocess(); // Copy the resulting scene to the current post process texture - - PostProcessScene(cm, [&]() { di->DrawEndScene2D(mainvp.sector, *GetRenderState()); }); - - PostProcess.Unclock(); - } - di->EndDrawInfo(); - -#if 0 - if (vrmode->mEyeCount > 1) - mBuffers->BlitToEyeTexture(eye_ix); -#endif - } - - return mainvp.sector; -} void PolyFrameBuffer::RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint, double FOV) { @@ -399,7 +327,7 @@ static uint8_t ToIntColorComponent(float v) return clamp((int)(v * 255.0f + 0.5f), 0, 255); } -void PolyFrameBuffer::PostProcessScene(int fixedcm, const std::function &afterBloomDrawEndScene2D) +void PolyFrameBuffer::PostProcessScene(bool swscene, int fixedcm, const std::function &afterBloomDrawEndScene2D) { afterBloomDrawEndScene2D(); diff --git a/src/rendering/polyrenderer/backend/poly_framebuffer.h b/src/rendering/polyrenderer/backend/poly_framebuffer.h index 2b58476237..a7e6ee14e0 100644 --- a/src/rendering/polyrenderer/backend/poly_framebuffer.h +++ b/src/rendering/polyrenderer/backend/poly_framebuffer.h @@ -46,8 +46,9 @@ public: void TextureFilterChanged() override; void BeginFrame() override; void BlurScene(float amount) override; - void PostProcessScene(int fixedcm, const std::function &afterBloomDrawEndScene2D) override; + void PostProcessScene(bool swscene, int fixedcm, const std::function &afterBloomDrawEndScene2D) override; void AmbientOccludeScene(float m5) override; + //void SetSceneRenderTarget(bool useSSAO) override; IHardwareTexture *CreateHardwareTexture() override; FModelRenderer *CreateModelRenderer(int mli) override; @@ -70,7 +71,6 @@ public: } FrameDeleteList; private: - sector_t *RenderViewpoint(FRenderViewpoint &mainvp, AActor * camera, IntRect * bounds, float fov, float ratio, float fovratio, bool mainview, bool toscreen); void RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint, double FOV); void UpdateShadowMap(); diff --git a/src/rendering/polyrenderer/backend/poly_renderstate.cpp b/src/rendering/polyrenderer/backend/poly_renderstate.cpp index 5b56af5c19..a8f1550558 100644 --- a/src/rendering/polyrenderer/backend/poly_renderstate.cpp +++ b/src/rendering/polyrenderer/backend/poly_renderstate.cpp @@ -200,7 +200,7 @@ void PolyRenderState::EnableLineSmooth(bool on) { } -void PolyRenderState::EnableDrawBuffers(int count) +void PolyRenderState::EnableDrawBuffers(int count, bool apply) { } diff --git a/src/rendering/polyrenderer/backend/poly_renderstate.h b/src/rendering/polyrenderer/backend/poly_renderstate.h index e8069ffe85..1db19c71a5 100644 --- a/src/rendering/polyrenderer/backend/poly_renderstate.h +++ b/src/rendering/polyrenderer/backend/poly_renderstate.h @@ -38,7 +38,7 @@ public: void EnableDepthTest(bool on) override; void EnableMultisampling(bool on) override; void EnableLineSmooth(bool on) override; - void EnableDrawBuffers(int count) override; + void EnableDrawBuffers(int count, bool apply) override; void SetRenderTarget(DCanvas *canvas, PolyDepthStencil *depthStencil, bool topdown); void Bind(PolyDataBuffer *buffer, uint32_t offset, uint32_t length); diff --git a/src/rendering/swrenderer/r_swscene.cpp b/src/rendering/swrenderer/r_swscene.cpp index d25ba485fd..1f49803684 100644 --- a/src/rendering/swrenderer/r_swscene.cpp +++ b/src/rendering/swrenderer/r_swscene.cpp @@ -122,7 +122,7 @@ sector_t *SWSceneDrawer::RenderView(player_t *player) DrawTexture(twod, fbtex.get(), 0, 0, DTA_SpecialColormap, map, TAG_DONE); screen->Draw2D(); screen->Clear2D(); - screen->PostProcessScene(CM_DEFAULT, [&]() { + screen->PostProcessScene(true, CM_DEFAULT, [&]() { SWRenderer->DrawRemainingPlayerSprites(); screen->Draw2D(); screen->Clear2D(); @@ -138,7 +138,7 @@ sector_t *SWSceneDrawer::RenderView(player_t *player) int cm = CM_DEFAULT; auto map = swrenderer::CameraLight::Instance()->ShaderColormap(); if (map) cm = (int)(ptrdiff_t)(map - SpecialColormaps.Data()) + CM_FIRSTSPECIALCOLORMAP; - screen->PostProcessScene(cm, [&]() { }); + screen->PostProcessScene(true, cm, [&]() { }); SWRenderer->DrawRemainingPlayerSprites(); screen->Draw2D(); diff --git a/src/rendering/v_video.h b/src/rendering/v_video.h index 300b054421..4b7aedd1a8 100644 --- a/src/rendering/v_video.h +++ b/src/rendering/v_video.h @@ -312,12 +312,16 @@ public: virtual void WriteSavePic(player_t *player, FileWriter *file, int width, int height); virtual sector_t *RenderView(player_t *player) { return nullptr; } virtual void AmbientOccludeScene(float m5) {} + virtual void FirstEye() {} + virtual void NextEye(int eyecount) {} + virtual void SetSceneRenderTarget(bool useSSAO) {} + virtual void UpdateShadowMap() {} // Screen wiping virtual FTexture *WipeStartScreen(); virtual FTexture *WipeEndScreen(); - virtual void PostProcessScene(int fixedcm, const std::function &afterBloomDrawEndScene2D) { if (afterBloomDrawEndScene2D) afterBloomDrawEndScene2D(); } + virtual void PostProcessScene(bool swscene, int fixedcm, const std::function &afterBloomDrawEndScene2D) { if (afterBloomDrawEndScene2D) afterBloomDrawEndScene2D(); } void ScaleCoordsFromWindow(int16_t &x, int16_t &y); diff --git a/src/rendering/vulkan/renderer/vk_renderstate.cpp b/src/rendering/vulkan/renderer/vk_renderstate.cpp index 721c56861b..3e2cc97e74 100644 --- a/src/rendering/vulkan/renderer/vk_renderstate.cpp +++ b/src/rendering/vulkan/renderer/vk_renderstate.cpp @@ -506,7 +506,7 @@ void VkRenderState::EndFrame() mStreamBufferWriter.Reset(); } -void VkRenderState::EnableDrawBuffers(int count) +void VkRenderState::EnableDrawBuffers(int count, bool apply) { if (mRenderTarget.DrawBuffers != count) { diff --git a/src/rendering/vulkan/renderer/vk_renderstate.h b/src/rendering/vulkan/renderer/vk_renderstate.h index fcdc8efb1d..9494a794b2 100644 --- a/src/rendering/vulkan/renderer/vk_renderstate.h +++ b/src/rendering/vulkan/renderer/vk_renderstate.h @@ -42,7 +42,7 @@ public: void EnableDepthTest(bool on) override; void EnableMultisampling(bool on) override; void EnableLineSmooth(bool on) override; - void EnableDrawBuffers(int count) override; + void EnableDrawBuffers(int count, bool apply) override; void BeginFrame(); void SetRenderTarget(VkTextureImage *image, VulkanImageView *depthStencilView, int width, int height, VkFormat Format, VkSampleCountFlagBits samples); diff --git a/src/rendering/vulkan/system/vk_framebuffer.cpp b/src/rendering/vulkan/system/vk_framebuffer.cpp index 32013a919b..f3404ef80c 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.cpp +++ b/src/rendering/vulkan/system/vk_framebuffer.cpp @@ -436,79 +436,6 @@ sector_t *VulkanFrameBuffer::RenderView(player_t *player) return retsec; } -sector_t *VulkanFrameBuffer::RenderViewpoint(FRenderViewpoint &mainvp, AActor * camera, IntRect * bounds, float fov, float ratio, float fovratio, bool mainview, bool toscreen) -{ - // To do: this is virtually identical to FGLRenderer::RenderViewpoint and should be merged. - - R_SetupFrame(mainvp, r_viewwindow, camera); - - if (mainview && toscreen) - UpdateShadowMap(); - - // Update the attenuation flag of all light defaults for each viewpoint. - // This function will only do something if the setting differs. - FLightDefaults::SetAttenuationForLevel(!!(camera->Level->flags3 & LEVEL3_ATTENUATE)); - - // Render (potentially) multiple views for stereo 3d - // Fixme. The view offsetting should be done with a static table and not require setup of the entire render state for the mode. - auto vrmode = VRMode::GetVRMode(mainview && toscreen); - for (int eye_ix = 0; eye_ix < vrmode->mEyeCount; ++eye_ix) - { - const auto &eye = vrmode->mEyes[eye_ix]; - screen->SetViewportRects(bounds); - - if (mainview) // Bind the scene frame buffer and turn on draw buffers used by ssao - { - mRenderState->SetRenderTarget(&GetBuffers()->SceneColor, GetBuffers()->SceneDepthStencil.View.get(), GetBuffers()->GetWidth(), GetBuffers()->GetHeight(), VK_FORMAT_R16G16B16A16_SFLOAT, GetBuffers()->GetSceneSamples()); - bool useSSAO = (gl_ssao != 0); - GetRenderState()->SetPassType(useSSAO ? GBUFFER_PASS : NORMAL_PASS); - GetRenderState()->EnableDrawBuffers(GetRenderState()->GetPassDrawBufferCount()); - } - - auto di = HWDrawInfo::StartDrawInfo(mainvp.ViewLevel, nullptr, mainvp, nullptr); - auto &vp = di->Viewpoint; - - di->Set3DViewport(*GetRenderState()); - 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) - - // Stereo mode specific perspective projection - di->VPUniforms.mProjectionMatrix = eye.GetProjection(fov, ratio, fovratio); - // Stereo mode specific viewpoint adjustment - vp.Pos += eye.GetViewShift(vp.HWAngles.Yaw.Degrees); - di->SetupView(*GetRenderState(), vp.Pos.X, vp.Pos.Y, vp.Pos.Z, false, false); - - di->ProcessScene(toscreen); - - if (mainview) - { - PostProcess.Clock(); - if (toscreen) di->EndDrawScene(mainvp.sector, *GetRenderState()); // do not call this for camera textures. - - if (GetRenderState()->GetPassType() == GBUFFER_PASS) // Turn off ssao draw buffers - { - GetRenderState()->SetPassType(NORMAL_PASS); - GetRenderState()->EnableDrawBuffers(1); - } - - mPostprocess->BlitSceneToPostprocess(); // Copy the resulting scene to the current post process texture - - PostProcessScene(cm, [&]() { di->DrawEndScene2D(mainvp.sector, *GetRenderState()); }); - - PostProcess.Unclock(); - } - di->EndDrawInfo(); - -#if 0 - if (vrmode->mEyeCount > 1) - mBuffers->BlitToEyeTexture(eye_ix); -#endif - } - - return mainvp.sector; -} - void VulkanFrameBuffer::RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint, double FOV) { auto BaseLayer = static_cast(tex->GetHardwareTexture(0, 0)); @@ -544,8 +471,9 @@ void VulkanFrameBuffer::RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint tex->SetUpdated(true); } -void VulkanFrameBuffer::PostProcessScene(int fixedcm, const std::function &afterBloomDrawEndScene2D) +void VulkanFrameBuffer::PostProcessScene(bool swscene, int fixedcm, const std::function &afterBloomDrawEndScene2D) { + if (!swscene) mPostprocess->BlitSceneToPostprocess(); // Copy the resulting scene to the current post process texture mPostprocess->PostProcessScene(fixedcm, afterBloomDrawEndScene2D); } @@ -947,3 +875,8 @@ void VulkanFrameBuffer::AmbientOccludeScene(float m5) { mPostprocess->AmbientOccludeScene(m5); } + +void VulkanFrameBuffer::SetSceneRenderTarget(bool useSSAO) +{ + mRenderState->SetRenderTarget(&GetBuffers()->SceneColor, GetBuffers()->SceneDepthStencil.View.get(), GetBuffers()->GetWidth(), GetBuffers()->GetHeight(), VK_FORMAT_R16G16B16A16_SFLOAT, GetBuffers()->GetSceneSamples()); +} diff --git a/src/rendering/vulkan/system/vk_framebuffer.h b/src/rendering/vulkan/system/vk_framebuffer.h index e9b6ac1580..6a1f1697d0 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.h +++ b/src/rendering/vulkan/system/vk_framebuffer.h @@ -87,8 +87,10 @@ public: void StartPrecaching() override; void BeginFrame() override; void BlurScene(float amount) override; - void PostProcessScene(int fixedcm, const std::function &afterBloomDrawEndScene2D) override; + void PostProcessScene(bool swscene, int fixedcm, const std::function &afterBloomDrawEndScene2D) override; void AmbientOccludeScene(float m5) override; + void SetSceneRenderTarget(bool useSSAO) override; + void UpdateShadowMap() override; IHardwareTexture *CreateHardwareTexture() override; FMaterial* CreateMaterial(FGameTexture* tex, int scaleflags) override; @@ -113,12 +115,10 @@ public: void UpdateGpuStats(); private: - sector_t *RenderViewpoint(FRenderViewpoint &mainvp, AActor * camera, IntRect * bounds, float fov, float ratio, float fovratio, bool mainview, bool toscreen); void RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint, double FOV); void PrintStartupLog(); void CreateFanToTrisIndexBuffer(); void CopyScreenToBuffer(int w, int h, void *data); - void UpdateShadowMap(); void DeleteFrameObjects(); void FlushCommands(VulkanCommandBuffer **commands, size_t count, bool finish, bool lastsubmit);