35 glDeleteBuffers(1, &
_id);
64 assert(dataPointer &&
"No data pointer passed");
65 assert(elementSize > 0 && elementSize < 5 &&
"Element size invalid");
70 SL_EXIT_MSG(
"Attribute type does not exist in VBO.");
74 SL_EXIT_MSG(
"Interleaved buffers can't be updated.");
78 glGenBuffers(1, &
_id);
86 glBindBuffer(GL_ARRAY_BUFFER,
_id);
87 glBufferSubData(GL_ARRAY_BUFFER,
138 glGenBuffers(1, &
_id);
139 glBindBuffer(GL_ARRAY_BUFFER,
_id);
149 if (a.dataPointer !=
_attribs[0].dataPointer)
201 glBufferData(GL_ARRAY_BUFFER,
221 SLuint iSrc = v * elementSizeBytes;
222 for (
SLuint b = 0; b < elementSizeBytes; ++b)
223 data[iDst + b] = ((
SLuchar*)a.dataPointer)[iSrc + b];
227 glBufferData(GL_ARRAY_BUFFER,
236 glBufferData(GL_ARRAY_BUFFER,
246 glBufferSubData(GL_ARRAY_BUFFER,
274 glBindBuffer(GL_ARRAY_BUFFER,
_id);
284 glVertexAttribIPointer((
SLuint)a.location,
288 (
void*)(
size_t)a.offsetBytes);
292 glVertexAttribPointer((
SLuint)a.location,
297 (
void*)(
size_t)a.offsetBytes);
301 glEnableVertexAttribArray((
SLuint)a.location);
304 if (instanceDivisor > 0)
305 glVertexAttribDivisor((
SLuint)a.location,
319 glVertexAttribIPointer((
SLuint)a.location,
323 (
void*)(
size_t)a.offsetBytes);
327 glVertexAttribPointer((
SLuint)a.location,
332 (
void*)(
size_t)a.offsetBytes);
336 glEnableVertexAttribArray((
SLuint)a.location);
339 if (instanceDivisor > 0)
340 glVertexAttribDivisor((
SLuint)a.location,
357 glDisableVertexAttribArray((
SLuint)a.location);
vector< SLuchar > SLVuchar
#define SL_EXIT_MSG(message)
SLGLAttributeType
Enumeration for float vertex attribute types.
SLGLBufferUsage
Enumeration for buffer usage types also supported by OpenGL ES.
@ BU_stream
Buffer will be modified once and used at most a few times.
SLGLBufferType
Enumeration for buffer data types.
@ BT_ubyte
vertex index type (0-2^8)
@ BT_ushort
vertex index type (0-2^16)
@ BT_float
float vertex attributes
@ BT_int
int vertex attributes
@ BT_uint
vertex index type (0-2^32)
Singleton class for global render state.
Wrapper class around OpenGL Vertex Buffer Objects (VBO)
SLint attribIndex(SLGLAttributeType type)
Returns the vector index if a vertex attribute exists otherwise -1.
void generate(SLuint numVertices, SLGLBufferUsage usage=BU_static, SLbool outputInterleaved=true)
Generates the VBO.
SLuint _sizeBytes
Distance for interleaved attributes in bytes.
static SLuint totalBufferSize
static total no. of buffers in use
SLbool _outputIsInterleaved
Vector of vertex attributes.
SLGLBufferUsage _usage
Total size of float VBO in bytes.
static SLuint totalBufferCount
SLVVertexAttrib _attribs
NO. of vertices in array.
SLuint _numVertices
OpenGL id of vertex buffer object.
SLGLVertexBuffer()
Constructor initializing with default values.
SLbool _inputIsInterleaved
Flag if VBO should be generated interleaved.
void clear()
Calls deleteGL & clears the attributes.
static SLuint sizeOfType(SLGLBufferType type)
static total size of all buffers in bytes
void deleteGL()
Deletes all vertex array & vertex buffer objects.
SLuint _strideBytes
Flag if VBO should be generated interleaved.
void disableAttrib()
disables the vertex attribute for OpenGL < 3.0
void bindAndEnableAttrib(SLuint divisor=0) const
Binds & enables the vertex attribute for OpenGL < 3.0 and during VAO creation.
void updateAttrib(SLGLAttributeType type, SLint elementSize, void *dataPointer)
Updates a specific vertex attribute in the VBO.