SLProject
4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
|
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... | |
SLuint | vaoID () const |
Returns either the VAO id or the VBO id. More... | |
SLuint | 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 | setAttrib (SLGLAttributeType type, SLint location, SLVVec4i *data) |
Adds a vertex attribute with vector of SLVec4i. 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 | setInstanceVBO (SLGLVertexBuffer *vbo, SLuint divisor=0) |
Attach a VBO that has been created outside of this VAO. 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, SLuint divisor=0) |
Generates the VA & VB objects for a NO. of vertices. More... | |
void | generateTF (SLuint numVertices, SLGLBufferUsage usage=BU_static, SLbool outputInterleaved=true, SLuint divisor=0) |
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 | drawElementsInstanced (SLGLPrimitiveType primitiveType, SLuint countInstance=0, SLuint numIndexes=0, SLuint indexOffset=0) |
Draws the VAO as an array with instance 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 |
SLGLVertexBuffer * | vbo () |
Static Public Attributes | |
static SLuint | totalDrawCalls = 0 |
static SLuint | totalPrimitivesRendered = 0 |
static total no. of draw calls More... | |
Protected Attributes | |
SLuint | _instances |
static total no. of primitives rendered More... | |
SLuint | _vaoID |
Number of instances of drawing. More... | |
SLuint | _tfoID |
OpenGL id of vertex array object. More... | |
SLuint | _numVertices |
OpenGL id of transform feedback object. More... | |
SLGLVertexBuffer | _vbo |
NO. of vertices in array. More... | |
SLuint | _idVBOIndices |
Vertex buffer object for float attributes. More... | |
size_t | _numIndicesElements |
OpenGL id of index vbo. More... | |
void * | _indexDataElements |
NO. of vertex indices in array for triangles, lines or points. More... | |
size_t | _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... | |
SLGLVertexBuffer * | _instanceVbo |
index data type (ubyte, ushort, uint) More... | |
SLuint | _instanceDivisor |
Vertex buffer object containing the positions for instanced drawing. 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 (_vbo). 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:
Definition at line 39 of file SLGLVertexArray.h.
SLGLVertexArray::SLGLVertexArray | ( | ) |
Constructor initializing with default values
Definition at line 22 of file SLGLVertexArray.cpp.
|
inline |
Definition at line 43 of file SLGLVertexArray.h.
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.
Definition at line 364 of file SLGLVertexArray.cpp.
|
inline |
Clears the attribute definition.
Definition at line 49 of file SLGLVertexArray.h.
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.
Definition at line 38 of file SLGLVertexArray.cpp.
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.
Definition at line 442 of file SLGLVertexArray.cpp.
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.
Definition at line 540 of file SLGLVertexArray.cpp.
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.
Definition at line 394 of file SLGLVertexArray.cpp.
void SLGLVertexArray::drawElementsInstanced | ( | SLGLPrimitiveType | primitiveType, |
SLuint | countInstances = 0 , |
||
SLuint | numIndexes = 0 , |
||
SLuint | indexOffset = 0 |
||
) |
Draws the VAO as an array with instance primitive type.
Wrapper around glDrawElementsInstanced using a second VBO (_instanceVbo) that contains all positions for the instances. This used e.g. for SLParticleSystems on systems without geometry shaders.
Definition at line 485 of file SLGLVertexArray.cpp.
void SLGLVertexArray::endTF | ( | ) |
End transform feedback.
We activate back the rendering and stop the transform feedback.
Definition at line 379 of file SLGLVertexArray.cpp.
void SLGLVertexArray::generate | ( | SLuint | numVertices, |
SLGLBufferUsage | usage = BU_static , |
||
SLbool | outputInterleaved = true , |
||
SLuint | divisor = 0 |
||
) |
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.
Definition at line 189 of file SLGLVertexArray.cpp.
void SLGLVertexArray::generateTF | ( | SLuint | numVertices, |
SLGLBufferUsage | usage = BU_static , |
||
SLbool | outputInterleaved = true , |
||
SLuint | divisor = 0 |
||
) |
Generates the VA & VB & TF objects.
Same as generate but with transform feedback
Definition at line 270 of file SLGLVertexArray.cpp.
|
inline |
Definition at line 206 of file SLGLVertexArray.h.
|
inline |
Definition at line 205 of file SLGLVertexArray.h.
|
inline |
Definition at line 204 of file SLGLVertexArray.h.
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.
Definition at line 66 of file SLGLVertexArray.cpp.
|
inline |
Adds a vertex attribute with vector of SLfloat.
Definition at line 74 of file SLGLVertexArray.h.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
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.
Definition at line 108 of file SLGLVertexArray.cpp.
|
inline |
Adds the index array for indexed element drawing with a vector of ubyte.
Definition at line 106 of file SLGLVertexArray.h.
|
inline |
Adds the index array for indexed element drawing with a vector of uint.
Definition at line 128 of file SLGLVertexArray.h.
|
inline |
Adds the index array for indexed element drawing with a vector of ushort.
Definition at line 117 of file SLGLVertexArray.h.
void SLGLVertexArray::setInstanceVBO | ( | SLGLVertexBuffer * | vbo, |
SLuint | divisor = 0 |
||
) |
Attach a VBO that has been created outside of this VAO.
Assignment of the additional VBO for instanced drawing. The passed vbo contains the positions for the instanced drawing done in drawElementsInstanced. This used e.g. for SLParticleSystems on systems without geometry shaders.
Definition at line 97 of file SLGLVertexArray.cpp.
|
inline |
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.
Definition at line 133 of file SLGLVertexArray.cpp.
|
inline |
Updates a specific vertex attribute in the VBO.
Definition at line 151 of file SLGLVertexArray.h.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Definition at line 207 of file SLGLVertexArray.h.
|
protected |
Vertex buffer object for float attributes.
Definition at line 219 of file SLGLVertexArray.h.
|
protected |
NO. of vertex indices in array for hard edges.
Definition at line 223 of file SLGLVertexArray.h.
|
protected |
NO. of vertex indices in array for triangles, lines or points.
Definition at line 221 of file SLGLVertexArray.h.
|
protected |
Pointer to index data for hard edges.
Definition at line 224 of file SLGLVertexArray.h.
|
protected |
Vertex buffer object containing the positions for instanced drawing.
Definition at line 226 of file SLGLVertexArray.h.
|
protected |
static total no. of primitives rendered
Definition at line 214 of file SLGLVertexArray.h.
|
protected |
index data type (ubyte, ushort, uint)
Definition at line 225 of file SLGLVertexArray.h.
|
protected |
Pointer to index data for elements.
Definition at line 222 of file SLGLVertexArray.h.
|
protected |
OpenGL id of index vbo.
Definition at line 220 of file SLGLVertexArray.h.
|
protected |
OpenGL id of transform feedback object.
Definition at line 217 of file SLGLVertexArray.h.
|
protected |
OpenGL id of vertex array object.
Definition at line 216 of file SLGLVertexArray.h.
|
protected |
Number of instances of drawing.
Definition at line 215 of file SLGLVertexArray.h.
|
protected |
NO. of vertices in array.
Definition at line 218 of file SLGLVertexArray.h.
|
static |
Definition at line 210 of file SLGLVertexArray.h.
|
static |
static total no. of draw calls
Definition at line 211 of file SLGLVertexArray.h.