Carna  Version 3.0.1
IndexBuffer.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2010 - 2015 Leonid Kostrykin
3  *
4  * Chair of Medical Engineering (mediTEC)
5  * RWTH Aachen University
6  * Pauwelsstr. 20
7  * 52074 Aachen
8  * Germany
9  *
10  */
11 
12 #ifndef INDEXBUFFER_H_6014714286
13 #define INDEXBUFFER_H_6014714286
14 
15 #include <Carna/Carna.h>
16 #include <Carna/base/BaseBuffer.h>
17 #include <iterator>
18 #include <cstdint>
19 
24 namespace Carna
25 {
26 
27 namespace base
28 {
29 
30 
31 
32 // ----------------------------------------------------------------------------------
33 // IndexBuffer
34 // ----------------------------------------------------------------------------------
35 
43 class CARNA_LIB IndexBufferBase : public BaseBuffer
44 {
45 
46 protected:
47 
52  void copy( const void* bufferPtr, std::size_t bufferSize, std::size_t indicesCount );
53 
54 public:
55 
56  const static unsigned int TYPE_UINT_8;
57  const static unsigned int TYPE_UINT_16;
58  const static unsigned int TYPE_UINT_32;
59 
65  const static unsigned int PRIMITIVE_TYPE_TRIANGLES;
66 
72  const static unsigned int PRIMITIVE_TYPE_TRIANGLE_STRIP;
73 
78  const static unsigned int PRIMITIVE_TYPE_TRIANGLE_FAN;
79 
84  const static unsigned int PRIMITIVE_TYPE_LINES;
85 
90  const static unsigned int PRIMITIVE_TYPE_LINE_STRIP;
91 
97  const static unsigned int PRIMITIVE_TYPE_LINE_LOOP;
98 
102  const static unsigned int PRIMITIVE_TYPE_POINTS;
103 
107  const unsigned int type;
108 
112  const unsigned int primitiveType;
113 
124  IndexBufferBase( unsigned int type, unsigned int primitiveType );
125 
126 }; // IndexBufferBase
127 
128 
129 
130 // ----------------------------------------------------------------------------------
131 // IndexBufferTypeMapper
132 // ----------------------------------------------------------------------------------
133 
137 template< typename IndexType >
139 {
140  static_assert( sizeof( IndexType ) < 0, "Unknown index type." );
141 };
142 
143 
147 template< >
148 struct IndexBufferTypeMapper< uint8_t >
149 {
153  operator unsigned int()
154  {
156  }
157 };
158 
159 
163 template< >
164 struct IndexBufferTypeMapper< uint16_t >
165 {
169  operator unsigned int()
170  {
172  }
173 };
174 
175 
179 template< >
180 struct IndexBufferTypeMapper< uint32_t >
181 {
185  operator unsigned int()
186  {
188  }
189 };
190 
191 
192 
193 // ----------------------------------------------------------------------------------
194 // IndexBuffer
195 // ----------------------------------------------------------------------------------
196 
203 template< typename IndexType >
205 {
206 
207 public:
208 
212  typedef IndexType Index;
213 
221  IndexBuffer( unsigned int primitiveType );
222 
227  void copy( const IndexType* indicesPtr, const std::size_t indicesCount );
228 
229 }; // IndexBuffer
230 
231 
232 template< typename IndexType >
233 IndexBuffer< IndexType >::IndexBuffer( unsigned int primitiveType )
234  : IndexBufferBase( IndexBufferTypeMapper< IndexType >(), primitiveType )
235 {
236 }
237 
238 
239 template< typename IndexType >
240 void IndexBuffer< IndexType >::copy( const IndexType* indicesPtr, const std::size_t indicesCount )
241 {
242  IndexBufferBase::copy( indicesPtr, indicesCount * sizeof( Index ), indicesCount );
243 }
244 
245 
246 
247 } // namespace Carna :: base
248 
249 } // namespace Carna
250 
251 #endif // INDEXBUFFER_H_6014714286
void copy(const IndexType *indicesPtr, const std::size_t indicesCount)
Copies indicesCount indices referenced by indicesPtr to the maintained index buffer object...
Definition: IndexBuffer.h:240
static const unsigned int PRIMITIVE_TYPE_TRIANGLE_STRIP
Draws triangles. Indicates that the indices make up the th triangle with .
Definition: IndexBuffer.h:72
Maps index buffer element types to descriptive constants.
Definition: IndexBuffer.h:138
void copy(const void *bufferPtr, std::size_t bufferSize, std::size_t indicesCount)
Copies indicesCount indices referenced by bufferPtr to the maintained index buffer object...
static const unsigned int PRIMITIVE_TYPE_POINTS
Draws points. Indicates that each index makes up a single point.
Definition: IndexBuffer.h:102
static const unsigned int TYPE_UINT_16
Indicates uint16_t element type.
Definition: IndexBuffer.h:57
IndexType Index
Holds the index type maintained by this index buffer object.
Definition: IndexBuffer.h:212
Defines Carna::base::BaseBuffer.
static const unsigned int PRIMITIVE_TYPE_TRIANGLES
Draws triangles. Indicates that the indices make up the th triangle with .
Definition: IndexBuffer.h:65
const unsigned int type
Holds the element type of the maintained OpenGL buffer object.
Definition: IndexBuffer.h:107
static const unsigned int PRIMITIVE_TYPE_TRIANGLE_FAN
Draws triangles. Indicates that the indices make up the th triangle with .
Definition: IndexBuffer.h:78
static const unsigned int TYPE_UINT_8
Indicates uint8_t element type.
Definition: IndexBuffer.h:56
static const unsigned int PRIMITIVE_TYPE_LINE_STRIP
Draws lines. Indicates that the indices make up a the th line segment with .
Definition: IndexBuffer.h:90
static const unsigned int TYPE_UINT_32
Indicates uint32_t element type.
Definition: IndexBuffer.h:58
IndexBuffer(unsigned int primitiveType)
Creates GL_ELEMENT_ARRAY_BUFFER object.
Definition: IndexBuffer.h:233
const unsigned int primitiveType
Holds how the indexed vertices do interconnect to primitives.
Definition: IndexBuffer.h:112
static const unsigned int PRIMITIVE_TYPE_LINE_LOOP
Draws lines. Indicates that the indices make up the th line segment. Another line segment from the l...
Definition: IndexBuffer.h:97
Specializes IndexBufferBase for particular IndexType.
Definition: IndexBuffer.h:204
Implements OpenGL buffer objects maintenance RAII base class.
Definition: BaseBuffer.h:39
static const unsigned int PRIMITIVE_TYPE_LINES
Draws lines. Indicates that the indices make up the th line segment with .
Definition: IndexBuffer.h:84
Maintains GL_ELEMENT_ARRAY_BUFFER object that holds the vertex indices, that interconnect the vertice...
Definition: IndexBuffer.h:43