22 #include "precompiled.h"
32 : m_VertexSize(vertexSize), m_Handle(0), m_SysMem(0), m_Usage(usage), m_Target(target)
36 if (target == GL_ARRAY_BUFFER)
41 size = std::min(size, vertexSize*65536);
75 typedef std::list<VBChunk*>::iterator Iter;
105 typedef std::list<VBChunk*>::iterator Iter;
107 if (numVertices <= (*iter)->m_Count) {
124 if (chunk->
m_Count > numVertices)
148 typedef std::list<VBChunk*>::iterator Iter;
160 || (*iter)->m_Index + (*iter)->m_Count == chunk->
m_Index)
163 chunk->
m_Count += (*iter)->m_Count;
222 pglBindBufferARB(GL_ARRAY_BUFFER, 0);
223 pglBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, 0);
242 typedef std::list<VBChunk*>::iterator Iter;
245 debug_printf(L
"free chunk %p: size=%d\n", *iter, (
int)((*iter)->m_Count));
246 maxSize = std::max((*iter)->m_Count, maxSize);
size_t m_Index
Start index of this chunk in owner.
u8 * Bind()
Bind to this buffer; return pointer to address required as parameter to glVertexPointer ( + etc) call...
size_t GetBytesReserved() const
GLenum m_Usage
Usage type of the buffer (GL_STATIC_DRAW etc)
VBChunk: describes a portion of this vertex buffer.
GLenum m_Target
Buffer target (GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER)
u8 * GetBindAddress()
Get the address that Bind() will return, without actually binding.
#define ENSURE(expr)
ensure the expression <expr> evaluates to non-zero.
u8 * m_SysMem
Raw system memory for systems not supporting VBOs.
std::list< VBChunk * > m_FreeList
List of free chunks in this buffer.
size_t m_FreeVertices
Available free vertices - total of all free vertices in the free list.
CVertexBuffer(size_t vertexSize, GLenum usage, GLenum target)
void UpdateChunkVertices(VBChunk *chunk, void *data)
Update vertex data for given chunk. Transfers the provided data to the actual OpenGL vertex buffer...
void Release(VBChunk *chunk)
Return given chunk to this buffer.
size_t m_Count
Number of vertices used by chunk.
size_t m_MaxVertices
Number of vertices of above size in this buffer.
CVertexBuffer * m_Owner
Owning (parent) vertex buffer.
size_t GetBytesAllocated() const
GLuint m_Handle
Handle to the actual GL vertex buffer object.
size_t m_VertexSize
Vertex size of this vertex buffer.
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...
#define MAX_VB_SIZE_BYTES
static void Unbind()
Unbind any currently-bound buffer, so glVertexPointer etc calls will not attempt to use it...
VBChunk * Allocate(size_t vertexSize, size_t numVertices, GLenum usage, GLenum target)
Try to allocate a buffer of given number of vertices (each of given size), and with the given type - ...
void debug_printf(const wchar_t *fmt,...)
write a formatted string to the debug channel, subject to filtering (see below).