Skip to content

Commit

Permalink
- moved the backend specific ApplySSAO code fragment to the respectiv…
Browse files Browse the repository at this point in the history
…e RenderState objects so that the std::functions could be taken out of the RenderScene interface.
  • Loading branch information
coelckers committed Jun 8, 2019
1 parent 087777e commit 4a9a7ae
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 54 deletions.
1 change: 0 additions & 1 deletion src/rendering/gl/renderer/gl_renderer.h
Expand Up @@ -105,7 +105,6 @@ class FGLRenderer

private:

void DrawScene(HWDrawInfo *di, int drawmode);
bool QuadStereoCheckInitialRenderContextState();
void PresentAnaglyph(bool r, bool g, bool b);
void PresentSideBySide();
Expand Down
11 changes: 11 additions & 0 deletions src/rendering/gl/renderer/gl_renderstate.cpp
Expand Up @@ -525,6 +525,17 @@ void FGLRenderState::EnableLineSmooth(bool on)
ToggleState(GL_LINE_SMOOTH, on);
}

void FGLRenderState::ApplySSAO(float m5, unsigned int vpIndex)
{
EnableDrawBuffers(1);
GLRenderer->AmbientOccludeScene(m5);
glViewport(screen->mSceneViewport.left, screen->mSceneViewport.top, screen->mSceneViewport.width, screen->mSceneViewport.height);
GLRenderer->mBuffers->BindSceneFB(true);
EnableDrawBuffers(GetPassDrawBufferCount());
Apply();
screen->mViewpoints->Bind(*this, vpIndex);
}

//==========================================================================
//
//
Expand Down
1 change: 1 addition & 0 deletions src/rendering/gl/renderer/gl_renderstate.h
Expand Up @@ -139,6 +139,7 @@ class FGLRenderState : public FRenderState
void EnableDepthTest(bool on) override;
void EnableMultisampling(bool on) override;
void EnableLineSmooth(bool on) override;
void ApplySSAO(float m5, unsigned int vpindex) override;


};
Expand Down
27 changes: 1 addition & 26 deletions src/rendering/gl/renderer/gl_scene.cpp
Expand Up @@ -70,29 +70,6 @@ EXTERN_CVAR (Bool, cl_capfps)
namespace OpenGLRenderer
{

//-----------------------------------------------------------------------------
//
// gl_drawscene - this function renders the scene from the current
// viewpoint, including mirrors and skyboxes and other portals
// It is assumed that the HWPortal::EndFrame returns with the
// stencil, z-buffer and the projection matrix intact!
//
//-----------------------------------------------------------------------------

void FGLRenderer::DrawScene(HWDrawInfo *di, int drawmode)
{
di->DoDrawScene(gl_RenderState, drawmode, [&]()
{
gl_RenderState.EnableDrawBuffers(1);
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, di->vpIndex);
});
}

