SLProject 4.0.000
SLGLVertexArray Class Reference

SLGLVertexArray encapsulates the core OpenGL drawing. More...

#include <SLGLVertexArray.h>

Inheritance diagram for SLGLVertexArray:
[legend]

Public Member Functions

 SLGLVertexArray ()
 
 ~SLGLVertexArray ()
 
void deleteGL ()
 Deletes all vertex array & vertex buffer objects. More...
 
void clearAttribs ()
 Clears the attribute definition. More...
 
SLint vaoID () const
 Returns either the VAO id or the VBO id. More...
 
SLint tfoID () const
 Returns the TFO id. More...
 
void setAttrib (SLGLAttributeType type, SLint elementSize, SLint location, void *dataPointer, SLGLBufferType dataType=BT_float)
 Adds a vertex attribute with data pointer and an element size. More...
 
void setAttrib (SLGLAttributeType type, SLint location, SLVuint *data)
 Adds a vertex attribute with vector of SLuint. More...
 
void setAttrib (SLGLAttributeType type, SLint location, SLVfloat *data)
 Adds a vertex attribute with vector of SLfloat. More...
 
void setAttrib (SLGLAttributeType type, SLint location, SLVVec2f *data)
 Adds a vertex attribute with vector of SLVec2f. More...
 
void setAttrib (SLGLAttributeType type, SLint location, SLVVec3f *data)
 Adds a vertex attribute with vector of SLVec3f. More...
 
void setAttrib (SLGLAttributeType type, SLint location, SLVVec4f *data)
 Adds a vertex attribute with vector of SLVec4f. More...
 
void setIndices (SLuint numIndicesElements, SLGLBufferType indexDataType, void *indexDataElements, SLuint numIndicesEdges=0, void *indexDataEdges=nullptr)
 Adds the index array for indexed element drawing. More...
 
void setIndices (SLVubyte *indicesElements, SLVubyte *indicesEdges=nullptr)
 Adds the index array for indexed element drawing with a vector of ubyte. More...
 
void setIndices (SLVushort *indicesElements, SLVushort *indicesEdges=nullptr)
 Adds the index array for indexed element drawing with a vector of ushort. More...
 
void setIndices (SLVuint *indicesElements, SLVuint *indicesEdges=nullptr)
 Adds the index array for indexed element drawing with a vector of uint. 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 VA & VB objects for a NO. of vertices. More...
 
void generateTF (SLuint numVertices, SLGLBufferUsage usage=BU_static, SLbool outputInterleaved=true)
 Generates the VA & VB & TF objects. More...
 
void beginTF (SLuint tfoID)
 Begin transform feedback. More...
 
void endTF ()
 End transform feedback. More...
 
void drawElementsAs (SLGLPrimitiveType primitiveType, SLuint numIndexes=0, SLuint indexOffsetBytes=0)
 Draws the VAO by element indices with a primitive type. More...
 
void drawArrayAs (SLGLPrimitiveType primitiveType, SLint firstVertex=0, SLsizei countVertices=0)
 Draws the VAO as an array with a primitive type. More...
 
void drawEdges (SLCol4f color, SLfloat lineWidth=1.0f)
 Draws the hard edges of the VAO with the edge indices. More...
 
SLuint numVertices () const
 
SLuint numIndicesElements () const
 
SLuint numIndicesEdges () const
 

Static Public Attributes

static SLuint totalDrawCalls = 0
 
static SLuint totalPrimitivesRendered = 0
 static total no. of draw calls More...
 

Protected Attributes

SLuint _vaoID
 static total no. of primitives rendered More...
 
SLuint _tfoID
 OpenGL id of vertex array object. More...
 
SLuint _numVertices
 OpenGL id of transform feedback object. More...
 
SLGLVertexBuffer _VBOf
 NO. of vertices in array. More...
 
SLuint _idVBOIndices
 Vertex buffer object for float attributes. More...
 
SLuint _numIndicesElements
 OpenGL id of index vbo. More...
 
void * _indexDataElements
 NO. of vertex indices in array for triangles, lines or points. More...
 
SLuint _numIndicesEdges
 Pointer to index data for elements. More...
 
void * _indexDataEdges
 NO. of vertex indices in array for hard edges. More...
 
SLGLBufferType _indexDataType
 Pointer to index data for hard edges. More...
 

Detailed Description

SLGLVertexArray encapsulates the core OpenGL drawing.

