- moved DrawScene to GLRenderer and call it through std::function.

This was the last remaining virtual override of HWDrawInfo.
With it removed this type is now fully API independent.
This commit is contained in:
Christoph Oelckers 2018-10-29 12:54:10 +01:00
parent 325d2126ec
commit 893e08df70
9 changed files with 28 additions and 31 deletions

View File

@ -19,7 +19,6 @@ class FCanvasTexture;
class FFlatVertexBuffer; class FFlatVertexBuffer;
class FSkyVertexBuffer; class FSkyVertexBuffer;
class OpenGLFrameBuffer; class OpenGLFrameBuffer;
struct FDrawInfo;
class FShaderManager; class FShaderManager;
class HWPortal; class HWPortal;
class FLightBuffer; class FLightBuffer;
@ -105,6 +104,7 @@ 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

@ -1,3 +1,4 @@
/*
#ifndef __GL_DRAWINFO_H #ifndef __GL_DRAWINFO_H
#define __GL_DRAWINFO_H #define __GL_DRAWINFO_H
@ -13,6 +14,6 @@
struct FDrawInfo : public HWDrawInfo struct FDrawInfo : public HWDrawInfo
{ {
void DrawScene(int drawmode) override;
}; };
#endif #endif
*/

View File

@ -83,11 +83,11 @@ EXTERN_CVAR (Bool, r_drawvoxels)
// //
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void FDrawInfo::DrawScene(int drawmode) void FGLRenderer::DrawScene(HWDrawInfo *di, int drawmode)
{ {
static int recursion=0; static int recursion=0;
static int ssao_portals_available = 0; static int ssao_portals_available = 0;
const auto &vp = Viewpoint; const auto &vp = di->Viewpoint;
bool applySSAO = false; bool applySSAO = false;
if (drawmode == DM_MAINVIEW) if (drawmode == DM_MAINVIEW)
@ -108,36 +108,36 @@ void FDrawInfo::DrawScene(int drawmode)
if (vp.camera != nullptr) if (vp.camera != nullptr)
{ {
ActorRenderFlags savedflags = vp.camera->renderflags; ActorRenderFlags savedflags = vp.camera->renderflags;
CreateScene(); di->CreateScene();
vp.camera->renderflags = savedflags; vp.camera->renderflags = savedflags;
} }
else else
{ {
CreateScene(); di->CreateScene();
} }
glDepthMask(true); glDepthMask(true);
if (!gl_no_skyclear) screen->mPortalState->RenderFirstSkyPortal(recursion, this, gl_RenderState); if (!gl_no_skyclear) screen->mPortalState->RenderFirstSkyPortal(recursion, di, gl_RenderState);
RenderScene(gl_RenderState); di->RenderScene(gl_RenderState);
if (applySSAO && gl_RenderState.GetPassType() == GBUFFER_PASS) if (applySSAO && gl_RenderState.GetPassType() == GBUFFER_PASS)
{ {
gl_RenderState.EnableDrawBuffers(1); gl_RenderState.EnableDrawBuffers(1);
GLRenderer->AmbientOccludeScene(VPUniforms.mProjectionMatrix.get()[5]); GLRenderer->AmbientOccludeScene(di->VPUniforms.mProjectionMatrix.get()[5]);
glViewport(screen->mSceneViewport.left, screen->mSceneViewport.top, screen->mSceneViewport.width, screen->mSceneViewport.height); glViewport(screen->mSceneViewport.left, screen->mSceneViewport.top, screen->mSceneViewport.width, screen->mSceneViewport.height);
GLRenderer->mBuffers->BindSceneFB(true); GLRenderer->mBuffers->BindSceneFB(true);
gl_RenderState.EnableDrawBuffers(gl_RenderState.GetPassDrawBufferCount()); gl_RenderState.EnableDrawBuffers(gl_RenderState.GetPassDrawBufferCount());
gl_RenderState.Apply(); gl_RenderState.Apply();
screen->mViewpoints->Bind(gl_RenderState, vpIndex); screen->mViewpoints->Bind(gl_RenderState, di->vpIndex);
} }
// Handle all portals after rendering the opaque objects but before // Handle all portals after rendering the opaque objects but before
// doing all translucent stuff // doing all translucent stuff
recursion++; recursion++;
screen->mPortalState->EndFrame(this, gl_RenderState); screen->mPortalState->EndFrame(di, gl_RenderState);
recursion--; recursion--;
RenderTranslucent(gl_RenderState); di->RenderTranslucent(gl_RenderState);
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -170,7 +170,7 @@ sector_t * FGLRenderer::RenderViewpoint (FRenderViewpoint &mainvp, AActor * came
} }
FDrawInfo *di = static_cast<FDrawInfo*>(HWDrawInfo::StartDrawInfo(nullptr, mainvp, nullptr)); auto di = HWDrawInfo::StartDrawInfo(nullptr, mainvp, nullptr);
auto &vp = di->Viewpoint; auto &vp = di->Viewpoint;
di->Set3DViewport(gl_RenderState); di->Set3DViewport(gl_RenderState);
@ -184,7 +184,10 @@ 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);
di->ProcessScene(toscreen); // std::function until this can be done better in a cross-API fashion.
di->ProcessScene(toscreen, [&](HWDrawInfo *di, int mode) {
DrawScene(di, mode);
});
if (mainview) if (mainview)
{ {

View File

@ -379,11 +379,6 @@ IDataBuffer *OpenGLFrameBuffer::CreateDataBuffer(int bindingpoint, bool ssbo)
return new GLDataBuffer(bindingpoint, ssbo); return new GLDataBuffer(bindingpoint, ssbo);
} }
HWDrawInfo *OpenGLFrameBuffer::CreateDrawInfo()
{
return new FDrawInfo;
}
void OpenGLFrameBuffer::TextureFilterChanged() void OpenGLFrameBuffer::TextureFilterChanged()
{ {
if (GLRenderer != NULL && GLRenderer->mSamplerManager != NULL) GLRenderer->mSamplerManager->SetTextureFilterMode(); if (GLRenderer != NULL && GLRenderer->mSamplerManager != NULL) GLRenderer->mSamplerManager->SetTextureFilterMode();

View File

@ -43,7 +43,6 @@ public:
IVertexBuffer *CreateVertexBuffer() override; IVertexBuffer *CreateVertexBuffer() override;
IIndexBuffer *CreateIndexBuffer() override; IIndexBuffer *CreateIndexBuffer() override;
IDataBuffer *CreateDataBuffer(int bindingpoint, bool ssbo) override; IDataBuffer *CreateDataBuffer(int bindingpoint, bool ssbo) override;
HWDrawInfo *CreateDrawInfo() override;
// Retrieves a buffer containing image data for a screenshot. // Retrieves a buffer containing image data for a screenshot.
// Hint: Pitch can be negative for upside-down images, in which case buffer // Hint: Pitch can be negative for upside-down images, in which case buffer

View File

@ -97,11 +97,12 @@ HWDrawInfo *FDrawInfoList::GetNew()
mList.Pop(di); mList.Pop(di);
return di; return di;
} }
return screen->CreateDrawInfo(); return new HWDrawInfo;
} }
void FDrawInfoList::Release(HWDrawInfo * di) void FDrawInfoList::Release(HWDrawInfo * di)
{ {
di->DrawScene = nullptr;
di->ClearBuffers(); di->ClearBuffers();
mList.Push(di); mList.Push(di);
} }
@ -115,6 +116,7 @@ void FDrawInfoList::Release(HWDrawInfo * di)
HWDrawInfo *HWDrawInfo::StartDrawInfo(HWDrawInfo *parent, FRenderViewpoint &parentvp, HWViewpointUniforms *uniforms) HWDrawInfo *HWDrawInfo::StartDrawInfo(HWDrawInfo *parent, FRenderViewpoint &parentvp, HWViewpointUniforms *uniforms)
{ {
HWDrawInfo *di = di_list.GetNew(); HWDrawInfo *di = di_list.GetNew();
if (parent) di->DrawScene = parent->DrawScene;
di->StartScene(parentvp, uniforms); di->StartScene(parentvp, uniforms);
return di; return di;
} }
@ -674,14 +676,13 @@ void HWDrawInfo::Set3DViewport(FRenderState &state)
// //
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void HWDrawInfo::ProcessScene(bool toscreen) void HWDrawInfo::ProcessScene(bool toscreen, const std::function<void(HWDrawInfo *,int)> &drawScene)
{ {
screen->mPortalState->BeginScene(); screen->mPortalState->BeginScene();
int mapsection = R_PointInSubsector(Viewpoint.Pos)->mapsection; int mapsection = R_PointInSubsector(Viewpoint.Pos)->mapsection;
CurrentMapSections.Set(mapsection); CurrentMapSections.Set(mapsection);
DrawScene(toscreen ? DM_MAINVIEW : DM_OFFSCREEN); DrawScene = drawScene;
DrawScene(this, toscreen ? DM_MAINVIEW : DM_OFFSCREEN);
} }

