Add DynamicTypedBuffer utility
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -202,3 +202,29 @@ protected:
|
||||
desc = GPUBufferDescription::Structured(numElements, _stride, _isUnorderedAccess);
|
||||
}
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Dynamic Typed buffer that allows to upload data to the GPU from CPU (supports dynamic resizing).
|
||||
/// </summary>
|
||||
class FLAXENGINE_API DynamicTypedBuffer : public DynamicBuffer
|
||||
{
|
||||
private:
|
||||
PixelFormat _format;
|
||||
bool _isUnorderedAccess;
|
||||
|
||||
public:
|
||||
|
||||
/// <summary>
|
||||
/// Init
|
||||
/// </summary>
|
||||
/// <param name="initialCapacity">Initial capacity of the buffer (in bytes).</param>
|
||||
/// <param name="format">Format of the data.</param>
|
||||
/// <param name="isUnorderedAccess">True if unordered access usage.</param>
|
||||
/// <param name="name">Buffer name.</param>
|
||||
DynamicTypedBuffer(uint32 initialCapacity, PixelFormat format, bool isUnorderedAccess = false, const String& name = String::Empty);
|
||||
|
||||
protected:
|
||||
|
||||
// [DynamicBuffer]
|
||||
void InitDesc(GPUBufferDescription& desc, int32 numElements) override;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user