#include <Buffer.h>
Classes | |
| class | Update |
Public Member Functions | |
| Buffer (uint32_t usage, Size pageSize=PageManager::DEFAULT_PAGE_SIZE) | |
| Buffer (uint32_t usage, Size size, const Byte *bytes, Size pageSize=PageManager::DEFAULT_PAGE_SIZE) | |
| Creates buffer with a given content. More... | |
| Buffer (const Buffer &buf) | |
| Copy constructor. More... | |
| Buffer & | operator= (const Buffer &buf) |
| Assignment constructor. More... | |
| ~Buffer () | |
| Size | getSize () const override |
| template<typename T > | |
| Size | getNumTypedElements () const |
| const Byte * | getData () const |
| uint32_t | getUsage () const |
| Size | resize (Size pSize) |
| Resizes buffer. More... | |
| Size | setData (Size size, const Byte *data) |
| Assign data bytes and size (allocate for size, then copy bytes if exists). More... | |
| Size | setSubData (Size offset, Size size, const Byte *data) |
| Set a subset of buffer's data. More... | |
| template<typename T > | |
| Size | setSubData (Size index, const T &t) |
| Set a subset of buffer's data using data of a given object. More... | |
| template<typename T > | |
| Size | setSubData (Size index, const std::vector< T > &t) |
| Set a subset of buffer's data using a vector of objects of a given type. More... | |
| Size | append (Size size, const Byte *data) |
| Append new data at the end of the current buffer. More... | |
| template<typename T > | |
| Size | append (const T &t) |
| Append new data at the end of the current buffer from an object of a given type. More... | |
| template<typename T > | |
| Size | append (const std::vector< T > &t) |
| Append new data at the end of the current buffer using a vector of objects of a given type. More... | |
| const Sysmem & | getSysmem () const |
| Access the sysmem object. More... | |
| bool | isDirty () const |
| void | applyUpdate (const Update &update) |
| Applies update to a buffer. More... | |
| Update | getUpdate () const |
| Generate Update object from the current changes to the buffer. More... | |
Static Public Member Functions | |
| static uint32_t | getBufferCPUCount () |
| static Size | getBufferCPUMemSize () |
| template<typename T > | |
| static Buffer * | createBuffer (uint32_t usage, const std::vector< T > &v) |
| Creates a buffer from std::vector. More... | |
Public Attributes | |
| const GPUObjectPointer | gpuObject {} |
Protected Member Functions | |
| void | incrementCreatedBufferCount () |
| Counter used for debugging excessive creation of buffers. | |
| void | flush () const |
| Instantly applies current changes to a buffer without creating an Update object. More... | |
| void | markDirty (Size offset, Size bytes) |
| Marks pages on which specified data range is stored as dirty. More... | |
| template<typename T > | |
| void | markDirty (Size index, Size count=1) |
| Marks pages on which data from a number of objects of a specified type range is stored as dirty. More... | |
| Sysmem & | editSysmem () |
| Byte * | editData () |
Returns pointer to data to be edited, but data still needs to be flagged as dirty with a separate makeDirty call. More... | |
Protected Attributes | |
| PageManager | _renderPages |
| Sysmem | _renderSysmem |
| std::atomic< size_t > | _getUpdateCount { 0 } |
| std::atomic< size_t > | _applyUpdateCount { 0 } |
| PageManager | _pages |
| Size | _end { 0 } |
| Sysmem | _sysmem |
| const uint32_t | _usage { 0 } |
Represents various kinds of buffers (index, vertex, uniform, resource, etc.) on the CPU side.
| Buffer::Buffer | ( | uint32_t | usage, |
| Size | pageSize = PageManager::DEFAULT_PAGE_SIZE |
||
| ) |
| usage | A bit sum of Buffer::Usage flags describing this buffer. |
| pageSize | Size of the page in bytes. Pages are the smallest parts of the buffer that can be updated. |
| Buffer::Buffer | ( | uint32_t | usage, |
| Size | size, | ||
| const Byte * | bytes, | ||
| Size | pageSize = PageManager::DEFAULT_PAGE_SIZE |
||
| ) |
Creates buffer with a given content.
| usage | Planned usage of this buffer, bit sum of Buffer::Usage flags. |
| size | Size in bytes. |
| bytes | Pointer to the data. |
| pageSize | Size of the page in bytes. Pages are the smallest parts of the buffer that can be updated. |
| Buffer::Buffer | ( | const Buffer & | buf | ) |
| Buffer::~Buffer | ( | ) |
Buffer destructor updated statistics.
|
inline |
Append new data at the end of the current buffer using a vector of objects of a given type.
| T | Object type. |
| t | Vector of objects that will be the source of data. |
|
inline |
Append new data at the end of the current buffer from an object of a given type.
| T | Object type. |
| t | Instance of the object that will be the source of data. |
| Buffer::Size Buffer::append | ( | Size | size, |
| const Byte * | data | ||
| ) |
Append new data at the end of the current buffer.
Resizes buffer to (size + getSize) and copies the new data.
| size | Size of the data to append in bytes. |
| data | Pointer to the data. |
| void Buffer::applyUpdate | ( | const Update & | update | ) |
Applies update to a buffer.
After the batches are generated changes to the buffer contents need to be applied. The reason for this is that a frame is executed at the same time as another frame object is being generated.
| update | Update object to apply. |
|
inlinestatic |
Creates a buffer from std::vector.
| T | Vector type. |
| usage | Planned usage of this buffer, bit sum of Buffer::Usage flags. |
| v | Vector, which contents will be copied to the buffer. |
|
inlineprotected |
Returns pointer to data to be edited, but data still needs to be flagged as dirty with a separate makeDirty call.
|
inlineprotected |
|
protected |
Instantly applies current changes to a buffer without creating an Update object.
For use by the render thread to avoid the intermediate step of getUpdate/applyUpdate.
|
static |
|
static |
|
inline |
|
inline |
| T | Element type. |
|
overridevirtual |
Implements gpu::Resource.
|
inline |
| Buffer::Update Buffer::getUpdate | ( | ) | const |
|
inline |
|
inline |
|
inlineprotected |
Marks pages on which data from a number of objects of a specified type range is stored as dirty.
| T | Type of the object from which data is stored. |
| index | Start position. Offset in bytes is index * sizeof(T). |
| count | Number of objects to mark as dirty. Range in bytes is count * sizeof(T). |
|
protected |
Marks pages on which specified data range is stored as dirty.
Used to notify buffer update system that data was edited.
| offset | |
| bytes |
Assignment constructor.
Performs deep copy of the sysmem buffer.
| buf | Buffer to be copied. |
| Buffer::Size Buffer::resize | ( | Size | pSize | ) |
Resizes buffer.
Keeps previous data [0 to min(pSize, mSize)].
| pSize | New size in bytes. |
| Buffer::Size Buffer::setData | ( | Size | size, |
| const Byte * | data | ||
| ) |
Assign data bytes and size (allocate for size, then copy bytes if exists).
| size | New size in bytes. |
| data | Pointer to data of size specified in the previous parameter. |
|
inline |
Set a subset of buffer's data using a vector of objects of a given type.
| T | Object type. |
| index | Position in the buffer to which to write to. Offset in bytes is (index * sizeof(T)). |
| t | Vector of objects that will be the source of data. |
|
inline |
Set a subset of buffer's data using data of a given object.
| T | Type of the object. |
| index | Position in the buffer to which to write to. Offset in bytes is (index * sizeof(T)). |
| t | Instance of the object that will be the source of data. |
| Buffer::Size Buffer::setSubData | ( | Size | offset, |
| Size | size, | ||
| const Byte * | data | ||
| ) |
Set a subset of buffer's data.
Fails and returns 0 if buffer is not big enough.
| offset | Offset at which to start writing data. |
| size | Size in bytes of data to write. |
| data | Pointer to the data. |
|
mutableprotected |
Number of times a buffer update object was applied.
|
protected |
Size of the buffer.
|
mutableprotected |
Number of times a buffer update object was created.
|
mutableprotected |
PageManager for _sysmem. When buffer memory is edited, pages that were changed are flagged here and then Update object can be generated. Later applying the update copies changes to _renderSysmem object.
|
mutableprotected |
PageManager for second copy of the buffer (one ot which updates are applied).
|
mutableprotected |
Second copy of the buffer. Update objects need to be generated from _sysmem and applying them copies them to _renderSysmem.
|
protected |
Changes to the buffer are written here, and then pages corresponding to them in _pages are marked as dirty. This is later used to create Update object that can be applied to _renderSysmem.
|
protected |
Usage of this buffer. It's a bit sum of Buffer::Usage.
| const GPUObjectPointer gpu::Buffer::gpuObject {} |
Pointer to the renderer backend object associated with this object. The renderer backend object will have different type depending on currently running backend, for example OpenGL or Vulkan.