Loading [MathJax]/extensions/tex2jax.js
Carna  Version 3.3.2
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Mesh.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 MESH_H_6014714286
13 #define MESH_H_6014714286
14 
17 #include <Carna/base/IndexBuffer.h>
18 #include <memory>
19 
24 namespace Carna
25 {
26 
27 namespace base
28 {
29 
30 
31 
32 // ----------------------------------------------------------------------------------
33 // MeshBase
34 // ----------------------------------------------------------------------------------
35 
63 class CARNA_LIB MeshBase
64 {
65 
66  const std::unique_ptr< Association< VertexBufferBase > > myVertexBuffer;
67  const std::unique_ptr< Association< IndexBufferBase > > myIndexBuffer;
68 
69 public:
70 
75  MeshBase
76  ( const VertexAttributes& va
77  , Association< VertexBufferBase >* vertexBuffer
78  , Association< IndexBufferBase >* indexBuffer );
79 
84  virtual ~MeshBase();
85 
89  const unsigned int id;
90 
95 
100  void bind() const;
101 
106  void render() const;
107 
108  const VertexBufferBase& vertexBuffer() const;
109  const IndexBufferBase& indexBuffer() const;
110 
111  VertexBufferBase& vertexBuffer();
112  IndexBufferBase& indexBuffer();
113 
114 }; // MeshBase
115 
116 
117 
118 // ----------------------------------------------------------------------------------
119 // Mesh
120 // ----------------------------------------------------------------------------------
121 
134 template< typename VertexType, typename IndexType >
135 class Mesh : public MeshBase
136 {
137 
138 public:
139 
144  , Association< IndexBufferBase >* indexBuffer );
145 
146  typedef VertexType Vertex;
147  typedef IndexType Index;
148 
149 }; // Mesh
150 
151 
152 template< typename VertexType, typename IndexType >
155  , Association< IndexBufferBase >* indexBuffer )
156  : MeshBase( VertexType::attributes, vertexBuffer, indexBuffer )
157 {
158 }
159 
160 
161 
162 } // namespace Carna :: base
163 
164 } // namespace Carna
165 
166 #endif // MESH_H_6014714286
const unsigned int id
Holds the ID of the OpenGL vertex array object.
Definition: Mesh.h:89
Implements MeshBase class for particular VertexType and IndexType.
Definition: Mesh.h:135
Mesh(Association< VertexBufferBase > *vertexBuffer, Association< IndexBufferBase > *indexBuffer)
Definition: Mesh.h:154
Defines Carna::base::VertexAttributes.
Maintains GL_ARRAY_BUFFER object that holds vertices. This class realizes the RAII-idiom.
Definition: VertexBuffer.h:42
Defines Carna::base::IndexBuffer.
IndexType Index
Holds the element type of the index buffer.
Definition: Mesh.h:147
const GLContext & glContext
References the OpenGL context this mesh is valid within.
Definition: Mesh.h:94
Format-independent abstract Mesh base class. Each mesh consists of a VertexBuffer, an IndexBuffer and a vertex array. This class realizes the RAII-idiom w.r.t. the vertex array.
Definition: Mesh.h:63
VertexType Vertex
Holds the element type of the vertex buffer.
Definition: Mesh.h:146
Represents an association.
Definition: Association.h:44
Wraps and represents an OpenGL context.
Definition: GLContext.h:62
std::vector< VertexAttribute > VertexAttributes
Defines VertexAttribute vector.
Defines Carna::base::VertexBuffer.
Maintains GL_ELEMENT_ARRAY_BUFFER object that holds the vertex indices, that interconnect the vertice...
Definition: IndexBuffer.h:43