//-----------------------------------------------------------------------------
//
// Renders one viewpoint in a scene
Expand Down Expand Up @@ -145,9 +122,7 @@ sector_t * FGLRenderer::RenderViewpoint (FRenderViewpoint &mainvp, AActor * came
di->SetupView(gl_RenderState, vp.Pos.X, vp.Pos.Y, vp.Pos.Z, false, false);

// std::function until this can be done better in a cross-API fashion.
di->ProcessScene(toscreen, [&](HWDrawInfo *di, int mode) {
DrawScene(di, mode);
});
di->ProcessScene(gl_RenderState, toscreen);

if (mainview)
{
Expand Down
12 changes: 4 additions & 8 deletions src/rendering/hwrenderer/scene/hw_drawinfo.cpp
Expand Up @@ -90,7 +90,6 @@ HWDrawInfo *FDrawInfoList::GetNew()

void FDrawInfoList::Release(HWDrawInfo * di)
{
di->DrawScene = nullptr;
di->ClearBuffers();
di->Level = nullptr;
mList.Push(di);
Expand All @@ -105,7 +104,6 @@ void FDrawInfoList::Release(HWDrawInfo * di)
HWDrawInfo *HWDrawInfo::StartDrawInfo(FLevelLocals *lev, HWDrawInfo *parent, FRenderViewpoint &parentvp, HWViewpointUniforms *uniforms)
{
HWDrawInfo *di = di_list.GetNew();
if (parent) di->DrawScene = parent->DrawScene;
di->Level = lev;
di->StartScene(parentvp, uniforms);
return di;
Expand Down Expand Up @@ -651,7 +649,7 @@ void HWDrawInfo::Set3DViewport(FRenderState &state)
//
//-----------------------------------------------------------------------------

void HWDrawInfo::DoDrawScene(FRenderState &RenderState, int drawmode, const std::function<void()> &ApplySSAO)
void HWDrawInfo::DoDrawScene(FRenderState &RenderState, int drawmode)
{
static int recursion = 0;
static int ssao_portals_available = 0;
Expand Down Expand Up @@ -691,7 +689,7 @@ void HWDrawInfo::DoDrawScene(FRenderState &RenderState, int drawmode, const std:

if (applySSAO && RenderState.GetPassType() == GBUFFER_PASS)
{
ApplySSAO();
RenderState.ApplySSAO(VPUniforms.mProjectionMatrix.get()[5], vpIndex);
}

// Handle all portals after rendering the opaque objects but before
Expand All @@ -709,15 +707,13 @@ void HWDrawInfo::DoDrawScene(FRenderState &RenderState, int drawmode, const std:
//
//-----------------------------------------------------------------------------

void HWDrawInfo::ProcessScene(bool toscreen, const std::function<void(HWDrawInfo *,int)> &drawScene)
void HWDrawInfo::ProcessScene(FRenderState &state, bool toscreen)
{
screen->mPortalState->BeginScene();

int mapsection = Level->PointInRenderSubsector(Viewpoint.Pos)->mapsection;
CurrentMapSections.Set(mapsection);
DrawScene = drawScene;
DrawScene(this, toscreen ? DM_MAINVIEW : DM_OFFSCREEN);

DoDrawScene(state, toscreen ? DM_MAINVIEW : DM_OFFSCREEN);
}

//==========================================================================
Expand Down
6 changes: 2 additions & 4 deletions src/rendering/hwrenderer/scene/hw_drawinfo.h
Expand Up @@ -179,8 +179,6 @@ struct HWDrawInfo
fixed_t viewx, viewy; // since the nodes are still fixed point, keeping the view position also fixed point for node traversal is faster.
bool multithread;

std::function<void(HWDrawInfo *, int)> DrawScene = nullptr;

private:
// For ProcessLowerMiniseg
bool inview;
Expand Down Expand Up @@ -245,7 +243,7 @@ struct HWDrawInfo
HWDrawInfo *EndDrawInfo();
void SetViewArea();
int SetFullbrightFlags(player_t *player);
void HWDrawInfo::DoDrawScene(FRenderState& RenderState, int drawmode, const std::function<void()> &ApplySSAO);
void HWDrawInfo::DoDrawScene(FRenderState& RenderState, int drawmode);

void CreateScene(bool drawpsprites);
void RenderScene(FRenderState &state);
Expand All @@ -254,7 +252,7 @@ struct HWDrawInfo
void EndDrawScene(sector_t * viewsector, FRenderState &state);
void DrawEndScene2D(sector_t * viewsector, FRenderState &state);
void Set3DViewport(FRenderState &state);
void ProcessScene(bool toscreen, const std::function<void(HWDrawInfo *, int)> &drawScene);
void ProcessScene(FRenderState& state, bool toscreen);

bool DoOneSectorUpper(subsector_t * subsec, float planez, area_t in_area);
bool DoOneSectorLower(subsector_t * subsec, float planez, area_t in_area);
Expand Down
2 changes: 1 addition & 1 deletion src/rendering/hwrenderer/scene/hw_portal.h
Expand Up @@ -142,7 +142,7 @@ class HWScenePortalBase : public HWPortal
{
if (Setup(di, state, di->mClipper))
{
di->DrawScene(di, DM_PORTAL);
di->DoDrawScene(state, DM_PORTAL);
Shutdown(di, state);
}
else state.ClearScreen();
Expand Down
1 change: 1 addition & 0 deletions src/rendering/hwrenderer/scene/hw_renderstate.h
Expand Up @@ -614,6 +614,7 @@ class FRenderState
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 ApplySSAO(float m5, unsigned int vpIndex) = 0; // Run the in-scene SSAO pass (this must be here because the render state is the only object connecting the renderer to the backend.)

void SetColorMask(bool on)
{
Expand Down
8 changes: 8 additions & 0 deletions src/rendering/vulkan/renderer/vk_renderstate.cpp
Expand Up @@ -4,6 +4,7 @@
#include "vulkan/system/vk_builders.h"
#include "vulkan/renderer/vk_renderpass.h"
#include "vulkan/renderer/vk_renderbuffers.h"
#include "vulkan/renderer/vk_postprocess.h"
#include "vulkan/textures/vk_hwtexture.h"
#include "templates.h"
#include "doomstat.h"
Expand Down Expand Up @@ -528,6 +529,13 @@ void VkRenderState::EnableDrawBuffers(int count)
}
}

void VkRenderState::ApplySSAO(float m5, unsigned int vpIndex)
{
auto vkfb = static_cast<VulkanFrameBuffer*>(screen);
vkfb->GetPostprocess()->AmbientOccludeScene(m5);
screen->mViewpoints->Bind(*this, vpIndex);
}

void VkRenderState::SetRenderTarget(VulkanImageView *view, VulkanImageView *depthStencilView, int width, int height, VkFormat format, VkSampleCountFlagBits samples)
{
EndRenderPass();
Expand Down
1 change: 1 addition & 0 deletions src/rendering/vulkan/renderer/vk_renderstate.h
Expand Up @@ -41,6 +41,7 @@ class VkRenderState : public FRenderState
void EnableMultisampling(bool on) override;
void EnableLineSmooth(bool on) override;
void EnableDrawBuffers(int count) override;
void ApplySSAO(float m5, unsigned int vpindex) override;

void BeginFrame();
void SetRenderTarget(VulkanImageView *view, VulkanImageView *depthStencilView, int width, int height, VkFormat Format, VkSampleCountFlagBits samples);
Expand Down
14 changes: 1 addition & 13 deletions src/rendering/vulkan/system/vk_framebuffer.cpp
Expand Up @@ -471,10 +471,7 @@ sector_t *VulkanFrameBuffer::RenderViewpoint(FRenderViewpoint &mainvp, AActor *
vp.Pos += eye.GetViewShift(vp.HWAngles.Yaw.Degrees);
di->SetupView(*GetRenderState(), vp.Pos.X, vp.Pos.Y, vp.Pos.Z, false, false);

// std::function until this can be done better in a cross-API fashion.
di->ProcessScene(toscreen, [&](HWDrawInfo *di, int mode) {
DrawScene(di, mode);
});
di->ProcessScene(*GetRenderState(), toscreen);

if (mainview)
{
Expand Down Expand Up @@ -542,15 +539,6 @@ void VulkanFrameBuffer::RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint
tex->SetUpdated(true);
}

void VulkanFrameBuffer::DrawScene(HWDrawInfo *di, int drawmode)
{
di->DoDrawScene(*GetRenderState(), drawmode, [&]
{
mPostprocess->AmbientOccludeScene(di->VPUniforms.mProjectionMatrix.get()[5]);
screen->mViewpoints->Bind(*GetRenderState(), di->vpIndex);
});
}

void VulkanFrameBuffer::PostProcessScene(int fixedcm, const std::function<void()> &afterBloomDrawEndScene2D)
{
mPostprocess->PostProcessScene(fixedcm, afterBloomDrawEndScene2D);
Expand Down
1 change: 0 additions & 1 deletion src/rendering/vulkan/system/vk_framebuffer.h
Expand Up @@ -110,7 +110,6 @@ class VulkanFrameBuffer : public SystemBaseFrameBuffer
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 DrawScene(HWDrawInfo *di, int drawmode);
void PrintStartupLog();
void CreateFanToTrisIndexBuffer();
void CopyScreenToBuffer(int w, int h, void *data);
Expand Down

0 comments on commit 4a9a7ae

Please sign in to comment.