LibCarna Version 3.4.0
Loading...
Searching...
No Matches
ManagedMesh.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010 - 2016 Leonid Kostrykin
3 *
4 * Chair of Medical Engineering (mediTEC)
5 * RWTH Aachen University
6 * Pauwelsstr. 20
7 * 52074 Aachen
8 * Germany
9 *
10 *
11 * Copyright (C) 2021 - 2025 Leonid Kostrykin
12 *
13 */
14
15#ifndef MANAGEDMESH_H_6014714286
16#define MANAGEDMESH_H_6014714286
17
21#include <memory>
22#include <vector>
23
29namespace LibCarna
30{
31
32namespace base
33{
34
35
36
37// ----------------------------------------------------------------------------------
38// ManagedMeshBase
39// ----------------------------------------------------------------------------------
40
59class LIBCARNA ManagedMeshBase : public GeometryFeature
60{
61
63
64 struct Details;
65 const std::unique_ptr< Details > pimpl;
66
67protected:
68
69 friend class GeometryFeature;
70 friend class ManagedMeshInterface;
71
75 ManagedMeshBase( unsigned int primitiveType, const VertexAttributes& va );
76
81
86
91
96
101
105 const MeshBase& mesh() const;
106
107public:
108
113
114 virtual bool controlsSameVideoResource( const GeometryFeature& ) const override;
115
120 const unsigned int primitiveType;
121
126
128
129}; // ManagedMeshBase
130
131
132
133// ----------------------------------------------------------------------------------
134// ManagedMesh
135// ----------------------------------------------------------------------------------
136
148template< typename VertexType, typename IndexType >
150{
151
152 const std::vector< VertexType > vertices;
153 const std::vector< IndexType > indices;
154
155 ManagedMesh( unsigned int primitiveType
156 , const VertexType* vertices
157 , const std::size_t vertexCount
158 , const IndexType* indices
159 , const std::size_t indexCount );
160
161protected:
162
163 virtual VertexBufferBase* loadVertexBuffer() override;
164
165 virtual IndexBufferBase* loadIndexBuffer() override;
166
167public:
168
170 typedef IndexType Index;
171
176 ( unsigned int primitiveType
177 , const VertexType* vertices
178 , const std::size_t vertexCount
179 , const IndexType* indices
180 , const std::size_t indexCount );
181
182}; // ManagedMesh
183
184
185template< typename VertexType, typename IndexType >
187 ( unsigned int primitiveType
188 , const VertexType* vertices
189 , const std::size_t vertexCount
190 , const IndexType* indices
191 , const std::size_t indexCount )
192 : ManagedMeshBase( primitiveType, Vertex::attributes )
193 , vertices( vertices, vertices + vertexCount )
194 , indices ( indices, indices + indexCount )
195{
196}
197
198
199template< typename VertexType, typename IndexType >
201{
203 vb->copy( &vertices.front(), vertices.size() );
204 return vb;
205}
206
207
208template< typename VertexType, typename IndexType >
210{
211 IndexBuffer< IndexType >* const ib = new IndexBuffer< IndexType >( primitiveType );
212 ib->copy( &indices.front(), indices.size() );
213 return ib;
214}
215
216
217template< typename VertexType, typename IndexType >
219 ( unsigned int primitiveType
220 , const VertexType* vertices
221 , const std::size_t vertexCount
222 , const IndexType* indices
223 , const std::size_t indexCount )
224{
225 return *new ManagedMesh< Vertex, Index >( primitiveType, vertices, vertexCount, indices, indexCount );
226}
227
228
229
230} // namespace LibCarna :: base
231
232} // namespace LibCarna
233
234#endif // MANAGEDMESH_H_6014714286
Defines LibCarna::base::GeometryFeature.
Defines LibCarna::base::ManagedMeshInterface.
Defines LibCarna::base::Mesh.
Represents an association.
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...
Represents MeshBase object whose lifetime is managed by instances of this class. This is a format-ind...
virtual VertexBufferBase * loadVertexBuffer()=0
Creates OpenGL vertex buffer object and fills it with data.
void releaseMesh()
Releases mesh within current OpenGL context.
virtual bool controlsSameVideoResource(const GeometryFeature &) const override
Tells whether this instance maintains the same video resources like other.
virtual IndexBufferBase * loadIndexBuffer()=0
Creates OpenGL index buffer object and fills it with data.
const VertexAttributes vertexAttributes
Holds the vertex format of the vertices contained by the vertex buffer.
const unsigned int primitiveType
Holds the primitive type, like GL_TRIANGLES, that should be used when rendering this mesh.
void acquireMesh()
Acquires mesh within current OpenGL context.
const MeshBase & mesh() const
References mesh within current OpenGL context.
virtual ManagedMeshInterface * acquireVideoResource() override
Acquires the video resources from this GeometryFeature by returning new instance of a class derived f...
ManagedMeshInterface ManagedInterface
Defines the type to be used for interfacing the video resource.
ManagedMeshBase(unsigned int primitiveType, const VertexAttributes &va)
Instantiates.
virtual ~ManagedMeshBase()
Deletes.
Interfaces the MeshBase that a ManagedMeshBase represents.
Implements MeshBase class for particular VertexType and IndexType.
virtual VertexBufferBase * loadVertexBuffer() override
Creates OpenGL vertex buffer object and fills it with data.
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.
IndexType Index
Holds the element type of the index buffer.
virtual IndexBufferBase * loadIndexBuffer() override
Creates OpenGL index buffer object and fills it with data.
Format-independent abstract Mesh base class. Each mesh consists of a VertexBuffer,...
Definition Mesh.hpp:67
Maintains GL_ARRAY_BUFFER object that holds vertices. This class realizes the RAII-idiom.
std::vector< VertexAttribute > VertexAttributes
Defines VertexAttribute vector.
#define NON_COPYABLE
Marks the class that it is placed in as non-copyable.