diff --git a/Source/Engine/Graphics/DynamicBuffer.cpp b/Source/Engine/Graphics/DynamicBuffer.cpp index dd96d7d2c..29882aef5 100644 --- a/Source/Engine/Graphics/DynamicBuffer.cpp +++ b/Source/Engine/Graphics/DynamicBuffer.cpp @@ -1,6 +1,7 @@ // Copyright (c) 2012-2022 Wojciech Figat. All rights reserved. #include "DynamicBuffer.h" +#include "PixelFormatExtensions.h" #include "GPUDevice.h" #include "Engine/Core/Log.h" #include "Engine/Core/Utilities.h" @@ -87,3 +88,18 @@ void DynamicBuffer::Dispose() SAFE_DELETE_GPU_RESOURCE(_buffer); Data.Resize(0); } + +DynamicTypedBuffer::DynamicTypedBuffer(uint32 initialCapacity, PixelFormat format, bool isUnorderedAccess, const String& name) + : DynamicBuffer(initialCapacity, PixelFormatExtensions::SizeInBytes(format), name) + , _format(format) + , _isUnorderedAccess(isUnorderedAccess) +{ +} + +void DynamicTypedBuffer::InitDesc(GPUBufferDescription& desc, int32 numElements) +{ + auto bufferFlags = GPUBufferFlags::ShaderResource; + if (_isUnorderedAccess) + bufferFlags |= GPUBufferFlags::UnorderedAccess; + desc = GPUBufferDescription::Buffer(numElements * _stride, bufferFlags, _format, nullptr, _stride); +} diff --git a/Source/Engine/Graphics/DynamicBuffer.h b/Source/Engine/Graphics/DynamicBuffer.h index aeab4105e..507c284de 100644 --- a/Source/Engine/Graphics/DynamicBuffer.h +++ b/Source/Engine/Graphics/DynamicBuffer.h @@ -202,3 +202,29 @@ protected: desc = GPUBufferDescription::Structured(numElements, _stride, _isUnorderedAccess); } }; + +/// +/// Dynamic Typed buffer that allows to upload data to the GPU from CPU (supports dynamic resizing). +/// +class FLAXENGINE_API DynamicTypedBuffer : public DynamicBuffer +{ +private: + PixelFormat _format; + bool _isUnorderedAccess; + +public: + + /// + /// Init + /// + /// Initial capacity of the buffer (in bytes). + /// Format of the data. + /// True if unordered access usage. + /// Buffer name. + DynamicTypedBuffer(uint32 initialCapacity, PixelFormat format, bool isUnorderedAccess = false, const String& name = String::Empty); + +protected: + + // [DynamicBuffer] + void InitDesc(GPUBufferDescription& desc, int32 numElements) override; +};