Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
|
CVertexBuffer: encapsulation of backend buffers, also supplying some additional functionality for sharing buffers between multiple objects. More...
#include <VertexBuffer.h>
Classes | |
struct | VBChunk |
Public Member Functions | |
CVertexBuffer (Renderer::Backend::IDevice *device, const char *name, const size_t vertexSize, const Renderer::Backend::IBuffer::Type type, const uint32_t usage) | |
CVertexBuffer (Renderer::Backend::IDevice *device, const char *name, const size_t vertexSize, const Renderer::Backend::IBuffer::Type type, const uint32_t usage, const size_t maximumBufferSize) | |
~CVertexBuffer () | |
void | UploadIfNeeded (Renderer::Backend::IDeviceCommandContext *deviceCommandContext) |
void | PrepareForRendering (VBChunk *chunk) |
Make the vertex data available for the next usage. More... | |
void | UpdateChunkVertices (VBChunk *chunk, void *data) |
Update vertex data for given chunk. Transfers the provided data to the actual OpenGL vertex buffer. More... | |
size_t | GetVertexSize () const |
size_t | GetBytesReserved () const |
size_t | GetBytesAllocated () const |
bool | CompatibleVertexType (const size_t vertexSize, const Renderer::Backend::IBuffer::Type type, const uint32_t usage) const |
Returns true if this vertex buffer is compatible with the specified vertex type and intended usage. More... | |
void | DumpStatus () const |
Renderer::Backend::IBuffer * | GetBuffer () |
Static Public Member Functions | |
static bool | UseStreaming (const uint32_t usage) |
Given the usage flags of a buffer that has been (or will be) allocated: More... | |
Private Member Functions | |
NONCOPYABLE (CVertexBuffer) | |
VBChunk * | Allocate (const size_t vertexSize, const size_t numberOfVertices, const Renderer::Backend::IBuffer::Type type, const uint32_t usage, void *backingStore) |
Try to allocate a buffer of given number of vertices (each of given size), and with the given type - return null if no free chunks available. More... | |
void | Release (VBChunk *chunk) |
Return given chunk to this buffer. More... | |
Private Attributes | |
size_t | m_VertexSize |
Vertex size of this vertex buffer. More... | |
size_t | m_MaxVertices |
Number of vertices of above size in this buffer. More... | |
std::vector< VBChunk * > | m_FreeList |
List of free chunks in this buffer. More... | |
std::vector< VBChunk * > | m_AllocList |
List of allocated chunks. More... | |
size_t | m_FreeVertices |
Available free vertices - total of all free vertices in the free list. More... | |
std::unique_ptr< Renderer::Backend::IBuffer > | m_Buffer |
bool | m_HasNeededChunks |
Friends | |
class | CVertexBufferManager |
CVertexBuffer: encapsulation of backend buffers, also supplying some additional functionality for sharing buffers between multiple objects.
The class can be used in two modes, depending on the usage parameter:
Static buffer: Call Allocate() with backingStore = nullptr. Then call UpdateChunkVertices() with any pointer - the data will be immediately copied to the buffer. This should be used for vertex data that rarely changes.
Dynamic buffer: Call Allocate() with backingStore pointing at some memory that will remain valid for the lifetime of the CVertexBuffer. This should be used for vertex data that may change every frame. Rendering is expected to occur in two phases:
CVertexBuffer::CVertexBuffer | ( | Renderer::Backend::IDevice * | device, |
const char * | name, | ||
const size_t | vertexSize, | ||
const Renderer::Backend::IBuffer::Type | type, | ||
const uint32_t | usage | ||
) |
CVertexBuffer::CVertexBuffer | ( | Renderer::Backend::IDevice * | device, |
const char * | name, | ||
const size_t | vertexSize, | ||
const Renderer::Backend::IBuffer::Type | type, | ||
const uint32_t | usage, | ||
const size_t | maximumBufferSize | ||
) |
CVertexBuffer::~CVertexBuffer | ( | ) |
|
private |
Try to allocate a buffer of given number of vertices (each of given size), and with the given type - return null if no free chunks available.
bool CVertexBuffer::CompatibleVertexType | ( | const size_t | vertexSize, |
const Renderer::Backend::IBuffer::Type | type, | ||
const uint32_t | usage | ||
) | const |
Returns true if this vertex buffer is compatible with the specified vertex type and intended usage.
void CVertexBuffer::DumpStatus | ( | ) | const |
|
inline |
size_t CVertexBuffer::GetBytesAllocated | ( | ) | const |
size_t CVertexBuffer::GetBytesReserved | ( | ) | const |
|
inline |
|
private |
void CVertexBuffer::PrepareForRendering | ( | VBChunk * | chunk | ) |
Make the vertex data available for the next usage.
|
private |
Return given chunk to this buffer.
void CVertexBuffer::UpdateChunkVertices | ( | VBChunk * | chunk, |
void * | data | ||
) |
Update vertex data for given chunk. Transfers the provided data to the actual OpenGL vertex buffer.
void CVertexBuffer::UploadIfNeeded | ( | Renderer::Backend::IDeviceCommandContext * | deviceCommandContext | ) |
|
static |
Given the usage flags of a buffer that has been (or will be) allocated:
If true, we assume the buffer is going to be modified on every frame, so we will re-upload the entire buffer every frame using glMapBuffer. This requires the buffer's owner to hold onto its backing store.
If false, we assume it will change rarely, and use direct upload to update it incrementally. The backing store can be freed to save memory.
|
friend |
|
private |
List of allocated chunks.
|
private |
|
private |
List of free chunks in this buffer.
|
private |
Available free vertices - total of all free vertices in the free list.
|
private |
|
private |
Number of vertices of above size in this buffer.
|
private |
Vertex size of this vertex buffer.