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  * $Revision$ *
45  * $Author$ *
46  * $Date$ *
47  * *
48 \*===========================================================================*/
49 
50 
51 #ifndef ACG_VERTEXDECLARATION_HH
52 #define ACG_VERTEXDECLARATION_HH
53 
54 #include <vector>
55 #include <list>
56 #include <map>
57 #include <QString>
58 #include <ACG/Config/ACGDefines.hh>
59 
60 namespace GLSL
61 {
62  class Program;
63 }
64 
65 namespace ACG
66 {
67 
70 {
78  VERTEX_USAGE_FORCE_DWORD = 0xFFFFFFFF
79 };
80 
84 struct ACGDLLEXPORT VertexElement
85 {
86  VertexElement();
87 
88  unsigned int type_;
89  unsigned int numElements_;
91  const char* shaderInputName_;
92  const void* pointer_;
93  unsigned int divisor_;
94  unsigned int vbo_;
95 
98  void setByteOffset(unsigned int _offset);
99 
102  unsigned int getByteOffset() const;
103 };
104 
266 class ACGDLLEXPORT VertexDeclaration
267 {
268 public:
269 
272 
275  void addElement(const VertexElement* _pElement);
276 
279  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);
280 
283  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);
284 
287  void addElements(unsigned int _numElements, const VertexElement* _pElements);
288 
291  void clear();
292 
296  void activateFixedFunction() const;
297 
300  void deactivateFixedFunction() const;
301 
302 
306  void activateShaderPipeline(GLSL::Program* _prog) const;
307 
308 
312  void deactivateShaderPipeline(GLSL::Program* _prog) const;
313 
314 
318  void setVertexStride(unsigned int _stride);
319 
322  unsigned int getVertexStride(unsigned int i = 0) const;
323 
326  unsigned int getNumElements() const;
327 
330  const VertexElement* getElement(unsigned int i) const;
331 
334  int findElementIdByUsage(VERTEX_USAGE _usage) const;
335 
338  const VertexElement* findElementByUsage(VERTEX_USAGE _usage) const;
339 
342  static unsigned int getGLTypeSize(unsigned int _type);
343 
346  static unsigned int getElementSize(const VertexElement* _pElement);
347 
350  static bool supportsInstancedArrays();
351 
354  QString toString() const;
355 
356 private:
357 
362  void updateOffsets();
363 
367  void updateShaderInputName(VertexElement* _pElem);
368 
369 
370  std::vector<VertexElement> elements_;
371 
373  unsigned int vertexStride_;
374 
376  std::map<unsigned int, unsigned int> vertexStridesVBO_;
377 
380 };
381 
382 
383 //=============================================================================
384 } // namespace ACG
385 //=============================================================================
386 
387 
388 
389 #endif // ACG_VERTEXDECLARATION_HH defined
VERTEX_USAGE
-— input name in vertex shader ----—
unsigned int type_
GL_FLOAT, GL_UNSIGNED_BYTE, GL_INT, ...
std::map< unsigned int, unsigned int > vertexStridesVBO_
Map vbo to offset in bytes between each vertex in that vbo.
Description of one vertex element.
unsigned int vbo_
Explicit vbo source of this element, set to 0 if the buffer bound at the time of activating the decla...
const void * pointer_
Offset in bytes to the first occurrence of this element in vertex buffer; Or address to vertex data i...
Class to define the vertex input layout.
defined by user via VertexElement::shaderInputName_
unsigned int vertexStride_
Offset in bytes between each vertex.
unsigned int numElements_
how many elements of type_
VERTEX_USAGE usage_
position, normal, shader input ..
unsigned int divisor_
For instanced rendering: Step rate describing how many instances are drawn before advancing to the ne...
const char * shaderInputName_
set shader input name, if usage_ = VERTEX_USAGE_USER_DEFINED otherwise this is set automatically...
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51
This namespace contains all the classes and functions for handling GLSL shader and program objects...
Definition: AntiAliasing.hh:75
int strideUserDefined_
Flag that indicates, whether the stride was set by user or derived automatically. ...
GLSL program class.
Definition: GLSLShader.hh:217