Developer Documentation
|
Class to define the vertex input layout. More...
#include <OpenFlipper/libs_required/ACG/GL/VertexDeclaration.hh>
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 |
bool | operator== (const VertexDeclaration &_other) const |
bool | operator!= (const VertexDeclaration &_other) const |
Static Public Member Functions | |
static size_t | getGLTypeSize (unsigned int _type) |
static size_t | 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 268 of file VertexDeclaration.hh.
void ACG::VertexDeclaration::activateFixedFunction | ( | ) | const |
prepare OpenGL to use a vertex buffer with this declaration -> uses the fixed function pointers (glVertexPointer, glColorPointer...)
Definition at line 361 of file VertexDeclaration.cc.
void ACG::VertexDeclaration::activateShaderPipeline | ( | GLSL::Program * | _prog | ) | const |
prepare OpenGL to use a vertex buffer with this declaration -> uses shader attribute pointers ( glVertexAttribPointer )
Definition at line 429 of file VertexDeclaration.cc.
void ACG::VertexDeclaration::addElement | ( | const VertexElement * | _pElement | ) |
append one element to declaration
Definition at line 115 of file VertexDeclaration.cc.
void 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
Definition at line 120 of file VertexDeclaration.cc.
void 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
Definition at line 142 of file VertexDeclaration.cc.
void ACG::VertexDeclaration::addElements | ( | unsigned int | _numElements, |
const VertexElement * | _pElements | ||
) |
append multiple element declarations
Definition at line 166 of file VertexDeclaration.cc.
void ACG::VertexDeclaration::clear | ( | ) |
remove all vertex elements, also clears the user defined stride flag
Definition at line 570 of file VertexDeclaration.cc.
void ACG::VertexDeclaration::deactivateFixedFunction | ( | ) | const |
disables vertex attributes to prevent any draw related crashes
Definition at line 407 of file VertexDeclaration.cc.
void ACG::VertexDeclaration::deactivateShaderPipeline | ( | GLSL::Program * | _prog | ) | const |
disables this vertex declaration to prevent any draw related crashes -> calls glDisableVertexAttribArray
Definition at line 486 of file VertexDeclaration.cc.
const VertexElement * ACG::VertexDeclaration::findElementByUsage | ( | VERTEX_USAGE | _usage | ) | const |
find element ptr by usage, return 0 if not found
Definition at line 534 of file VertexDeclaration.cc.
int ACG::VertexDeclaration::findElementIdByUsage | ( | VERTEX_USAGE | _usage | ) | const |
find element id by usage, return -1 if not found
Definition at line 525 of file VertexDeclaration.cc.
const VertexElement * ACG::VertexDeclaration::getElement | ( | unsigned int | i | ) | const |
get the i'th vertex element desc
Definition at line 519 of file VertexDeclaration.cc.
|
static |
get size of one vertex element
Definition at line 349 of file VertexDeclaration.cc.
|
static |
get size of GL_FLOAT, GL_INT ...
Definition at line 315 of file VertexDeclaration.cc.
unsigned int ACG::VertexDeclaration::getNumElements | ( | ) | const |
get num of vertex elements
Definition at line 309 of file VertexDeclaration.cc.
unsigned int ACG::VertexDeclaration::getVertexStride | ( | unsigned int | i = 0 | ) | const |
get vertex size (for element i, for multi vbo support)
Definition at line 545 of file VertexDeclaration.cc.
|
inline |
comparison operator
Definition at line 365 of file VertexDeclaration.hh.
bool ACG::VertexDeclaration::operator== | ( | const VertexDeclaration & | _other | ) | const |
comparison operator
Definition at line 640 of file VertexDeclaration.cc.
void ACG::VertexDeclaration::setVertexStride | ( | unsigned int | _stride | ) |
set vertex stride manually, otherwise it is computed from the vertex elements
Definition at line 564 of file VertexDeclaration.cc.
|
static |
Check hw support for streaming instance data from vbo
Definition at line 655 of file VertexDeclaration.cc.
QString ACG::VertexDeclaration::toString | ( | ) | const |
Returns a string describing the vertex format for debugging purpose.
Definition at line 580 of file VertexDeclaration.cc.
|
private |
automatically computes byte offset for interleaved vertex elements and computes vertex stride
Definition at line 233 of file VertexDeclaration.cc.
|
private |
automatically sets shader input name on passed element, if not provided
Definition at line 282 of file VertexDeclaration.cc.