- consolidated the 3 virtually identical instances of DrawScene and moved the function to HWDrawInfo.

The only backend dependent call in there, ambient occlusion, has been made a virtual of DFrameBuffer.
This commit is contained in:
Christoph Oelckers 2020-04-24 21:47:18 +02:00
parent 90585c4931
commit c203df5edb
12 changed files with 96 additions and 201 deletions

View file

@ -102,7 +102,6 @@ public:
private: private:
void DrawScene(HWDrawInfo *di, int drawmode);
bool QuadStereoCheckInitialRenderContextState(); bool QuadStereoCheckInitialRenderContextState();
void PresentAnaglyph(bool r, bool g, bool b); void PresentAnaglyph(bool r, bool g, bool b);
void PresentSideBySide(); void PresentSideBySide();

View file

@ -65,7 +65,6 @@
// //
//========================================================================== //==========================================================================
CVAR(Bool, gl_texture, true, 0) 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_threshold, 0.5f,CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
CVAR(Float, gl_mask_sprite_threshold, 0.5f,CVAR_ARCHIVE|CVAR_GLOBALCONFIG) CVAR(Float, gl_mask_sprite_threshold, 0.5f,CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
@ -78,72 +77,6 @@ EXTERN_CVAR (Bool, r_drawvoxels)
namespace OpenGLRenderer 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)
{
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);
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// //
// Renders one viewpoint in a scene // Renders one viewpoint in a scene
@ -195,10 +128,7 @@ sector_t * FGLRenderer::RenderViewpoint (FRenderViewpoint &mainvp, AActor * came
vp.Pos += eye.GetViewShift(vp.HWAngles.Yaw.Degrees); 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(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);
di->ProcessScene(toscreen, [&](HWDrawInfo *di, int mode) {
DrawScene(di, mode);
});
if (mainview) if (mainview)
{ {

View file

@ -519,6 +519,16 @@ FRenderState* OpenGLFrameBuffer::RenderState()
return &gl_RenderState; return &gl_RenderState;
} }
void OpenGLFrameBuffer::AmbientOccludeScene(float m5)
{
gl_RenderState.EnableDrawBuffers(1);
GLRenderer->AmbientOccludeScene(m5);
glViewport(screen->mSceneViewport.left, mSceneViewport.top, mSceneViewport.width, mSceneViewport.height);
GLRenderer->mBuffers->BindSceneFB(true);
gl_RenderState.EnableDrawBuffers(gl_RenderState.GetPassDrawBufferCount());
gl_RenderState.Apply();
}
//=========================================================================== //===========================================================================
// //

View file

@ -27,6 +27,7 @@ public:
void InitializeState() override; void InitializeState() override;
void Update() override; void Update() override;
void AmbientOccludeScene(float m5) override;
FRenderState* RenderState() override; FRenderState* RenderState() override;
void CleanForRestart() override; void CleanForRestart() override;
void UpdatePalette() override; void UpdatePalette() override;

View file

@ -47,6 +47,7 @@
EXTERN_CVAR(Float, r_visibility) EXTERN_CVAR(Float, r_visibility)
CVAR(Bool, gl_bandedswlight, false, CVAR_ARCHIVE) CVAR(Bool, gl_bandedswlight, false, CVAR_ARCHIVE)
CVAR(Bool, gl_sort_textures, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) CVAR(Bool, gl_sort_textures, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
CVAR(Bool, gl_no_skyclear, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
sector_t * hw_FakeFlat(sector_t * sec, sector_t * dest, area_t in_area, bool back); sector_t * hw_FakeFlat(sector_t * sec, sector_t * dest, area_t in_area, bool back);
@ -90,7 +91,6 @@ HWDrawInfo *FDrawInfoList::GetNew()
void FDrawInfoList::Release(HWDrawInfo * di) void FDrawInfoList::Release(HWDrawInfo * di)
{ {
di->DrawScene = nullptr;
di->ClearBuffers(); di->ClearBuffers();
di->Level = nullptr; di->Level = nullptr;
mList.Push(di); mList.Push(di);
@ -105,7 +105,6 @@ void FDrawInfoList::Release(HWDrawInfo * di)
HWDrawInfo *HWDrawInfo::StartDrawInfo(FLevelLocals *lev, HWDrawInfo *parent, FRenderViewpoint &parentvp, HWViewpointUniforms *uniforms) HWDrawInfo *HWDrawInfo::StartDrawInfo(FLevelLocals *lev, HWDrawInfo *parent, FRenderViewpoint &parentvp, HWViewpointUniforms *uniforms)
{ {
HWDrawInfo *di = di_list.GetNew(); HWDrawInfo *di = di_list.GetNew();
if (parent) di->DrawScene = parent->DrawScene;
di->Level = lev; di->Level = lev;
di->StartScene(parentvp, uniforms); di->StartScene(parentvp, uniforms);
return di; return di;
@ -642,20 +641,82 @@ void HWDrawInfo::Set3DViewport(FRenderState &state)
state.SetStencil(0, SOP_Keep, SF_AllOn); 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::DrawScene(int drawmode)
{
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);
}
auto& RenderState = *screen->RenderState();
RenderState.SetDepthMask(true);
if (!gl_no_skyclear) screen->mPortalState->RenderFirstSkyPortal(recursion, this, RenderState);
RenderScene(RenderState);
if (applySSAO && RenderState.GetPassType() == GBUFFER_PASS)
{
screen->AmbientOccludeScene(VPUniforms.mProjectionMatrix.get()[5]);
screen->mViewpoints->Bind(RenderState, vpIndex);
}
// 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 // R_RenderView - renders one view - either the screen or a camera texture
// //
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void HWDrawInfo::ProcessScene(bool toscreen, const std::function<void(HWDrawInfo *,int)> &drawScene) void HWDrawInfo::ProcessScene(bool toscreen)
{ {
screen->mPortalState->BeginScene(); screen->mPortalState->BeginScene();
int mapsection = Level->PointInRenderSubsector(Viewpoint.Pos)->mapsection; int mapsection = Level->PointInRenderSubsector(Viewpoint.Pos)->mapsection;
CurrentMapSections.Set(mapsection); CurrentMapSections.Set(mapsection);
DrawScene = drawScene; DrawScene(toscreen ? DM_MAINVIEW : DM_OFFSCREEN);
DrawScene(this, toscreen ? DM_MAINVIEW : DM_OFFSCREEN);
} }

View file

@ -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. 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; bool multithread;
std::function<void(HWDrawInfo *, int)> DrawScene = nullptr;
private: private:
// For ProcessLowerMiniseg // For ProcessLowerMiniseg
bool inview; bool inview;
@ -246,6 +244,7 @@ public:
void SetViewArea(); void SetViewArea();
int SetFullbrightFlags(player_t *player); int SetFullbrightFlags(player_t *player);
void DrawScene(int drawmode);
void CreateScene(bool drawpsprites); void CreateScene(bool drawpsprites);
void RenderScene(FRenderState &state); void RenderScene(FRenderState &state);
void RenderTranslucent(FRenderState &state); void RenderTranslucent(FRenderState &state);
@ -253,7 +252,7 @@ public:
void EndDrawScene(sector_t * viewsector, FRenderState &state); void EndDrawScene(sector_t * viewsector, FRenderState &state);
void DrawEndScene2D(sector_t * viewsector, FRenderState &state); void DrawEndScene2D(sector_t * viewsector, FRenderState &state);
void Set3DViewport(FRenderState &state); void Set3DViewport(FRenderState &state);
void ProcessScene(bool toscreen, const std::function<void(HWDrawInfo *, int)> &drawScene); void ProcessScene(bool toscreen);
bool DoOneSectorUpper(subsector_t * subsec, float planez, area_t in_area); bool DoOneSectorUpper(subsector_t * subsec, float planez, area_t in_area);
bool DoOneSectorLower(subsector_t * subsec, float planez, area_t in_area); bool DoOneSectorLower(subsector_t * subsec, float planez, area_t in_area);

View file

@ -143,7 +143,7 @@ public:
{ {
if (Setup(di, state, di->mClipper)) if (Setup(di, state, di->mClipper))
{ {
di->DrawScene(di, DM_PORTAL); di->DrawScene(DM_PORTAL);
Shutdown(di, state); Shutdown(di, state);
} }
else state.ClearScreen(); else state.ClearScreen();

View file

@ -59,7 +59,6 @@ EXTERN_CVAR(Bool, r_drawvoxels)
EXTERN_CVAR(Int, gl_tonemap) EXTERN_CVAR(Int, gl_tonemap)
EXTERN_CVAR(Int, screenblocks) EXTERN_CVAR(Int, screenblocks)
EXTERN_CVAR(Bool, cl_capfps) EXTERN_CVAR(Bool, cl_capfps)
EXTERN_CVAR(Bool, gl_no_skyclear)
extern bool NoInterpolateView; extern bool NoInterpolateView;
extern int rendered_commandbuffers; extern int rendered_commandbuffers;
@ -340,10 +339,7 @@ sector_t *PolyFrameBuffer::RenderViewpoint(FRenderViewpoint &mainvp, AActor * ca
vp.Pos += eye.GetViewShift(vp.HWAngles.Yaw.Degrees); vp.Pos += eye.GetViewShift(vp.HWAngles.Yaw.Degrees);
di->SetupView(*GetRenderState(), vp.Pos.X, vp.Pos.Y, vp.Pos.Z, false, false); 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);
di->ProcessScene(toscreen, [&](HWDrawInfo *di, int mode) {
DrawScene(di, mode);
});
if (mainview) if (mainview)
{ {
@ -398,60 +394,6 @@ void PolyFrameBuffer::RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint,
tex->SetUpdated(true); tex->SetUpdated(true);
} }
void PolyFrameBuffer::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) mPortalState->RenderFirstSkyPortal(recursion, di, *GetRenderState());
di->RenderScene(*GetRenderState());
if (applySSAO && GetRenderState()->GetPassType() == GBUFFER_PASS)
{
//mPostprocess->AmbientOccludeScene(di->VPUniforms.mProjectionMatrix.get()[5]);
//mViewpoints->Bind(*GetRenderState(), di->vpIndex);
}
// Handle all portals after rendering the opaque objects but before
// doing all translucent stuff
recursion++;
mPortalState->EndFrame(di, *GetRenderState());
recursion--;
di->RenderTranslucent(*GetRenderState());
}
static uint8_t ToIntColorComponent(float v) static uint8_t ToIntColorComponent(float v)
{ {
return clamp((int)(v * 255.0f + 0.5f), 0, 255); return clamp((int)(v * 255.0f + 0.5f), 0, 255);
@ -678,3 +620,8 @@ unsigned int PolyFrameBuffer::GetLightBufferBlockSize() const
void PolyFrameBuffer::UpdateShadowMap() void PolyFrameBuffer::UpdateShadowMap()
{ {
} }
void PolyFrameBuffer::AmbientOccludeScene(float m5)
{
//mPostprocess->AmbientOccludeScene(m5);
}

View file

@ -47,6 +47,7 @@ public:
void BeginFrame() override; void BeginFrame() override;
void BlurScene(float amount) override; void BlurScene(float amount) override;
void PostProcessScene(int fixedcm, const std::function<void()> &afterBloomDrawEndScene2D) override; void PostProcessScene(int fixedcm, const std::function<void()> &afterBloomDrawEndScene2D) override;
void AmbientOccludeScene(float m5) override;
IHardwareTexture *CreateHardwareTexture() override; IHardwareTexture *CreateHardwareTexture() override;
FModelRenderer *CreateModelRenderer(int mli) override; FModelRenderer *CreateModelRenderer(int mli) override;
@ -71,7 +72,6 @@ public:
private: private:
sector_t *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);
void RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint, double FOV); void RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint, double FOV);
void DrawScene(HWDrawInfo *di, int drawmode);
void UpdateShadowMap(); void UpdateShadowMap();
void CheckCanvas(); void CheckCanvas();

View file

@ -311,6 +311,7 @@ public:
virtual const char* DeviceName() const { return "Unknown"; } virtual const char* DeviceName() const { return "Unknown"; }
virtual void WriteSavePic(player_t *player, FileWriter *file, int width, int height); virtual void WriteSavePic(player_t *player, FileWriter *file, int width, int height);
virtual sector_t *RenderView(player_t *player) { return nullptr; } virtual sector_t *RenderView(player_t *player) { return nullptr; }
virtual void AmbientOccludeScene(float m5) {}
// Screen wiping // Screen wiping
virtual FTexture *WipeStartScreen(); virtual FTexture *WipeStartScreen();

View file

@ -67,7 +67,6 @@ EXTERN_CVAR(Bool, r_drawvoxels)
EXTERN_CVAR(Int, gl_tonemap) EXTERN_CVAR(Int, gl_tonemap)
EXTERN_CVAR(Int, screenblocks) EXTERN_CVAR(Int, screenblocks)
EXTERN_CVAR(Bool, cl_capfps) EXTERN_CVAR(Bool, cl_capfps)
EXTERN_CVAR(Bool, gl_no_skyclear)
extern bool NoInterpolateView; extern bool NoInterpolateView;
extern int rendered_commandbuffers; extern int rendered_commandbuffers;
@ -480,10 +479,7 @@ sector_t *VulkanFrameBuffer::RenderViewpoint(FRenderViewpoint &mainvp, AActor *
vp.Pos += eye.GetViewShift(vp.HWAngles.Yaw.Degrees); vp.Pos += eye.GetViewShift(vp.HWAngles.Yaw.Degrees);
di->SetupView(*GetRenderState(), vp.Pos.X, vp.Pos.Y, vp.Pos.Z, false, false); 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);
di->ProcessScene(toscreen, [&](HWDrawInfo *di, int mode) {
DrawScene(di, mode);
});
if (mainview) if (mainview)
{ {
@ -548,60 +544,6 @@ void VulkanFrameBuffer::RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint
tex->SetUpdated(true); tex->SetUpdated(true);
} }
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) 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());
}
void VulkanFrameBuffer::PostProcessScene(int fixedcm, const std::function<void()> &afterBloomDrawEndScene2D) void VulkanFrameBuffer::PostProcessScene(int fixedcm, const std::function<void()> &afterBloomDrawEndScene2D)
{ {
mPostprocess->PostProcessScene(fixedcm, afterBloomDrawEndScene2D); mPostprocess->PostProcessScene(fixedcm, afterBloomDrawEndScene2D);
@ -1000,3 +942,8 @@ FRenderState* VulkanFrameBuffer::RenderState()
{ {
return mRenderState.get(); return mRenderState.get();
} }
void VulkanFrameBuffer::AmbientOccludeScene(float m5)
{
mPostprocess->AmbientOccludeScene(m5);
}

View file

@ -88,6 +88,7 @@ public:
void BeginFrame() override; void BeginFrame() override;
void BlurScene(float amount) override; void BlurScene(float amount) override;
void PostProcessScene(int fixedcm, const std::function<void()> &afterBloomDrawEndScene2D) override; void PostProcessScene(int fixedcm, const std::function<void()> &afterBloomDrawEndScene2D) override;
void AmbientOccludeScene(float m5) override;
IHardwareTexture *CreateHardwareTexture() override; IHardwareTexture *CreateHardwareTexture() override;
FMaterial* CreateMaterial(FGameTexture* tex, int scaleflags) override; FMaterial* CreateMaterial(FGameTexture* tex, int scaleflags) override;
@ -114,7 +115,6 @@ public:
private: private:
sector_t *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);
void RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint, double FOV); void RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint, double FOV);
void DrawScene(HWDrawInfo *di, int drawmode);
void PrintStartupLog(); void PrintStartupLog();
void CreateFanToTrisIndexBuffer(); void CreateFanToTrisIndexBuffer();
void CopyScreenToBuffer(int w, int h, void *data); void CopyScreenToBuffer(int w, int h, void *data);