Pyrogenesis
trunk
|
CVertexBuffer: encapsulation of ARB_vertex_buffer_object, also supplying some additional functionality for sharing buffers between multiple objects. More...
#include <VertexBuffer.h>
Classes | |
struct | VBChunk |
VBChunk: describes a portion of this vertex buffer. More... | |
Public Member Functions | |
CVertexBuffer (size_t vertexSize, GLenum usage, GLenum target) | |
~CVertexBuffer () | |
u8 * | Bind () |
Bind to this buffer; return pointer to address required as parameter to glVertexPointer ( + etc) calls. More... | |
u8 * | GetBindAddress () |
Get the address that Bind() will return, without actually binding. More... | |
void | PrepareForRendering (VBChunk *chunk) |
Make the vertex data available for the next call to Bind() 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 (size_t vertexSize, GLenum usage, GLenum target) |
Returns true if this vertex buffer is compatible with the specified vertex type and intended usage. More... | |
void | DumpStatus () |
Static Public Member Functions | |
static void | Unbind () |
Unbind any currently-bound buffer, so glVertexPointer etc calls will not attempt to use it. More... | |
static bool | UseStreaming (GLenum usage) |
Given the usage flags of a buffer that has been (or will be) allocated: More... | |
Protected Member Functions | |
VBChunk * | Allocate (size_t vertexSize, size_t numVertices, GLenum usage, GLenum target, 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 Member Functions | |
NONCOPYABLE (CVertexBuffer) | |
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::list< VBChunk * > | m_FreeList |
List of free chunks in this buffer. More... | |
std::list< 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... | |
GLuint | m_Handle |
Handle to the actual GL vertex buffer object. More... | |
u8 * | m_SysMem |
Raw system memory for systems not supporting VBOs. More... | |
GLenum | m_Usage |
Usage type of the buffer (GL_STATIC_DRAW etc) More... | |
GLenum | m_Target |
Buffer target (GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER) More... | |
Friends | |
class | CVertexBufferManager |
CVertexBuffer: encapsulation of ARB_vertex_buffer_object, also supplying some additional functionality for sharing buffers between multiple objects.
The class can be used in two modes, depending on the usage parameter:
GL_STATIC_DRAW: Call Allocate() with backingStore = NULL. Then call UpdateChunkVertices() with any pointer - the data will be immediately copied to the VBO. This should be used for vertex data that rarely changes.
GL_DYNAMIC_DRAW, GL_STREAM_DRAW: 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 | ( | size_t | vertexSize, |
GLenum | usage, | ||
GLenum | target | ||
) |
CVertexBuffer::~CVertexBuffer | ( | ) |
|
protected |
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.
u8 * CVertexBuffer::Bind | ( | ) |
Bind to this buffer; return pointer to address required as parameter to glVertexPointer ( + etc) calls.
bool CVertexBuffer::CompatibleVertexType | ( | size_t | vertexSize, |
GLenum | usage, | ||
GLenum | target | ||
) |
Returns true if this vertex buffer is compatible with the specified vertex type and intended usage.
void CVertexBuffer::DumpStatus | ( | ) |
u8 * CVertexBuffer::GetBindAddress | ( | ) |
Get the address that Bind() will return, without actually binding.
size_t CVertexBuffer::GetBytesAllocated | ( | ) | const |
size_t CVertexBuffer::GetBytesReserved | ( | ) | const |
|
inline |
|
private |
|
inline |
Make the vertex data available for the next call to Bind()
|
protected |
Return given chunk to this buffer.
|
static |
Unbind any currently-bound buffer, so glVertexPointer etc calls will not attempt to use it.
void CVertexBuffer::UpdateChunkVertices | ( | VBChunk * | chunk, |
void * | data | ||
) |
Update vertex data for given chunk. Transfers the provided data to the actual OpenGL vertex buffer.
|
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 glSubBufferData to update it incrementally. The backing store can be freed to save memory.
|
friend |
|
private |
List of allocated chunks.
|
private |
List of free chunks in this buffer.
|
private |
Available free vertices - total of all free vertices in the free list.
|
private |
Handle to the actual GL vertex buffer object.
|
private |
Number of vertices of above size in this buffer.
|
private |
Raw system memory for systems not supporting VBOs.
|
private |
Buffer target (GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER)
|
private |
Usage type of the buffer (GL_STATIC_DRAW etc)
|
private |
Vertex size of this vertex buffer.