Developer Documentation
VertexDeclaration.hh
1 /*===========================================================================*\
2  * *
3  * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39  * *
40 \*===========================================================================*/
41 
42 
43 
44 
45 #ifndef ACG_VERTEXDECLARATION_HH
46 #define ACG_VERTEXDECLARATION_HH
47 
48 #include <vector>
49 #include <list>
50 #include <map>
51 #include <QString>
52 #include <ACG/Config/ACGDefines.hh>
53 
54 namespace GLSL
55 {
56  class Program;
57 }
58 
59 namespace ACG
60 {
61 
64 {
72  VERTEX_USAGE_FORCE_DWORD = 0xFFFFFFFF
73 };
74 
78 struct ACGDLLEXPORT VertexElement
79 {
80  VertexElement();
81 
82  unsigned int type_;
83  unsigned int numElements_;
85  const char* shaderInputName_;
86  const void* pointer_;
87  unsigned int divisor_;
88  unsigned int vbo_;
89 
92  void setByteOffset(unsigned int _offset);
93 
96  unsigned int getByteOffset() const;
97 
100  bool operator == (const VertexElement& _other) const;
101 
104  bool operator != (const VertexElement& _other) const {return !(*this == _other);}
105 };
106 
268 class ACGDLLEXPORT VertexDeclaration
269 {
270 public:
271 
274 
277  void addElement(const VertexElement* _pElement);
278 
281  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);
282 
285  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);
286 
289  void addElements(unsigned int _numElements, const VertexElement* _pElements);
290 
293  void clear();
294 
298  void activateFixedFunction() const;
299 
302  void deactivateFixedFunction() const;
303 
304 
308  void activateShaderPipeline(GLSL::Program* _prog) const;
309 
310 
314  void deactivateShaderPipeline(GLSL::Program* _prog) const;
315 
316 
320  void setVertexStride(unsigned int _stride);
321 
324  unsigned int getVertexStride(unsigned int i = 0) const;
325 
328  unsigned int getNumElements() const;
329 
332  const VertexElement* getElement(unsigned int i) const;
333 
336  int findElementIdByUsage(VERTEX_USAGE _usage) const;
337 
340  const VertexElement* findElementByUsage(VERTEX_USAGE _usage) const;
341 
344  static size_t getGLTypeSize(unsigned int _type);
345 
348  static size_t getElementSize(const VertexElement* _pElement);
349 
352  static bool supportsInstancedArrays();
353 
356  QString toString() const;
357 
358 
361  bool operator ==(const VertexDeclaration& _other) const;
362 
365  bool operator !=(const VertexDeclaration& _other) const {return !(*this == _other);}
366 
367 private:
368 
373  void updateOffsets();
374 
378  void updateShaderInputName(VertexElement* _pElem);
379 
380 
381  std::vector<VertexElement> elements_;
382 
384  unsigned int vertexStride_;
385 
387  std::map<unsigned int, unsigned int> vertexStridesVBO_;
388 
391 };
392 
393 
394 //=============================================================================
395 } // namespace ACG
396 //=============================================================================
397 
398 
399 
400 #endif // ACG_VERTEXDECLARATION_HH defined
This namespace contains all the classes and functions for handling GLSL shader and program objects...
Definition: AntiAliasing.hh:66
Namespace providing different geometric functions concerning angles.
Class to define the vertex input layout.
unsigned int vertexStride_
Offset in bytes between each vertex.
defined by user via VertexElement::shaderInputName_
unsigned int divisor_
For instanced rendering: Step rate describing how many instances are drawn before advancing to the ne...
GLSL program class.
Definition: GLSLShader.hh:211
VERTEX_USAGE usage_
position, normal, shader input ..
const char * shaderInputName_
set shader input name, if usage_ = VERTEX_USAGE_USER_DEFINED otherwise this is set automatically...
VERTEX_USAGE
-— input name in vertex shader ----—
Description of one vertex element.
const void * pointer_
Offset in bytes to the first occurrence of this element in vertex buffer; Or address to vertex data i...
unsigned int vbo_
Explicit vbo source of this element, set to 0 if the buffer bound at the time of activating the decla...
unsigned int numElements_
how many elements of type_
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. ...
unsigned int type_
GL_FLOAT, GL_UNSIGNED_BYTE, GL_INT, ...