Developer Documentation
|
Class to define the vertex input layout. More...
Public Member Functions | |
void | addElement (const VertexElement *_pElement) |
void | addElement (unsigned int _type, unsigned int _numElements, VERTEX_USAGE _usage, const void *_pointer, const char *_shaderInputName=0, unsigned int _divisor=0, unsigned int _vbo=0) |
void | addElement (unsigned int _type, unsigned int _numElements, VERTEX_USAGE _usage, size_t _byteOffset=0, const char *_shaderInputName=0, unsigned int _divisor=0, unsigned int _vbo=0) |
void | addElements (unsigned int _numElements, const VertexElement *_pElements) |
void | clear () |
void | activateFixedFunction () const |
void | deactivateFixedFunction () const |
void | activateShaderPipeline (GLSL::Program *_prog) const |
void | deactivateShaderPipeline (GLSL::Program *_prog) const |
void | setVertexStride (unsigned int _stride) |
unsigned int | getVertexStride (unsigned int i=0) const |
unsigned int | getNumElements () const |
const VertexElement * | getElement (unsigned int i) const |
int | findElementIdByUsage (VERTEX_USAGE _usage) const |
const VertexElement * | findElementByUsage (VERTEX_USAGE _usage) const |
QString | toString () const |
Static Public Member Functions | |
static unsigned int | getGLTypeSize (unsigned int _type) |
static unsigned int | getElementSize (const VertexElement *_pElement) |
static bool | supportsInstancedArrays () |
Private Member Functions | |
void | updateOffsets () |
void | updateShaderInputName (VertexElement *_pElem) |
Private Attributes | |
std::vector< VertexElement > | elements_ |
unsigned int | vertexStride_ |
Offset in bytes between each vertex. | |
std::map< unsigned int, unsigned int > | vertexStridesVBO_ |
Map vbo to offset in bytes between each vertex in that vbo. | |
int | strideUserDefined_ |
Flag that indicates, whether the stride was set by user or derived automatically. | |
Class to define the vertex input layout.
This class is used to specify vertex data layout (normals,positions,...).
The layout of a vertex buffer typically includes:
Example usage: Interleaved vertex data
Create a vertex declaration given the following vertex data:
The accompanying vertex declaration is created as follows:
Note that the element offsets are automatically computed, but it is possible to provide them manually of course.
These elements are then available in a vertex shader with the following input semantics:
VERTEX_USAGE_SHADER_INPUT is ignored in fixed function pipeline
Example usage: Multiple source buffers in system memory
Given are system memory buffers as vertex data source for drawing:
It is important that the vertex stride is manually set to 0!! and that the element data pointers are set accordingly:
Note:
Example usage: Instancing from vbo
Geometry instancing can be implemented in several ways:
The first two methods can be implemented without modifying the vertex declaration, so this example focuses on the last method, in which instance data is streamed from a vbo.
Given a mesh with the following vertex elements:
Each instance of this mesh should have a different world transform and a different color. So the per instance data is:
This per instance data is stored in a separate GL_ARRAY_BUFFER vbo.
So there are two vbos involved in the draw call: geometryVBO - stores static Vertex data of the mesh instanceVBO - stores InstanceData for each instance
The vertex declaration for the instanced draw call is initialized as follows:
The 4x4 modelview matrix has to be split up into float4 elements.
Using this setup, a call to decl.activateShaderPipeline() is enough to prepare an instanced draw call.
Finally, instancing requires a customized vertex shader that makes use of the per instance data:
Definition at line 266 of file MeshNode2T.cc.
void ACG::SceneGraph::ACG::VertexDeclaration::activateFixedFunction | ( | ) | const |
prepare OpenGL to use a vertex buffer with this declaration -> uses the fixed function pointers (glVertexPointer, glColorPointer...)
void ACG::SceneGraph::ACG::VertexDeclaration::activateShaderPipeline | ( | GLSL::Program * | _prog | ) | const |
prepare OpenGL to use a vertex buffer with this declaration -> uses shader attribute pointers ( glVertexAttribPointer )
void ACG::SceneGraph::ACG::VertexDeclaration::addElement | ( | const VertexElement * | _pElement | ) |
append one element to declaration
void ACG::SceneGraph::ACG::VertexDeclaration::addElement | ( | unsigned int | _type, |
unsigned int | _numElements, | ||
VERTEX_USAGE | _usage, | ||
const void * | _pointer, | ||
const char * | _shaderInputName = 0 , |
||
unsigned int | _divisor = 0 , |
||
unsigned int | _vbo = 0 |
||
) |
append one element to declarations, direct method
void ACG::SceneGraph::ACG::VertexDeclaration::addElement | ( | unsigned int | _type, |
unsigned int | _numElements, | ||
VERTEX_USAGE | _usage, | ||
size_t | _byteOffset = 0 , |
||
const char * | _shaderInputName = 0 , |
||
unsigned int | _divisor = 0 , |
||
unsigned int | _vbo = 0 |
||
) |
append one element to declarations, direct method
void ACG::SceneGraph::ACG::VertexDeclaration::addElements | ( | unsigned int | _numElements, |
const VertexElement * | _pElements | ||
) |
append multiple element declarations
void ACG::SceneGraph::ACG::VertexDeclaration::clear | ( | ) |
remove all vertex elements, also clears the user defined stride flag
void ACG::SceneGraph::ACG::VertexDeclaration::deactivateFixedFunction | ( | ) | const |
disables vertex attributes to prevent any draw related crashes
void ACG::SceneGraph::ACG::VertexDeclaration::deactivateShaderPipeline | ( | GLSL::Program * | _prog | ) | const |
disables this vertex declaration to prevent any draw related crashes -> calls glDisableVertexAttribArray
const VertexElement* ACG::SceneGraph::ACG::VertexDeclaration::findElementByUsage | ( | VERTEX_USAGE | _usage | ) | const |
find element ptr by usage, return 0 if not found
int ACG::SceneGraph::ACG::VertexDeclaration::findElementIdByUsage | ( | VERTEX_USAGE | _usage | ) | const |
find element id by usage, return -1 if not found
const VertexElement* ACG::SceneGraph::ACG::VertexDeclaration::getElement | ( | unsigned int | i | ) | const |
get the i'th vertex element desc
|
static |
get size of one vertex element
|
static |
get size of GL_FLOAT, GL_INT ...
unsigned int ACG::SceneGraph::ACG::VertexDeclaration::getNumElements | ( | ) | const |
get num of vertex elements
unsigned int ACG::SceneGraph::ACG::VertexDeclaration::getVertexStride | ( | unsigned int | i = 0 | ) | const |
get vertex size (for element i, for multi vbo support)
void ACG::SceneGraph::ACG::VertexDeclaration::setVertexStride | ( | unsigned int | _stride | ) |
set vertex stride manually, otherwise it is computed from the vertex elements
|
static |
Check hw support for streaming instance data from vbo
QString ACG::SceneGraph::ACG::VertexDeclaration::toString | ( | ) | const |
Returns a string describing the vertex format for debugging purpose.
|
private |
automatically computes byte offset for interleaved vertex elements and computes vertex stride
|
private |
automatically sets shader input name on passed element, if not provided