An SLGLVertexArray instance handles all OpenGL drawing with an OpenGL Vertex Array Object (VAO), a vertex buffer objects (VBO) for the attributes and an index buffer for element drawing. Attributes can be stored in a float VBO of type SLGLVertexBuffer.
VAOs where introduces OpenGL 3.0 and reduce the overhead per draw call. All vertex attributes (e.g. position, normals, texture coords, etc.) must be float at the input. All float attributes will be in one VBO (_VBOf). Vertices can be drawn either directly as in the array (SLGLVertexArray::drawArrayAs) or by element (SLGLVertexArray::drawElementsAs) with a separate indices buffer.
The setup of a VAO has multiple steps:

Constructor & Destructor Documentation

◆ SLGLVertexArray()

SLGLVertexArray::SLGLVertexArray ( )

Constructor initializing with default values

◆ ~SLGLVertexArray()

SLGLVertexArray::~SLGLVertexArray ( )
inline

Member Function Documentation

◆ beginTF()

void SLGLVertexArray::beginTF ( SLuint  tfoID)

Begin transform feedback.

Discard the rendering because we just compute next position with the transform feedback. We need to bind a transform feedback object but not the same from this vao, because we want to read from one vao and write on another.

◆ clearAttribs()

void SLGLVertexArray::clearAttribs ( )
inline

Clears the attribute definition.

◆ deleteGL()

void SLGLVertexArray::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.

◆ drawArrayAs()

void SLGLVertexArray::drawArrayAs ( SLGLPrimitiveType  primitiveType,
SLint  firstVertex = 0,
SLsizei  countVertices = 0 
)

Draws the VAO as an array with a primitive type.

Draws the vertex attributes as a specified primitive type as the vertices are defined in the attribute arrays.

◆ drawEdges()

void SLGLVertexArray::drawEdges ( SLCol4f  color,
SLfloat  lineWidth = 1.0f 
)

Draws the hard edges of the VAO with the edge indices.

Draws the hard edges with the specified color. The VAO has no or one active index buffer. For drawArrayAs no indices are needed. For drawElementsAs the index buffer is used. For triangle meshes also hard edges are generated. Their indices are stored behind the indices of the triangles.

◆ drawElementsAs()

void SLGLVertexArray::drawElementsAs ( SLGLPrimitiveType  primitiveType,
SLuint  numIndexes = 0,
SLuint  indexOffset = 0 
)

Draws the VAO by element indices with a primitive type.

Draws the vertex attributes as a specified primitive type by elements with the indices from the index buffer defined in setIndices.

◆ endTF()

void SLGLVertexArray::endTF ( )

End transform feedback.

We activate back the rendering and stop the transform feedback.

◆ generate()

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

Generates the VA & VB objects for a NO. of vertices.

Generates the OpenGL objects for the vertex array and the vertex buffer object. 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 | UV1_0 | UV1_1 |
Elements: | PX | PY | PZ | PX | PY | PZ | NX | NY | NZ | NX | NY | NZ | TX | TY | TX | TY |
Bytes: |#### #### ####|#### #### ####|#### #### ####|#### #### ####|#### ####|#### ####|
| | |
|<------ offset Normals ----->| |
|<----------------------- offset UVs ---------------------->|

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

The VAO has no or one active index buffer. For drawArrayAs no indices are needed. For drawElementsAs the index buffer is used. For triangle meshes also hard edges are generated. Their indices are stored behind the indices of the triangles.

◆ generateTF()

void SLGLVertexArray::generateTF ( SLuint  numVertices,
SLGLBufferUsage  usage = BU_static,
SLbool  outputInterleaved = true 
)

Generates the VA & VB & TF objects.

Same as generate but with transform feedback

◆ numIndicesEdges()

SLuint SLGLVertexArray::numIndicesEdges ( ) const
inline

◆ numIndicesElements()

SLuint SLGLVertexArray::numIndicesElements ( ) const
inline

◆ numVertices()

SLuint SLGLVertexArray::numVertices ( ) const
inline

◆ setAttrib() [1/6]

void SLGLVertexArray::setAttrib ( SLGLAttributeType  type,
SLint  elementSize,
SLint  location,
void *  dataPointer,
SLGLBufferType  dataType = BT_float 
)

Adds a vertex attribute with data pointer and an element size.

Defines a vertex attribute for the later generation. It must be of a specific SLVertexAttribType. Each attribute can appear only once in an vertex array. If all attributes of a vertex array have the same data pointer the data input will be interpreted as an interleaved array. See example in SLGLOculus::init. Be aware that the VBO for the attribute will not be generated until generate is called. The data pointer must still be valid when SLGLVertexArray::generate is called.

◆ setAttrib() [2/6]

void SLGLVertexArray::setAttrib ( SLGLAttributeType  type,
SLint  location,
SLVfloat data 
)
inline

