SLProject 4.0.000
SLGLVertexBuffer Class Reference

SLGLVertexBuffer encapsulates an OpenGL buffer for vertex attributes. More...

#include <SLGLVertexBuffer.h>

Public Member Functions

 SLGLVertexBuffer ()
 Constructor initializing with default values. More...
 
 ~SLGLVertexBuffer ()
 
void deleteGL ()
 Deletes all vertex array & vertex buffer objects. More...
 
void clear ()
 Calls deleteGL & clears the attributes. More...
 
SLint attribIndex (SLGLAttributeType type)
 Returns the vector index if a vertex attribute exists otherwise -1. More...
 
void updateAttrib (SLGLAttributeType type, SLint elementSize, void *dataPointer)
 Updates a specific vertex attribute in the VBO. More...
 
void updateAttrib (SLGLAttributeType type, SLVuint &data)
 Updates a specific vertex attribute in the VBO. More...
 
void updateAttrib (SLGLAttributeType type, SLVfloat &data)
 Updates a specific vertex attribute in the VBO. More...
 
void updateAttrib (SLGLAttributeType type, SLVVec2f &data)
 Updates a specific vertex attribute in the VBO. More...
 
void updateAttrib (SLGLAttributeType type, SLVVec3f &data)
 Updates a specific vertex attribute in the VBO. More...
 
void updateAttrib (SLGLAttributeType type, SLVVec4f &data)
 Updates a specific vertex attribute in the VBO. More...
 
void generate (SLuint numVertices, SLGLBufferUsage usage=BU_static, SLbool outputInterleaved=true)
 Generates the VBO. More...
 
void bindAndEnableAttrib ()
 Binds & enables the vertex attribute for OpenGL < 3.0. More...
 
void disableAttrib ()
 disables the vertex attribute for OpenGL < 3.0 More...
 
SLuint id () const
 
SLuint size () const
 
SLVVertexAttribattribs ()
 
SLbool outputInterleaved () const
 

Static Public Member Functions

static SLuint sizeOfType (SLGLBufferType type)
 static total size of all buffers in bytes More...
 

Static Public Attributes

static SLuint totalBufferCount = 0
 
static SLuint totalBufferSize = 0
 static total no. of buffers in use More...
 

Protected Attributes

SLuint _id
 
SLuint _numVertices
 OpenGL id of vertex buffer object. More...
 
SLVVertexAttrib _attribs
 NO. of vertices in array. More...
 
SLbool _outputInterleaved
 Vector of vertex attributes. More...
 
SLuint _strideBytes
 Flag if VBO should be generated interleaved. More...
 
SLuint _sizeBytes
 Distance for interleaved attributes in bytes. More...
 
SLGLBufferUsage _usage
 Total size of float VBO in bytes. More...
 

Detailed Description

SLGLVertexBuffer encapsulates an OpenGL buffer for vertex attributes.

SLGLVertexBuffer is only meant to be used within the SLGLVertexArray class. Attributes can be either be in sequential order (first all positions, then all normals, etc.) or interleaved (all attributes together for one vertex). See SLGLVertexBuffer::generate for more information.
Vertex index buffer are not handled in this class. They are generated in SLGLVertexArray.

Constructor & Destructor Documentation

◆ SLGLVertexBuffer()

SLGLVertexBuffer::SLGLVertexBuffer ( )

Constructor initializing with default values.

◆ ~SLGLVertexBuffer()

SLGLVertexBuffer::~SLGLVertexBuffer ( )
inline

Member Function Documentation

◆ attribIndex()

SLint SLGLVertexBuffer::attribIndex ( SLGLAttributeType  type)

Returns the vector index if a vertex attribute exists otherwise -1.

◆ attribs()

SLVVertexAttrib & SLGLVertexBuffer::attribs ( )
inline

◆ bindAndEnableAttrib()

void SLGLVertexBuffer::bindAndEnableAttrib ( )

Binds & enables the vertex attribute for OpenGL < 3.0.

This method is only used by SLGLVertexArray drawing methods for OpenGL contexts prior to 3.0 where vertex array objects did not exist. This is the additional overhead that had to be done per draw call.

◆ clear()

void SLGLVertexBuffer::clear ( )

Calls deleteGL & clears the attributes.

◆ deleteGL()

void SLGLVertexBuffer::deleteGL ( )

Deletes all vertex array & vertex buffer objects.

Deletes the OpenGL objects for the vertex array and the vertex buffer. The vector _attribs with the attribute information is not cleared.

◆ disableAttrib()

void SLGLVertexBuffer::disableAttrib ( )

disables the vertex attribute for OpenGL < 3.0

This method is only used by SLGLVertexArray drawing methods for OpenGL contexts prior to 3.0 where vertex array objects did not exist. This is the additional overhead that had to be done per draw call.

