From 2ee2766812297de4f136a634e52f4bccfd0a602a Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 28 Oct 2018 19:39:31 +0100 Subject: [PATCH] - moved more code from FDrawInfo to HWDrawInfo. The entire setup/takedown code did not reference any API specific data. The only thing needed is a global virtual creation function. --- src/gl/scene/gl_drawinfo.cpp | 79 ------------------------ src/gl/scene/gl_drawinfo.h | 3 - src/gl/scene/gl_scene.cpp | 2 +- src/gl/system/gl_framebuffer.cpp | 5 ++ src/gl/system/gl_framebuffer.h | 1 + src/hwrenderer/scene/hw_drawinfo.cpp | 92 ++++++++++++++++++++++++++++ src/hwrenderer/scene/hw_drawinfo.h | 2 + src/v_video.h | 2 + 8 files changed, 103 insertions(+), 83 deletions(-) diff --git a/src/gl/scene/gl_drawinfo.cpp b/src/gl/scene/gl_drawinfo.cpp index 615699ad6..db01ed6fc 100644 --- a/src/gl/scene/gl_drawinfo.cpp +++ b/src/gl/scene/gl_drawinfo.cpp @@ -45,85 +45,6 @@ #include "hwrenderer/dynlights/hw_lightbuffer.h" #include "hwrenderer/models/hw_models.h" -class FDrawInfoList -{ -public: - TDeletingArray mList; - - - FDrawInfo * GetNew(); - void Release(FDrawInfo *); -}; - - -static FDrawInfo * gl_drawinfo; -FDrawInfoList di_list; - -//========================================================================== -// -// Try to reuse the lists as often as possible as they contain resources that -// are expensive to create and delete. -// -// Note: If multithreading gets used, this class needs synchronization. -// -//========================================================================== - -FDrawInfo *FDrawInfoList::GetNew() -{ - if (mList.Size() > 0) - { - FDrawInfo *di; - mList.Pop(di); - return di; - } - return new FDrawInfo; -} - -void FDrawInfoList::Release(FDrawInfo * di) -{ - di->ClearBuffers(); - mList.Push(di); -} - -//========================================================================== -// -// Sets up a new drawinfo struct -// -//========================================================================== - -// OpenGL has no use for multiple clippers so use the same one for all DrawInfos. -static Clipper staticClipper; - -FDrawInfo *FDrawInfo::StartDrawInfo(FRenderViewpoint &parentvp, HWViewpointUniforms *uniforms) -{ - FDrawInfo *di=di_list.GetNew(); - staticClipper.Clear(); - di->mClipper = &staticClipper; - - di->StartScene(parentvp, uniforms); - - di->outer = gl_drawinfo; - gl_drawinfo = di; - - return di; -} - -//========================================================================== -// -// -// -//========================================================================== -FDrawInfo *FDrawInfo::EndDrawInfo() -{ - assert(this == gl_drawinfo); - for(int i=0;i(outer); - di_list.Release(this); - if (gl_drawinfo == nullptr) - ResetRenderDataAllocator(); - return gl_drawinfo; -} - bool FDrawInfo::SetDepthClamp(bool on) { return gl_RenderState.SetDepthClamp(on); diff --git a/src/gl/scene/gl_drawinfo.h b/src/gl/scene/gl_drawinfo.h index 37b68c0fe..8ebf3142c 100644 --- a/src/gl/scene/gl_drawinfo.h +++ b/src/gl/scene/gl_drawinfo.h @@ -35,8 +35,5 @@ struct FDrawInfo : public HWDrawInfo void DrawEndScene2D(sector_t * viewsector); bool SetDepthClamp(bool on) override; void ClearScreen() override; - - static FDrawInfo *StartDrawInfo(FRenderViewpoint &parentvp, HWViewpointUniforms *uniforms); - FDrawInfo *EndDrawInfo(); }; #endif diff --git a/src/gl/scene/gl_scene.cpp b/src/gl/scene/gl_scene.cpp index 45fde2ad1..d462360b1 100644 --- a/src/gl/scene/gl_scene.cpp +++ b/src/gl/scene/gl_scene.cpp @@ -416,7 +416,7 @@ sector_t * FGLRenderer::RenderViewpoint (FRenderViewpoint &mainvp, AActor * came Set3DViewport(); - FDrawInfo *di = FDrawInfo::StartDrawInfo(mainvp, nullptr); + FDrawInfo *di = static_cast(HWDrawInfo::StartDrawInfo(mainvp, nullptr)); auto &vp = di->Viewpoint; di->SetViewArea(); auto cm = di->SetFullbrightFlags(mainview ? vp.camera->player : nullptr); diff --git a/src/gl/system/gl_framebuffer.cpp b/src/gl/system/gl_framebuffer.cpp index b211df6d4..c4744baed 100644 --- a/src/gl/system/gl_framebuffer.cpp +++ b/src/gl/system/gl_framebuffer.cpp @@ -43,6 +43,7 @@ #include "hwrenderer/data/hw_viewpointbuffer.h" #include "hwrenderer/dynlights/hw_lightbuffer.h" #include "gl/shaders/gl_shaderprogram.h" +#include "gl/scene/gl_drawinfo.h" #include "gl_debug.h" #include "r_videoscale.h" #include "gl_buffers.h" @@ -376,6 +377,10 @@ IDataBuffer *OpenGLFrameBuffer::CreateDataBuffer(int bindingpoint, bool ssbo) return new GLDataBuffer(bindingpoint, ssbo); } +HWDrawInfo *OpenGLFrameBuffer::CreateDrawInfo() +{ + return new FDrawInfo; +} void OpenGLFrameBuffer::TextureFilterChanged() { diff --git a/src/gl/system/gl_framebuffer.h b/src/gl/system/gl_framebuffer.h index 167841129..11ce2c590 100644 --- a/src/gl/system/gl_framebuffer.h +++ b/src/gl/system/gl_framebuffer.h @@ -44,6 +44,7 @@ public: IVertexBuffer *CreateVertexBuffer() override; IIndexBuffer *CreateIndexBuffer() override; IDataBuffer *CreateDataBuffer(int bindingpoint, bool ssbo) override; + HWDrawInfo *CreateDrawInfo() override; // Retrieves a buffer containing image data for a screenshot. // Hint: Pitch can be negative for upside-down images, in which case buffer diff --git a/src/hwrenderer/scene/hw_drawinfo.cpp b/src/hwrenderer/scene/hw_drawinfo.cpp index bd74b5e05..ac68e9d13 100644 --- a/src/hwrenderer/scene/hw_drawinfo.cpp +++ b/src/hwrenderer/scene/hw_drawinfo.cpp @@ -61,8 +61,73 @@ inline void DeleteLinkedList(T *node) } } + +class FDrawInfoList +{ +public: + TDeletingArray mList; + + HWDrawInfo * GetNew(); + void Release(HWDrawInfo *); +}; + + +FDrawInfoList di_list; + +//========================================================================== +// +// Try to reuse the lists as often as possible as they contain resources that +// are expensive to create and delete. +// +// Note: If multithreading gets used, this class needs synchronization. +// +//========================================================================== + +HWDrawInfo *FDrawInfoList::GetNew() +{ + if (mList.Size() > 0) + { + HWDrawInfo *di; + mList.Pop(di); + return di; + } + return screen->CreateDrawInfo(); +} + +void FDrawInfoList::Release(HWDrawInfo * di) +{ + di->ClearBuffers(); + mList.Push(di); +} + +//========================================================================== +// +// Sets up a new drawinfo struct +// +//========================================================================== + +HWDrawInfo *HWDrawInfo::StartDrawInfo(FRenderViewpoint &parentvp, HWViewpointUniforms *uniforms) +{ + HWDrawInfo *di = di_list.GetNew(); + di->StartScene(parentvp, uniforms); + return di; +} + + +//========================================================================== +// +// +// +//========================================================================== + +static Clipper staticClipper; // Since all scenes are processed sequentially we only need one clipper. +static HWDrawInfo * gl_drawinfo; // This is a linked list of all active DrawInfos and needed to free the memory arena after the last one goes out of scope. + void HWDrawInfo::StartScene(FRenderViewpoint &parentvp, HWViewpointUniforms *uniforms) { + staticClipper.Clear(); + mClipper = &staticClipper; + Viewpoint = parentvp; if (uniforms) { @@ -84,8 +149,35 @@ void HWDrawInfo::StartScene(FRenderViewpoint &parentvp, HWViewpointUniforms *uni if (outer != nullptr) FullbrightFlags = outer->FullbrightFlags; else FullbrightFlags = 0; + outer = gl_drawinfo; + gl_drawinfo = this; + } +//========================================================================== +// +// +// +//========================================================================== + +HWDrawInfo *HWDrawInfo::EndDrawInfo() +{ + assert(this == gl_drawinfo); + for (int i = 0; i < GLDL_TYPES; i++) drawlists[i].Reset(); + gl_drawinfo = outer; + di_list.Release(this); + if (gl_drawinfo == nullptr) + ResetRenderDataAllocator(); + return gl_drawinfo; +} + + +//========================================================================== +// +// +// +//========================================================================== + void HWDrawInfo::ClearBuffers() { for (auto node : otherfloorplanes) DeleteLinkedList(node); diff --git a/src/hwrenderer/scene/hw_drawinfo.h b/src/hwrenderer/scene/hw_drawinfo.h index 878eb0977..7aa0011e5 100644 --- a/src/hwrenderer/scene/hw_drawinfo.h +++ b/src/hwrenderer/scene/hw_drawinfo.h @@ -298,8 +298,10 @@ public: HWPortal * FindPortal(const void * src); void RenderBSPNode(void *node); + static HWDrawInfo *StartDrawInfo(FRenderViewpoint &parentvp, HWViewpointUniforms *uniforms); void StartScene(FRenderViewpoint &parentvp, HWViewpointUniforms *uniforms); void ClearBuffers(); + HWDrawInfo *EndDrawInfo(); void SetViewArea(); int SetFullbrightFlags(player_t *player); diff --git a/src/v_video.h b/src/v_video.h index 6a414ad04..7580aae99 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -56,6 +56,7 @@ class IDataBuffer; class FFlatVertexBuffer; class GLViewpointBuffer; class FLightBuffer; +struct HWDrawInfo; enum EHWCaps { @@ -464,6 +465,7 @@ public: virtual IVertexBuffer *CreateVertexBuffer() { return nullptr; } virtual IIndexBuffer *CreateIndexBuffer() { return nullptr; } virtual IDataBuffer *CreateDataBuffer(int bindingpoint, bool ssbo) { return nullptr; } + virtual HWDrawInfo *CreateDrawInfo() { return nullptr; } bool BuffersArePersistent() { return !!(hwcaps & RFL_BUFFER_STORAGE); } // Begin/End 2D drawing operations.