Carna Version 3.3.3
Loading...
Searching...
No Matches
ManagedMesh.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 MANAGEDMESH_H_6014714286
13#define MANAGEDMESH_H_6014714286
14
15#include <Carna/base/Mesh.h>
18#include <memory>
19#include <vector>
20
25namespace Carna
26{
27
28namespace base
29{
30
31
32
33// ----------------------------------------------------------------------------------
34// ManagedMeshBase
35// ----------------------------------------------------------------------------------
36
56class CARNA_LIB ManagedMeshBase : public GeometryFeature
57{
58
60
61 struct Details;
62 const std::unique_ptr< Details > pimpl;
63
64protected:
65
66 friend class GeometryFeature;
67 friend class ManagedMeshInterface;
68
72 ManagedMeshBase( unsigned int primitiveType, const VertexAttributes& va );
73
78
83
88
93
98
102 const MeshBase& mesh() const;
103
104public:
105
110
111 virtual bool controlsSameVideoResource( const GeometryFeature& ) const override;
112
117 const unsigned int primitiveType;
118
123
125
126}; // ManagedMeshBase
127
128
129
130// ----------------------------------------------------------------------------------
131// ManagedMesh
132// ----------------------------------------------------------------------------------
133
146template< typename VertexType, typename IndexType >
148{
149
150 const std::vector< VertexType > vertices;
151 const std::vector< IndexType > indices;
152
153 ManagedMesh( unsigned int primitiveType
154 , const VertexType* vertices
155 , const std::size_t vertexCount
156 , const IndexType* indices
157 , const std::size_t indexCount );
158
159protected:
160
161 virtual VertexBufferBase* loadVertexBuffer() override;
162
163 virtual IndexBufferBase* loadIndexBuffer() override;
164
165public:
166
168 typedef IndexType Index;
169
174 ( unsigned int primitiveType
175 , const VertexType* vertices
176 , const std::size_t vertexCount
177 , const IndexType* indices
178 , const std::size_t indexCount );
179
180}; // ManagedMesh
181
182
183template< typename VertexType, typename IndexType >
185 ( unsigned int primitiveType
186 , const VertexType* vertices
187 , const std::size_t vertexCount
188 , const IndexType* indices
189 , const std::size_t indexCount )
190 : ManagedMeshBase( primitiveType, Vertex::attributes )
191 , vertices( vertices, vertices + vertexCount )
192 , indices ( indices, indices + indexCount )
193{
194}
195
196
197template< typename VertexType, typename IndexType >
199{
201 vb->copy( &vertices.front(), vertices.size() );
202 return vb;
203}
204
205
206template< typename VertexType, typename IndexType >
208{
209 IndexBuffer< IndexType >* const ib = new IndexBuffer< IndexType >( primitiveType );
210 ib->copy( &indices.front(), indices.size() );
211 return ib;
212}
213
214
215template< typename VertexType, typename IndexType >
217 ( unsigned int primitiveType
218 , const VertexType* vertices
219 , const std::size_t vertexCount
220 , const IndexType* indices
221 , const std::size_t indexCount )
222{
223 return *new ManagedMesh< Vertex, Index >( primitiveType, vertices, vertexCount, indices, indexCount );
224}
225
226
227
228} // namespace Carna :: base
229
230} // namespace Carna
231
232#endif // MANAGEDMESH_H_6014714286
Defines Carna::base::GeometryFeature.
Defines Carna::base::ManagedMeshInterface.
Defines Carna::base::Mesh.
Represents an association.
Definition Association.h:45
Represents "components" that are aggregated by Geometry objects. Closer description is given here.
Maintains GL_ELEMENT_ARRAY_BUFFER object that holds the vertex indices, that interconnect the vertice...
Definition IndexBuffer.h:44
Represents MeshBase object whose lifetime is managed by instances of this class. This is a format-ind...
Definition ManagedMesh.h:57
virtual ~ManagedMeshBase()
Deletes.
ManagedMeshInterface ManagedInterface
Defines the type to be used for interfacing the video resource.
virtual ManagedMeshInterface * acquireVideoResource() override
Acquires the video resources from this GeometryFeature by returning new instance of a class derived f...
const unsigned int primitiveType
Holds the primitive type, like GL_TRIANGLES, that should be used when rendering this mesh.
void releaseMesh()
Releases mesh within current OpenGL context.
const VertexAttributes vertexAttributes
Holds the vertex format of the vertices contained by the vertex buffer.
virtual IndexBufferBase * loadIndexBuffer()=0
Creates OpenGL index buffer object and fills it with data.
const MeshBase & mesh() const
References mesh within current OpenGL context.
virtual bool controlsSameVideoResource(const GeometryFeature &) const override
Tells whether this instance maintains the same video resources like other.
virtual VertexBufferBase * loadVertexBuffer()=0
Creates OpenGL vertex buffer object and fills it with data.
void acquireMesh()
Acquires mesh within current OpenGL context.
ManagedMeshBase(unsigned int primitiveType, const VertexAttributes &va)
Instantiates.
Interfaces the MeshBase that a ManagedMeshBase represents.
Implements MeshBase class for particular VertexType and IndexType.
static ManagedMesh< VertexType, IndexType > & create(unsigned int primitiveType, const VertexType *vertices, const std::size_t vertexCount, const IndexType *indices, const std::size_t indexCount)
Instantiates. Call release when you do not need the object any longer.
VertexType Vertex
Holds the element type of the vertex buffer.
virtual IndexBufferBase * loadIndexBuffer() override
Creates OpenGL index buffer object and fills it with data.
virtual VertexBufferBase * loadVertexBuffer() override
Creates OpenGL vertex buffer object and fills it with data.
IndexType Index
Holds the element type of the index buffer.
Format-independent abstract Mesh base class. Each mesh consists of a VertexBuffer,...
Definition Mesh.h:64
Maintains GL_ARRAY_BUFFER object that holds vertices. This class realizes the RAII-idiom.
std::vector< VertexAttribute > VertexAttributes
Defines VertexAttribute vector.
#define NON_COPYABLE
Features class it is placed in as non-copyable.