![]() |
ezEngine
Release 25.03
|
A dynamic buffer can be used when a lot of data needs to be stored in a single large buffer with dynamic size. More...
#include <DynamicBuffer.h>
Classes | |
struct | ChangedAllocation |
Public Member Functions | |
template<typename U > | |
ezUInt32 | Allocate (const U &userData, ezUInt32 uiCount=1) |
Allocates a single or multiple elements and returns the offset to the first element. This offset is used to identify the allocation and should also be used in a shader to read the data from the buffer. More... | |
void | Deallocate (ezUInt32 uiOffset) |
Removes an allocation at the given offset. The offset must have been returned by Allocate. This will create unused space in the buffer that can be filled by subsequent allocations or closed later by compaction. | |
template<typename T > | |
ezArrayPtr< T > | MapForWriting (ezUInt32 uiOffset) |
Maps a range of elements for writing. | |
void | UploadChangesForNextFrame () |
Upload all changed data to the GPU buffer for the next rendering frame, aka the next time BeginFrame is called on the GALDevice. | |
void | RunCompactionSteps (ezDynamicArray< ChangedAllocation > &out_changedAllocations, ezUInt32 uiMaxSteps=16) |
Tries to compact the buffer by moving allocations to free ranges. All moved allocations are returned in out_changedAllocations. More... | |
const ezGALBufferHandle & | GetBufferForRendering () const |
This should be called inside the rendering code to retrieve the underlying buffer for rendering. More... | |
Friends | |
class | ezMemoryUtils |
class | ezGALDevice |
A dynamic buffer can be used when a lot of data needs to be stored in a single large buffer with dynamic size.
This class supports allocation and deallocation of single elements or ranges of multiple elements. An allocation is identified by an offset and can have additional user data attached. The indented usage patterns is that data is allocated and written to the buffer during game play or extraction code. After all data has been written UploadChangesForNextFrame needs to be called to upload changed data to the GPU buffer. The renderer would then call GetBufferForRendering to get the correct buffer for rendering.
|
inline |
Allocates a single or multiple elements and returns the offset to the first element. This offset is used to identify the allocation and should also be used in a shader to read the data from the buffer.
The user data can be used to store additional information, typically the owner of the allocation, like e.g. a component handle.
|
inline |
This should be called inside the rendering code to retrieve the underlying buffer for rendering.
It is ensured that it will always return the same buffer until the next time BeginFrame is called on the GALDevice even if the buffer has been resized due to more allocations on the game play or extraction side.
void ezGALDynamicBuffer::RunCompactionSteps | ( | ezDynamicArray< ChangedAllocation > & | out_changedAllocations, |
ezUInt32 | uiMaxSteps = 16 |
||
) |
Tries to compact the buffer by moving allocations to free ranges. All moved allocations are returned in out_changedAllocations.
The user data can be used to update the owner of the allocation. To prevent too many changes per frame only uiMaxSteps are executed which corresponds to the number of allocations which can be moved.