SLProject
4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
|
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 (SLuint divisor=0) const |
Binds & enables the vertex attribute for OpenGL < 3.0 and during VAO creation. More... | |
void | disableAttrib () |
disables the vertex attribute for OpenGL < 3.0 More... | |
SLuint | id () const |
SLuint | size () const |
SLVVertexAttrib & | attribs () |
SLbool | outputIsInterleaved () 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 | _outputIsInterleaved |
Vector of vertex attributes. More... | |
SLbool | _inputIsInterleaved |
Flag if VBO should be generated interleaved. 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... | |
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.
Definition at line 44 of file SLGLVertexBuffer.h.
SLGLVertexBuffer::SLGLVertexBuffer | ( | ) |
Constructor initializing with default values.
Definition at line 19 of file SLGLVertexBuffer.cpp.
|
inline |
Definition at line 48 of file SLGLVertexBuffer.h.
SLint SLGLVertexBuffer::attribIndex | ( | SLGLAttributeType | type | ) |
Returns the vector index if a vertex attribute exists otherwise -1.
Definition at line 48 of file SLGLVertexBuffer.cpp.
|
inline |
Definition at line 98 of file SLGLVertexBuffer.h.
Binds & enables the vertex attribute for OpenGL < 3.0 and during VAO creation.
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. For VAO (Vertex Array Objects) this method is only used once at the creation of the VAO. The instanceDivisor number is only used for instanced drawing. For all other usage it is by default 0.
Definition at line 268 of file SLGLVertexBuffer.cpp.
void SLGLVertexBuffer::clear | ( | ) |
Calls deleteGL & clears the attributes.
Definition at line 42 of file SLGLVertexBuffer.cpp.
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.
Definition at line 31 of file SLGLVertexBuffer.cpp.
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.
Definition at line 351 of file SLGLVertexBuffer.cpp.
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 ----------->|
Definition at line 122 of file SLGLVertexBuffer.cpp.
|
inline |
Definition at line 96 of file SLGLVertexBuffer.h.
|
inline |
Definition at line 99 of file SLGLVertexBuffer.h.
|
inline |
Definition at line 97 of file SLGLVertexBuffer.h.
|
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
Definition at line 362 of file SLGLVertexBuffer.cpp.
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.
Definition at line 60 of file SLGLVertexBuffer.cpp.
|
inline |
Updates a specific vertex attribute in the VBO.
Definition at line 69 of file SLGLVertexBuffer.h.
|
inline |
|
inline |
|
inline |
|
inline |
|
protected |
NO. of vertices in array.
Definition at line 113 of file SLGLVertexBuffer.h.
|
protected |
Definition at line 111 of file SLGLVertexBuffer.h.
|
protected |
Flag if VBO should be generated interleaved.
Definition at line 115 of file SLGLVertexBuffer.h.
|
protected |
OpenGL id of vertex buffer object.
Definition at line 112 of file SLGLVertexBuffer.h.
|
protected |
Vector of vertex attributes.
Definition at line 114 of file SLGLVertexBuffer.h.
|
protected |
Distance for interleaved attributes in bytes.
Definition at line 117 of file SLGLVertexBuffer.h.
|
protected |
Flag if VBO should be generated interleaved.
Definition at line 116 of file SLGLVertexBuffer.h.
|
protected |
Total size of float VBO in bytes.
Definition at line 118 of file SLGLVertexBuffer.h.
|
static |
Definition at line 104 of file SLGLVertexBuffer.h.
|
static |
static total no. of buffers in use
Definition at line 105 of file SLGLVertexBuffer.h.