Skip to content
Permalink
Browse files

- consolidated the DrawScene function.

Unfortunately this needs to switch back and forth to the platform backend in order to apply the SSAO so some cleanup is still needed here.
  • Loading branch information...
coelckers committed Jun 8, 2019
1 parent a1a4a7a commit 0248ef2925443c12bc04016f0db40864b57b31cb
@@ -155,6 +155,7 @@ class DHUDMessage : public DHUDMessageBase

};


// HUD message visibility flags
enum
{
@@ -63,15 +63,8 @@
// CVARs
//
//==========================================================================
CVAR(Bool, gl_texture, true, 0)
CVAR(Bool, gl_no_skyclear, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
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
@@ -88,59 +81,16 @@ namespace OpenGLRenderer

void FGLRenderer::DrawScene(HWDrawInfo *di, int drawmode)
{
static int recursion=0;
static int ssao_portals_available = 0;
const auto &vp = di->Viewpoint;

bool applySSAO = false;
if (drawmode == DM_MAINVIEW)
{
ssao_portals_available = gl_ssao_portals;
applySSAO = true;
}
else if (drawmode == DM_OFFSCREEN)
{
ssao_portals_available = 0;
}
else if (drawmode == DM_PORTAL && ssao_portals_available > 0)
{
applySSAO = true;
ssao_portals_available--;
}

if (vp.camera != nullptr)
{
ActorRenderFlags savedflags = vp.camera->renderflags;
di->CreateScene(drawmode == DM_MAINVIEW);
vp.camera->renderflags = savedflags;
}
else
{
di->CreateScene(false);
}

glDepthMask(true);
if (!gl_no_skyclear) screen->mPortalState->RenderFirstSkyPortal(recursion, di, gl_RenderState);

di->RenderScene(gl_RenderState);

if (applySSAO && gl_RenderState.GetPassType() == GBUFFER_PASS)
{
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);
}

// Handle all portals after rendering the opaque objects but before
// doing all translucent stuff
recursion++;
screen->mPortalState->EndFrame(di, gl_RenderState);
recursion--;
di->RenderTranslucent(gl_RenderState);
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);
});
}

//-----------------------------------------------------------------------------
@@ -457,7 +457,7 @@ void HWDrawInfo::CreateScene(bool drawpsprites)
//
// RenderScene
//
// Draws the current draw lists for the non GLSL renderer
// Draws the current draw lists
//
//-----------------------------------------------------------------------------

@@ -642,6 +642,67 @@ void HWDrawInfo::Set3DViewport(FRenderState &state)
state.SetStencil(0, SOP_Keep, SF_AllOn);
}

//-----------------------------------------------------------------------------
//
// 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 HWDrawInfo::DoDrawScene(FRenderState &RenderState, int drawmode, const std::function<void()> &ApplySSAO)
{
static int recursion = 0;
static int ssao_portals_available = 0;
const auto& vp = Viewpoint;

bool applySSAO = false;
if (drawmode == DM_MAINVIEW)
{
ssao_portals_available = gl_ssao_portals;
applySSAO = true;
}
else if (drawmode == DM_OFFSCREEN)
{
ssao_portals_available = 0;
}
else if (drawmode == DM_PORTAL && ssao_portals_available > 0)
{
applySSAO = true;
ssao_portals_available--;
}

if (vp.camera != nullptr)
{
ActorRenderFlags savedflags = vp.camera->renderflags;
CreateScene(drawmode == DM_MAINVIEW);
vp.camera->renderflags = savedflags;
}
else
{
CreateScene(false);
}

RenderState.SetDepthMask(true);
if (!gl_no_skyclear) screen->mPortalState->RenderFirstSkyPortal(recursion, this, RenderState);

RenderScene(RenderState);

if (applySSAO && RenderState.GetPassType() == GBUFFER_PASS)
{
ApplySSAO();
}

// Handle all portals after rendering the opaque objects but before
// doing all translucent stuff
recursion++;
screen->mPortalState->EndFrame(this, RenderState);
recursion--;
RenderTranslucent(RenderState);
}


//-----------------------------------------------------------------------------
//
// R_RenderView - renders one view - either the screen or a camera texture
@@ -245,6 +245,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 CreateScene(bool drawpsprites);
void RenderScene(FRenderState &state);
@@ -76,7 +76,7 @@ void HWDrawInfo::AddWall(HWWall *wall)
}
else
{
auto newwall = drawlists[list].NewWall();
newwall = drawlists[list].NewWall();
}
}
*newwall = *wall;
@@ -112,3 +112,8 @@ CUSTOM_CVAR(Int, gl_shadowmap_filter, 1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
{
if (self < 0 || self > 8) self = 1;
}

CVAR(Bool, gl_texture, true, 0)
CVAR(Bool, gl_no_skyclear, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
CVAR(Float, gl_mask_threshold, 0.5f, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
CVAR(Float, gl_mask_sprite_threshold, 0.5f, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
@@ -71,3 +71,8 @@ EXTERN_CVAR(Int, gl_shadowmap_filter)
EXTERN_CVAR(Bool, gl_brightfog)
EXTERN_CVAR(Bool, gl_lightadditivesurfaces)
EXTERN_CVAR(Bool, gl_notexturefill)

EXTERN_CVAR(Bool, gl_texture)
EXTERN_CVAR(Bool, gl_no_skyclear)
EXTERN_CVAR(Float, gl_mask_threshold)
EXTERN_CVAR(Float, gl_mask_sprite_threshold)
@@ -544,56 +544,11 @@ void VulkanFrameBuffer::RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint

void VulkanFrameBuffer::DrawScene(HWDrawInfo *di, int drawmode)
{
// To do: this is virtually identical to FGLRenderer::DrawScene and should be merged.

static int recursion = 0;
static int ssao_portals_available = 0;
const auto &vp = di->Viewpoint;

bool applySSAO = false;
if (drawmode == DM_MAINVIEW)
{
ssao_portals_available = gl_ssao_portals;
applySSAO = true;
}
else if (drawmode == DM_OFFSCREEN)
{
ssao_portals_available = 0;
}
else if (drawmode == DM_PORTAL && ssao_portals_available > 0)
{
applySSAO = true;
ssao_portals_available--;
}

if (vp.camera != nullptr)
{
ActorRenderFlags savedflags = vp.camera->renderflags;
di->CreateScene(drawmode == DM_MAINVIEW);
vp.camera->renderflags = savedflags;
}
else
{
di->CreateScene(false);
}

GetRenderState()->SetDepthMask(true);
if (!gl_no_skyclear) screen->mPortalState->RenderFirstSkyPortal(recursion, di, *GetRenderState());

di->RenderScene(*GetRenderState());

if (applySSAO && GetRenderState()->GetPassType() == GBUFFER_PASS)
{
mPostprocess->AmbientOccludeScene(di->VPUniforms.mProjectionMatrix.get()[5]);
screen->mViewpoints->Bind(*GetRenderState(), di->vpIndex);
}

// Handle all portals after rendering the opaque objects but before
// doing all translucent stuff
recursion++;
screen->mPortalState->EndFrame(di, *GetRenderState());
recursion--;
di->RenderTranslucent(*GetRenderState());
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)

0 comments on commit 0248ef2

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