diff --git a/Source/Engine/Graphics/RenderBuffers.cpp b/Source/Engine/Graphics/RenderBuffers.cpp index df2962e52..a98b13d91 100644 --- a/Source/Engine/Graphics/RenderBuffers.cpp +++ b/Source/Engine/Graphics/RenderBuffers.cpp @@ -25,6 +25,11 @@ RenderBuffers::RenderBuffers(const SpawnParams& params) #undef CREATE_TEXTURE } +String RenderBuffers::CustomBuffer::ToString() const +{ + return Name; +} + RenderBuffers::~RenderBuffers() { Release(); @@ -61,6 +66,15 @@ void RenderBuffers::Prepare() UPDATE_LAZY_KEEP_RT(HalfResDepth); UPDATE_LAZY_KEEP_RT(LuminanceMap); #undef UPDATE_LAZY_KEEP_RT + for (int32 i = CustomBuffers.Count() - 1; i >= 0; i--) + { + CustomBuffer* e = CustomBuffers[i]; + if (frameIndex - e->LastFrameUsed >= LAZY_FRAMES_COUNT) + { + Delete(e); + CustomBuffers.RemoveAt(i); + } + } } GPUTexture* RenderBuffers::RequestHalfResDepth(GPUContext* context) @@ -184,4 +198,5 @@ void RenderBuffers::Release() UPDATE_LAZY_KEEP_RT(HalfResDepth); UPDATE_LAZY_KEEP_RT(LuminanceMap); #undef UPDATE_LAZY_KEEP_RT + CustomBuffers.ClearDelete(); } diff --git a/Source/Engine/Graphics/RenderBuffers.h b/Source/Engine/Graphics/RenderBuffers.h index 1eebe47f6..b99ec5308 100644 --- a/Source/Engine/Graphics/RenderBuffers.h +++ b/Source/Engine/Graphics/RenderBuffers.h @@ -21,18 +21,25 @@ /// API_CLASS() class FLAXENGINE_API RenderBuffers : public ScriptingObject { -DECLARE_SCRIPTING_TYPE(RenderBuffers); -protected: + DECLARE_SCRIPTING_TYPE(RenderBuffers); + class CustomBuffer : public Object + { + public: + String Name; + uint64 LastFrameUsed = 0; + + String ToString() const override; + }; + +protected: int32 _width = 0; int32 _height = 0; float _aspectRatio = 0.0f; Viewport _viewport; - Array> _resources; public: - union { struct @@ -80,15 +87,16 @@ public: GPUTexture* TemporalAA = nullptr; uint64 LastFrameTemporalAA = 0; -public: + // Maps the custom buffer type into the object that holds the state. + Array CustomBuffers; +public: /// /// Finalizes an instance of the class. /// ~RenderBuffers(); public: - /// /// Prepares buffers for rendering a scene. Called before rendering so other parts can reuse calculated value. /// @@ -102,7 +110,6 @@ public: GPUTexture* RequestHalfResDepth(GPUContext* context); public: - /// /// Gets the buffers width (in pixels). /// @@ -143,6 +150,20 @@ public: return _viewport; } + template + T* GetCustomBuffer(const StringView& name) + { + for (CustomBuffer* e : CustomBuffers) + { + if (e->Name == name) + return (T*)e; + } + CustomBuffer* result = New(); + result->Name = name; + CustomBuffers.Add(result); + return (T*)result; + } + /// /// Gets the current GPU memory usage by all the buffers (in bytes). /// @@ -162,7 +183,6 @@ public: API_FIELD(ReadOnly) GPUTexture* MotionVectors; public: - /// /// Allocates the buffers. ///