View File

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <atomic> #include <atomic>
#include <functional>
#include "vectors.h" #include "vectors.h"
#include "r_defs.h" #include "r_defs.h"
#include "r_utility.h" #include "r_utility.h"
@ -178,6 +179,7 @@ struct HWDrawInfo
area_t in_area; area_t in_area;
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.
std::function<void(HWDrawInfo *, int)> DrawScene = nullptr;
private: private:
// For ProcessLowerMiniseg // For ProcessLowerMiniseg
@ -190,7 +192,6 @@ private:
sector_t fakesec; // this is a struct member because it gets used in recursively called functions so it cannot be put on the stack. sector_t fakesec; // this is a struct member because it gets used in recursively called functions so it cannot be put on the stack.
void UnclipSubsector(subsector_t *sub); void UnclipSubsector(subsector_t *sub);
void AddLine(seg_t *seg, bool portalclip); void AddLine(seg_t *seg, bool portalclip);
void PolySubsector(subsector_t * sub); void PolySubsector(subsector_t * sub);
@ -271,7 +272,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); void ProcessScene(bool toscreen, const std::function<void(HWDrawInfo *, int)> &drawScene);
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);
@ -329,7 +330,5 @@ public:
GLDecal *AddDecal(bool onmirror); GLDecal *AddDecal(bool onmirror);
virtual void DrawScene(int drawmode) = 0;
}; };

View File

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

View File

@ -469,7 +469,6 @@ public:
virtual IVertexBuffer *CreateVertexBuffer() { return nullptr; } virtual IVertexBuffer *CreateVertexBuffer() { return nullptr; }
virtual IIndexBuffer *CreateIndexBuffer() { return nullptr; } virtual IIndexBuffer *CreateIndexBuffer() { return nullptr; }
virtual IDataBuffer *CreateDataBuffer(int bindingpoint, bool ssbo) { return nullptr; } virtual IDataBuffer *CreateDataBuffer(int bindingpoint, bool ssbo) { return nullptr; }
virtual HWDrawInfo *CreateDrawInfo() { return nullptr; }
bool BuffersArePersistent() { return !!(hwcaps & RFL_BUFFER_STORAGE); } bool BuffersArePersistent() { return !!(hwcaps & RFL_BUFFER_STORAGE); }
// Begin/End 2D drawing operations. // Begin/End 2D drawing operations.