Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
VertexDeclaration.hh
1 /*===========================================================================*\
2  * *
3  * OpenFlipper *
4  * Copyright (C) 2001-2014 by Computer Graphics Group, RWTH Aachen *
5  * www.openflipper.org *
6  * *
7  *---------------------------------------------------------------------------*
8  * This file is part of OpenFlipper. *
9  * *
10  * OpenFlipper is free software: you can redistribute it and/or modify *
11  * it under the terms of the GNU Lesser General Public License as *
12  * published by the Free Software Foundation, either version 3 of *
13  * the License, or (at your option) any later version with the *
14  * following exceptions: *
15  * *
16  * If other files instantiate templates or use macros *
17  * or inline functions from this file, or you compile this file and *
18  * link it with other files to produce an executable, this file does *
19  * not by itself cause the resulting executable to be covered by the *
20  * GNU Lesser General Public License. This exception does not however *
21  * invalidate any other reasons why the executable file might be *
22  * covered by the GNU Lesser General Public License. *
23  * *
24  * OpenFlipper is distributed in the hope that it will be useful, *
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
27  * GNU Lesser General Public License for more details. *
28  * *
29  * You should have received a copy of the GNU LesserGeneral Public *
30  * License along with OpenFlipper. If not, *
31  * see <http://www.gnu.org/licenses/>. *
32  * *
33 \*===========================================================================*/
34 
35 /*===========================================================================*\
36  * *
37  * $Revision: 20108 $ *
38  * $Author: tenter $ *
39  * $Date: 2015-01-08 14:00:50 +0100 (Thu, 08 Jan 2015) $ *
40  * *
41 \*===========================================================================*/
42 
43 
44 #ifndef ACG_VERTEXDECLARATION_HH
45 #define ACG_VERTEXDECLARATION_HH
46 
47 #include <vector>
48 #include <list>
49 #include <map>
50 #include <QString>
51 #include <ACG/Config/ACGDefines.hh>
52 
53 namespace GLSL
54 {
55  class Program;
56 }
57 
58 namespace ACG
59 {
60 
63 {
71  VERTEX_USAGE_FORCE_DWORD = 0xFFFFFFFF
72 };
73 
77 struct ACGDLLEXPORT VertexElement
78 {
79  VertexElement();
80 
81  unsigned int type_;
82  unsigned int numElements_;
84  const char* shaderInputName_;
85  const void* pointer_;
86  unsigned int divisor_;
87  unsigned int vbo_;
88 
91  void setByteOffset(unsigned int _offset);
92 
95  unsigned int getByteOffset() const;
96 };
97 
259 class ACGDLLEXPORT VertexDeclaration
260 {
261 public:
262 
265 
268  void addElement(const VertexElement* _pElement);
269 
272  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);
273 
276  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);
277 
280  void addElements(unsigned int _numElements, const VertexElement* _pElements);
281 
284  void clear();
285 
289  void activateFixedFunction() const;
290 
293  void deactivateFixedFunction() const;
294 
295 
299  void activateShaderPipeline(GLSL::Program* _prog) const;
300 
301 
305  void deactivateShaderPipeline(GLSL::Program* _prog) const;
306 
307 
311  void setVertexStride(unsigned int _stride);
312 
315  unsigned int getVertexStride(unsigned int i = 0) const;
316 
319  unsigned int getNumElements() const;
320 
323  const VertexElement* getElement(unsigned int i) const;
324 
327  int findElementIdByUsage(VERTEX_USAGE _usage) const;
328 
331  const VertexElement* findElementByUsage(VERTEX_USAGE _usage) const;
332 
335  static unsigned int getGLTypeSize(unsigned int _type);
336 
339  static unsigned int getElementSize(const VertexElement* _pElement);
340 
343  static bool supportsInstancedArrays();
344 
347  QString toString() const;
348 
349 private:
350 
355  void updateOffsets();
356 
360  void updateShaderInputName(VertexElement* _pElem);
361 
362 
363  std::vector<VertexElement> elements_;
364 
366  unsigned int vertexStride_;
367 
369  std::map<unsigned int, unsigned int> vertexStridesVBO_;
370 
373 };
374 
375 
376 //=============================================================================
377 } // namespace ACG
378 //=============================================================================
379 
380 
381 
382 #endif // ACG_VERTEXDECLARATION_HH defined
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...
unsigned int vbo_
Explicit vbo source of this element, set to 0 if the buffer bound at the time of activating the decla...
int strideUserDefined_
Flag that indicates, whether the stride was set by user or derived automatically. ...
VERTEX_USAGE usage_
position, normal, shader input ..
unsigned int vertexStride_
Offset in bytes between each vertex.
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 numElements_
how many elements of type_
GLSL program class.
Definition: GLSLShader.hh:210
Class to define the vertex input layout.
This namespace contains all the classes and functions for handling GLSL shader and program objects...
Definition: AntiAliasing.hh:68
unsigned int type_
GL_FLOAT, GL_UNSIGNED_BYTE, GL_INT, ...
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:10
std::map< unsigned int, unsigned int > vertexStridesVBO_
Map vbo to offset in bytes between each vertex in that vbo.
VERTEX_USAGE
-— input name in vertex shader ----—
const char * shaderInputName_
set shader input name, if usage_ = VERTEX_USAGE_USER_DEFINED otherwise this is set automatically...