Adds a vertex attribute with vector of SLfloat.

◆ setAttrib() [3/6]

void SLGLVertexArray::setAttrib ( SLGLAttributeType  type,
SLint  location,
SLVuint data 
)
inline

Adds a vertex attribute with vector of SLuint.

◆ setAttrib() [4/6]

void SLGLVertexArray::setAttrib ( SLGLAttributeType  type,
SLint  location,
SLVVec2f data 
)
inline

Adds a vertex attribute with vector of SLVec2f.

◆ setAttrib() [5/6]

void SLGLVertexArray::setAttrib ( SLGLAttributeType  type,
SLint  location,
SLVVec3f data 
)
inline

Adds a vertex attribute with vector of SLVec3f.

◆ setAttrib() [6/6]

void SLGLVertexArray::setAttrib ( SLGLAttributeType  type,
SLint  location,
SLVVec4f data 
)
inline

Adds a vertex attribute with vector of SLVec4f.

◆ setIndices() [1/4]

void SLGLVertexArray::setIndices ( SLuint  numIndicesElements,
SLGLBufferType  indexDataType,
void *  indexDataElements,
SLuint  numIndicesEdges = 0,
void *  indexDataEdges = nullptr 
)

Adds the index array for indexed element drawing.

Defines the vertex indices for the element drawing. Without indices vertex array can only be drawn with SLGLVertexArray::drawArrayAs. Be aware that the VBO for the indices will not be generated until generate is called. The data pointer must still be valid when generate is called.

◆ setIndices() [2/4]

void SLGLVertexArray::setIndices ( SLVubyte indicesElements,
SLVubyte indicesEdges = nullptr 
)
inline

Adds the index array for indexed element drawing with a vector of ubyte.

◆ setIndices() [3/4]

void SLGLVertexArray::setIndices ( SLVuint indicesElements,
SLVuint indicesEdges = nullptr 
)
inline

Adds the index array for indexed element drawing with a vector of uint.

◆ setIndices() [4/4]

void SLGLVertexArray::setIndices ( SLVushort indicesElements,
SLVushort indicesEdges = nullptr 
)
inline

Adds the index array for indexed element drawing with a vector of ushort.

◆ tfoID()

SLint SLGLVertexArray::tfoID ( ) const
inline

Returns the TFO id.

◆ updateAttrib() [1/6]

void SLGLVertexArray::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 SLGLVertexArray::updateAttrib ( SLGLAttributeType  type,
SLVfloat data 
)
inline

Updates a specific vertex attribute in the VBO.

◆ updateAttrib() [3/6]

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

Updates a specific vertex attribute in the VBO.

◆ updateAttrib() [4/6]

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

Updates a specific vertex attribute in the VBO.

◆ updateAttrib() [5/6]

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

Updates a specific vertex attribute in the VBO.

◆ updateAttrib() [6/6]

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

Updates a specific vertex attribute in the VBO.

◆ vaoID()

SLint SLGLVertexArray::vaoID ( ) const
inline

Returns either the VAO id or the VBO id.

Member Data Documentation

◆ _idVBOIndices

SLuint SLGLVertexArray::_idVBOIndices
protected

Vertex buffer object for float attributes.

◆ _indexDataEdges

void* SLGLVertexArray::_indexDataEdges
protected

NO. of vertex indices in array for hard edges.

◆ _indexDataElements

void* SLGLVertexArray::_indexDataElements
protected

NO. of vertex indices in array for triangles, lines or points.

◆ _indexDataType

SLGLBufferType SLGLVertexArray::_indexDataType
protected

Pointer to index data for hard edges.

◆ _numIndicesEdges

SLuint SLGLVertexArray::_numIndicesEdges
protected

Pointer to index data for elements.

◆ _numIndicesElements

SLuint SLGLVertexArray::_numIndicesElements
protected

OpenGL id of index vbo.

◆ _numVertices

SLuint SLGLVertexArray::_numVertices
protected

OpenGL id of transform feedback object.

◆ _tfoID

SLuint SLGLVertexArray::_tfoID
protected

OpenGL id of vertex array object.

◆ _vaoID

SLuint SLGLVertexArray::_vaoID
protected

static total no. of primitives rendered

◆ _VBOf

SLGLVertexBuffer SLGLVertexArray::_VBOf
protected

NO. of vertices in array.

◆ totalDrawCalls

SLuint SLGLVertexArray::totalDrawCalls = 0
static

◆ totalPrimitivesRendered

SLuint SLGLVertexArray::totalPrimitivesRendered = 0
static

static total no. of draw calls


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