◆ generate()

void SLGLVertexBuffer::generate ( SLuint  numVertices,
SLGLBufferUsage  usage = BU_static,
SLbool  outputInterleaved = true 
)

Generates the VBO.

Generates the OpenGL VBO for one or more vertex attributes. If the input data is an interleaved array (all attribute data pointer where identical) also the output buffer will be generated as an interleaved array. Vertex arrays with attributes that are updated can not be interleaved. Vertex attributes with separate arrays can generate an interleaved or a sequential vertex buffer.


Sequential attribute layout:
| Positions | Normals | TexCoords |
Attribs: | Position0 | Position1 | Normal0 | Normal1 |TexCoord0|TexCoord1|
Elements: | PX | PY | PZ | PX | PY | PZ | NX | NY | NZ | NX | NY | NZ | TX | TY | TX | TY |
Bytes: |#### #### ####|#### #### ####|#### #### ####|#### #### ####|#### ####|#### ####|
| | |
|<------ offset Normals ----->| |
|<-------------------- offset TexCoords ------------------->|

Interleaved attribute layout:
| Vertex 0 | Vertex 1 |
Attribs: | Position0 | Normal0 |TexCoord0| Position1 | Normal1 |TexCoord1|
Elements: | PX | PY | PZ | NX | NY | NZ | TX | TY | PX | PY | PZ | NX | NY | NZ | TX | TY |
Bytes: |#### #### ####|#### #### ####|#### ####|#### #### ####|#### #### ####|#### ####|
| | | |
|<-offsetN=32->| | |
|<------- offsetTC=32 ------->| |
| |
|<---------- strideBytes=32 ----------->|

◆ id()

SLuint SLGLVertexBuffer::id ( ) const
inline

◆ outputInterleaved()

SLbool SLGLVertexBuffer::outputInterleaved ( ) const
inline

◆ size()

SLuint SLGLVertexBuffer::size ( ) const
inline

◆ sizeOfType()

SLuint SLGLVertexBuffer::sizeOfType ( SLGLBufferType  type)
static

static total size of all buffers in bytes

Returns the size in byte depending off the buffer type.

Returns the size of a buffer data type

◆ updateAttrib() [1/6]

void SLGLVertexBuffer::updateAttrib ( SLGLAttributeType  type,
SLint  elementSize,
void *  dataPointer 
)

Updates a specific vertex attribute in the VBO.

Updates the specified vertex attribute. This works only for sequential attributes and not for interleaved attributes. This is used e.g. for meshes with vertex skinning. See SLMesh::draw where we have joint attributes.

◆ updateAttrib() [2/6]

void SLGLVertexBuffer::updateAttrib ( SLGLAttributeType  type,
SLVfloat data 
)
inline

Updates a specific vertex attribute in the VBO.

◆ updateAttrib() [3/6]

void SLGLVertexBuffer::updateAttrib ( SLGLAttributeType  type,
SLVuint data 
)
inline

Updates a specific vertex attribute in the VBO.

◆ updateAttrib() [4/6]

void SLGLVertexBuffer::updateAttrib ( SLGLAttributeType  type,
SLVVec2f data 
)
inline

Updates a specific vertex attribute in the VBO.

◆ updateAttrib() [5/6]

void SLGLVertexBuffer::updateAttrib ( SLGLAttributeType  type,
SLVVec3f data 
)
inline

Updates a specific vertex attribute in the VBO.

◆ updateAttrib() [6/6]

void SLGLVertexBuffer::updateAttrib ( SLGLAttributeType  type,
SLVVec4f data 
)
inline

Updates a specific vertex attribute in the VBO.

Member Data Documentation

◆ _attribs

SLVVertexAttrib SLGLVertexBuffer::_attribs
protected

NO. of vertices in array.

◆ _id

SLuint SLGLVertexBuffer::_id
protected

◆ _numVertices

SLuint SLGLVertexBuffer::_numVertices
protected

OpenGL id of vertex buffer object.

◆ _outputInterleaved

SLbool SLGLVertexBuffer::_outputInterleaved
protected

Vector of vertex attributes.

◆ _sizeBytes

SLuint SLGLVertexBuffer::_sizeBytes
protected

Distance for interleaved attributes in bytes.

◆ _strideBytes

SLuint SLGLVertexBuffer::_strideBytes
protected

Flag if VBO should be generated interleaved.

◆ _usage

SLGLBufferUsage SLGLVertexBuffer::_usage
protected

Total size of float VBO in bytes.

◆ totalBufferCount

SLuint SLGLVertexBuffer::totalBufferCount = 0
static

◆ totalBufferSize

SLuint SLGLVertexBuffer::totalBufferSize = 0
static

static total no. of buffers in use


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