Skip to content
Permalink
Browse files

- moved the backend specific ApplySSAO code fragment to the respectiv…

…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 4a9a7aebccc8662ee6e80b0ed7c4404bac7283da
@@ -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();
@@ -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);
}

//==========================================================================
//
//
@@ -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;


};
@@ -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
@@ -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)
{
@@ -90,7 +90,6 @@ HWDrawInfo *FDrawInfoList::GetNew()

void FDrawInfoList::Release(HWDrawInfo * di)
{
di->DrawScene = nullptr;
di->ClearBuffers();
di->Level = nullptr;
mList.Push(di);
@@ -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;
@@ -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;
@@ -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
@@ -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);
}

//==========================================================================
@@ -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;
@@ -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);
@@ -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);
@@ -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();
@@ -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)
{
@@ -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"
@@ -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();
@@ -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);
@@ -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)
{
@@ -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);
@@ -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);

0 comments on commit 4a9a7ae

Please sign in to comment.
You can’t perform that action at this time.