SLProject 4.0.000
|
SLGLVertexArray encapsulates the core OpenGL drawing. More...
#include <SLGLVertexArray.h>
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... | |
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:
SLGLVertexArray::SLGLVertexArray | ( | ) |
Constructor initializing with default values
|
inline |
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.
|
inline |
Clears the attribute definition.
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.
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.
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.
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.
void SLGLVertexArray::endTF | ( | ) |
End transform feedback.
We activate back the rendering and stop the transform feedback.
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.
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
|
inline |
|
inline |
|
inline |
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.
|
inline |
Adds a vertex attribute with vector of SLfloat.
|
inline |
Adds a vertex attribute with vector of SLuint.
|
inline |
Adds a vertex attribute with vector of SLVec2f.
|
inline |
Adds a vertex attribute with vector of SLVec3f.
|
inline |
Adds a vertex attribute with vector of SLVec4f.
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.
|
inline |
Adds the index array for indexed element drawing with a vector of ubyte.
|
inline |
Adds the index array for indexed element drawing with a vector of uint.
|
inline |
Adds the index array for indexed element drawing with a vector of ushort.
|
inline |
Returns the TFO id.
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.
|
inline |
Updates a specific vertex attribute in the VBO.
|
inline |
Updates a specific vertex attribute in the VBO.
|
inline |
Updates a specific vertex attribute in the VBO.
|
inline |
Updates a specific vertex attribute in the VBO.
|
inline |
Updates a specific vertex attribute in the VBO.
|
inline |
Returns either the VAO id or the VBO id.
|
protected |
Vertex buffer object for float attributes.
|
protected |
NO. of vertex indices in array for hard edges.
|
protected |
NO. of vertex indices in array for triangles, lines or points.
|
protected |
Pointer to index data for hard edges.
|
protected |
Pointer to index data for elements.
|
protected |
OpenGL id of index vbo.
|
protected |
OpenGL id of transform feedback object.
|
protected |
OpenGL id of vertex array object.
|
protected |
static total no. of primitives rendered
|
protected |
NO. of vertices in array.
|
static |
|
static |
static total no. of draw calls