Pyrogenesis  trunk
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
CVertexBuffer Class Reference

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 ()
 
u8Bind ()
 Bind to this buffer; return pointer to address required as parameter to glVertexPointer ( + etc) calls. More...
 
u8GetBindAddress ()
 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

VBChunkAllocate (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...
 
u8m_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
 

Detailed Description

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:

Constructor & Destructor Documentation

CVertexBuffer::CVertexBuffer ( size_t  vertexSize,
GLenum  usage,
GLenum  target 
)
CVertexBuffer::~CVertexBuffer ( )

Member Function Documentation

CVertexBuffer::VBChunk * CVertexBuffer::Allocate ( size_t  vertexSize,
size_t  numVertices,
GLenum  usage,
GLenum  target,
void *  backingStore 
)
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
size_t CVertexBuffer::GetVertexSize ( ) const
inline
CVertexBuffer::NONCOPYABLE ( CVertexBuffer  )
private
void CVertexBuffer::PrepareForRendering ( VBChunk chunk)
inline

Make the vertex data available for the next call to Bind()

void CVertexBuffer::Release ( VBChunk chunk)
protected

Return given chunk to this buffer.

void CVertexBuffer::Unbind ( )
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.

bool CVertexBuffer::UseStreaming ( GLenum  usage)
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.

Friends And Related Function Documentation

friend class CVertexBufferManager
friend

Member Data Documentation

std::list<VBChunk*> CVertexBuffer::m_AllocList
private

List of allocated chunks.

std::list<VBChunk*> CVertexBuffer::m_FreeList
private

List of free chunks in this buffer.

size_t CVertexBuffer::m_FreeVertices
private

Available free vertices - total of all free vertices in the free list.

GLuint CVertexBuffer::m_Handle
private

Handle to the actual GL vertex buffer object.

size_t CVertexBuffer::m_MaxVertices
private

Number of vertices of above size in this buffer.

u8* CVertexBuffer::m_SysMem
private

Raw system memory for systems not supporting VBOs.

GLenum CVertexBuffer::m_Target
private

Buffer target (GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER)

GLenum CVertexBuffer::m_Usage
private

Usage type of the buffer (GL_STATIC_DRAW etc)

size_t CVertexBuffer::m_VertexSize
private

Vertex size of this vertex buffer.


The documentation for this class was generated from the following files: