Nirtcpp 2.1.0
Nirtcpp is a high-performance c++ graphics engine.
Loading...
Searching...
No Matches
CMeshBuffer.hpp
1// Copyright (C) 2002-2012 Nikolaus Gebhardt
2// This file is part of the "Irrlicht Engine".
3// For conditions of distribution and use, see copyright notice in nirtcpp/nirtcpp.hpp
4
5#ifndef NIRT_T_MESH_BUFFER_HPP_INCLUDED
6#define NIRT_T_MESH_BUFFER_HPP_INCLUDED
7
8#include <nirtcpp/core/engine/irrArray.hpp>
9#include <nirtcpp/core/engine/IMeshBuffer.hpp>
10
11namespace nirt
12{
13namespace scene
14{
16 template <class T>
17 class CMeshBuffer : public IMeshBuffer
18 {
19 public:
22 : ChangedID_Vertex(1), ChangedID_Index(1)
23 , MappingHint_Vertex(EHM_NEVER), MappingHint_Index(EHM_NEVER)
25 {
26 #ifdef _DEBUG
27 setDebugName("CMeshBuffer");
28 #endif
29 }
30
31
33
34 virtual const video::SMaterial& getMaterial() const override
35 {
36 return Material;
37 }
38
39
41
42 virtual video::SMaterial& getMaterial() override
43 {
44 return Material;
45 }
46
47
49
50 virtual const void* getVertices() const override
51 {
52 return Vertices.const_pointer();
53 }
54
55
57
58 virtual void* getVertices() override
59 {
60 return Vertices.pointer();
61 }
62
63
65
66 virtual u32 getVertexCount() const override
67 {
68 return Vertices.size();
69 }
70
72
73 virtual video::E_INDEX_TYPE getIndexType() const override
74 {
75 return video::EIT_16BIT;
76 }
77
79
80 virtual const u16* getIndices() const override
81 {
82 return Indices.const_pointer();
83 }
84
85
87
88 virtual u16* getIndices() override
89 {
90 return Indices.pointer();
91 }
92
93
95
96 virtual u32 getIndexCount() const override
97 {
98 return Indices.size();
99 }
100
101
103
104 virtual const core::aabbox3d<f32>& getBoundingBox() const override
105 {
106 return BoundingBox;
107 }
108
109
111
113 virtual void setBoundingBox(const core::aabbox3df& box) override
114 {
115 BoundingBox = box;
116 }
117
118
120
121 virtual void recalculateBoundingBox() override
122 {
123 if (!Vertices.empty())
124 {
125 BoundingBox.reset(Vertices[0].Pos);
126 const nirt::u32 vsize = Vertices.size();
127 for (u32 i=1; i<vsize; ++i)
129 }
130 else
131 BoundingBox.reset(0,0,0);
132
133 }
134
135
137
138 virtual video::E_VERTEX_TYPE getVertexType() const override
139 {
140 return T::getType();
141 }
142
144 virtual const core::vector3df& getPosition(u32 i) const override
145 {
146 return Vertices[i].Pos;
147 }
148
150 virtual core::vector3df& getPosition(u32 i) override
151 {
152 return Vertices[i].Pos;
153 }
154
156 virtual const core::vector3df& getNormal(u32 i) const override
157 {
158 return Vertices[i].Normal;
159 }
160
162 virtual core::vector3df& getNormal(u32 i) override
163 {
164 return Vertices[i].Normal;
165 }
166
168 virtual const core::vector2df& getTCoords(u32 i) const override
169 {
170 return Vertices[i].TCoords;
171 }
172
174 virtual core::vector2df& getTCoords(u32 i) override
175 {
176 return Vertices[i].TCoords;
177 }
178
180 virtual video::SColor& getColor(u32 i) override
181 {
182 return Vertices[i].Color;
183 }
184
186 virtual const video::SColor& getColor(u32 i) const override
187 {
188 return Vertices[i].Color;
189 }
190
192
196 virtual void append(const void* const vertices, u32 numVertices, const u16* const indices, u32 numIndices) override
197 {
198 if (vertices == getVertices())
199 return;
200
201 const u32 vertexCount = getVertexCount();
202 u32 i;
203
204 Vertices.reallocate(vertexCount+numVertices);
205 for (i=0; i<numVertices; ++i)
206 {
207 Vertices.push_back(static_cast<const T*>(vertices)[i]);
208 BoundingBox.addInternalPoint(static_cast<const T*>(vertices)[i].Pos);
209 }
210
211 Indices.reallocate(getIndexCount()+numIndices);
212 for (i=0; i<numIndices; ++i)
213 {
214 Indices.push_back(indices[i]+vertexCount);
215 }
216 }
217
218
220
225 virtual void append(const IMeshBuffer* const other) override
226 {
227 /*
228 if (this==other)
229 return;
230
231 const u32 vertexCount = getVertexCount();
232 u32 i;
233
234 Vertices.reallocate(vertexCount+other->getVertexCount());
235 for (i=0; i<other->getVertexCount(); ++i)
236 {
237 Vertices.push_back(reinterpret_cast<const T*>(other->getVertices())[i]);
238 }
239
240 Indices.reallocate(getIndexCount()+other->getIndexCount());
241 for (i=0; i<other->getIndexCount(); ++i)
242 {
243 Indices.push_back(other->getIndices()[i]+vertexCount);
244 }
245 BoundingBox.addInternalBox(other->getBoundingBox());
246 */
247 }
248
249
252 {
253 return MappingHint_Vertex;
254 }
255
258 {
259 return MappingHint_Index;
260 }
261
263 virtual void setHardwareMappingHint( E_HARDWARE_MAPPING NewMappingHint, E_BUFFER_TYPE Buffer=EBT_VERTEX_AND_INDEX ) override
264 {
265 if (Buffer==EBT_VERTEX_AND_INDEX || Buffer==EBT_VERTEX)
266 MappingHint_Vertex=NewMappingHint;
267 if (Buffer==EBT_VERTEX_AND_INDEX || Buffer==EBT_INDEX)
268 MappingHint_Index=NewMappingHint;
269 }
270
272 virtual void setPrimitiveType(E_PRIMITIVE_TYPE type) override
273 {
274 PrimitiveType = type;
275 }
276
278 virtual E_PRIMITIVE_TYPE getPrimitiveType() const override
279 {
280 return PrimitiveType;
281 }
282
284 virtual void setDirty(E_BUFFER_TYPE Buffer=EBT_VERTEX_AND_INDEX) override
285 {
286 if (Buffer==EBT_VERTEX_AND_INDEX ||Buffer==EBT_VERTEX)
287 ++ChangedID_Vertex;
288 if (Buffer==EBT_VERTEX_AND_INDEX || Buffer==EBT_INDEX)
289 ++ChangedID_Index;
290 }
291
293
294 virtual u32 getChangedID_Vertex() const override {return ChangedID_Vertex;}
295
297
298 virtual u32 getChangedID_Index() const override {return ChangedID_Index;}
299
301 virtual EMESH_BUFFER_TYPE getType() const override
302 {
303 return getTypeT();
304 }
305
307 virtual IMeshBuffer* createClone(int cloneFlags) const override
308 {
309 CMeshBuffer<T> * clone = new CMeshBuffer<T>();
310
311 if (cloneFlags & ECF_VERTICES)
312 {
313 clone->Vertices = Vertices;
314 clone->BoundingBox = BoundingBox;
315 }
316
317 if (cloneFlags & ECF_INDICES)
318 {
319 clone->Indices = Indices;
320 }
321
323 clone->Material = getMaterial();
325 clone->MappingHint_Index = MappingHint_Index;
326
327 return clone;
328 }
329
331 // Minor note: Some compilers (VS) allow directly specializing the virtual function,
332 // but this will fail on other compilers (GCC). So using a helper function.
334
335 u32 ChangedID_Vertex;
336 u32 ChangedID_Index;
337
340 E_HARDWARE_MAPPING MappingHint_Index;
341
352 };
353
360
362 template <>
367 template <>
369 {
370 return EMBT_LIGHTMAP;
371 }
372 template <>
374 {
375 return EMBT_TANGENTS;
376 }
377
378
379} // end namespace scene
380} // end namespace nirt
381
382#endif
void setDebugName(const c8 *newName)
Sets the debug name of the object.
Definition IReferenceCounted.hpp:163
Axis aligned bounding box in 3d dimensional space.
Definition aabbox3d.hpp:22
void addInternalPoint(const vector3d< T > &p)
Adds a point to the bounding box.
Definition aabbox3d.hpp:74
void reset(T x, T y, T z)
Resets the bounding box to a one-point box.
Definition aabbox3d.hpp:50
u32 size() const
Get number of occupied elements of the array.
Definition irrArray.hpp:397
void push_back(const T &element)
Adds an element at back of array.
Definition irrArray.hpp:111
void reallocate(u32 new_size, bool canShrink=true)
Reallocates the array, make it bigger or smaller.
Definition irrArray.hpp:66
const T * const_pointer() const
Gets a const pointer to the array.
Definition irrArray.hpp:389
T * pointer()
Gets a pointer to the array.
Definition irrArray.hpp:381
Template implementation of the IMeshBuffer interface for 16-bit buffers.
Definition CMeshBuffer.hpp:18
virtual video::SMaterial & getMaterial() override
Get material of this meshbuffer.
Definition CMeshBuffer.hpp:42
virtual u32 getVertexCount() const override
Get number of vertices.
Definition CMeshBuffer.hpp:66
video::SMaterial Material
Material for this meshbuffer.
Definition CMeshBuffer.hpp:343
virtual const video::SMaterial & getMaterial() const override
Get material of this meshbuffer.
Definition CMeshBuffer.hpp:34
virtual video::E_VERTEX_TYPE getVertexType() const override
Get type of vertex data stored in this buffer.
Definition CMeshBuffer.hpp:138
virtual const core::aabbox3d< f32 > & getBoundingBox() const override
Get the axis aligned bounding box.
Definition CMeshBuffer.hpp:104
virtual void setBoundingBox(const core::aabbox3df &box) override
Set the axis aligned bounding box.
Definition CMeshBuffer.hpp:113
virtual core::vector3df & getPosition(u32 i) override
returns position of vertex i
Definition CMeshBuffer.hpp:150
virtual u32 getIndexCount() const override
Get number of indices.
Definition CMeshBuffer.hpp:96
virtual const core::vector2df & getTCoords(u32 i) const override
returns texture coord of vertex i
Definition CMeshBuffer.hpp:168
core::aabbox3d< f32 > BoundingBox
Bounding box of this meshbuffer.
Definition CMeshBuffer.hpp:349
virtual u32 getChangedID_Index() const override
Get the currently used ID for identification of changes.
Definition CMeshBuffer.hpp:298
virtual const void * getVertices() const override
Get pointer to vertices.
Definition CMeshBuffer.hpp:50
virtual video::SColor & getColor(u32 i) override
returns color of vertex i
Definition CMeshBuffer.hpp:180
virtual video::E_INDEX_TYPE getIndexType() const override
Get type of index data which is stored in this meshbuffer.
Definition CMeshBuffer.hpp:73
virtual void append(const IMeshBuffer *const other) override
Append the meshbuffer to the current buffer.
Definition CMeshBuffer.hpp:225
CMeshBuffer()
Default constructor for empty meshbuffer.
Definition CMeshBuffer.hpp:21
virtual E_HARDWARE_MAPPING getHardwareMappingHint_Index() const override
get the current hardware mapping hint
Definition CMeshBuffer.hpp:257
E_HARDWARE_MAPPING MappingHint_Vertex
hardware mapping hint
Definition CMeshBuffer.hpp:339
virtual core::vector2df & getTCoords(u32 i) override
returns texture coord of vertex i
Definition CMeshBuffer.hpp:174
virtual u32 getChangedID_Vertex() const override
Get the currently used ID for identification of changes.
Definition CMeshBuffer.hpp:294
virtual void * getVertices() override
Get pointer to vertices.
Definition CMeshBuffer.hpp:58
virtual u16 * getIndices() override
Get pointer to indices.
Definition CMeshBuffer.hpp:88
virtual void recalculateBoundingBox() override
Recalculate the bounding box.
Definition CMeshBuffer.hpp:121
virtual core::vector3df & getNormal(u32 i) override
returns normal of vertex i
Definition CMeshBuffer.hpp:162
virtual IMeshBuffer * createClone(int cloneFlags) const override
Create copy of the meshbuffer.
Definition CMeshBuffer.hpp:307
virtual const core::vector3df & getPosition(u32 i) const override
returns position of vertex i
Definition CMeshBuffer.hpp:144
virtual const u16 * getIndices() const override
Get pointer to indices.
Definition CMeshBuffer.hpp:80
virtual EMESH_BUFFER_TYPE getType() const override
Returns type of the class implementing the IMeshBuffer.
Definition CMeshBuffer.hpp:301
E_PRIMITIVE_TYPE PrimitiveType
Primitive type used for rendering (triangles, lines, ...)
Definition CMeshBuffer.hpp:351
EMESH_BUFFER_TYPE getTypeT() const
Returns type of the class implementing the IMeshBuffer for template specialization.
core::array< T > Vertices
Vertices of this buffer.
Definition CMeshBuffer.hpp:345
core::array< u16 > Indices
Indices into the vertices of this buffer.
Definition CMeshBuffer.hpp:347
virtual E_PRIMITIVE_TYPE getPrimitiveType() const override
Get the kind of primitive geometry which is used by the meshbuffer.
Definition CMeshBuffer.hpp:278
virtual void setPrimitiveType(E_PRIMITIVE_TYPE type) override
Describe what kind of primitive geometry is used by the meshbuffer.
Definition CMeshBuffer.hpp:272
virtual const core::vector3df & getNormal(u32 i) const override
returns normal of vertex i
Definition CMeshBuffer.hpp:156
virtual E_HARDWARE_MAPPING getHardwareMappingHint_Vertex() const override
get the current hardware mapping hint
Definition CMeshBuffer.hpp:251
virtual void setHardwareMappingHint(E_HARDWARE_MAPPING NewMappingHint, E_BUFFER_TYPE Buffer=EBT_VERTEX_AND_INDEX) override
set the hardware mapping hint, for driver
Definition CMeshBuffer.hpp:263
virtual const video::SColor & getColor(u32 i) const override
returns color of vertex i
Definition CMeshBuffer.hpp:186
virtual void append(const void *const vertices, u32 numVertices, const u16 *const indices, u32 numIndices) override
Append the vertices and indices to the current buffer.
Definition CMeshBuffer.hpp:196
virtual void setDirty(E_BUFFER_TYPE Buffer=EBT_VERTEX_AND_INDEX) override
flags the mesh as changed, reloads hardware buffers
Definition CMeshBuffer.hpp:284
Class for holding a mesh with a single material.
Definition IMeshBuffer.hpp:41
@ ECF_INDICES
clone the vertices (or copy pointer for SSharedMeshBuffer)
Definition IMeshBuffer.hpp:205
Class representing a 32 bit ARGB color.
Definition SColor.hpp:317
Class for holding parameters for a material renderer.
Definition SMaterial.hpp:304
E_BUFFER_TYPE
Definition EHardwareBufferFlags.hpp:29
@ EBT_VERTEX_AND_INDEX
Change both vertex and index mapping to the same value.
Definition EHardwareBufferFlags.hpp:37
@ EBT_INDEX
Change the index mapping.
Definition EHardwareBufferFlags.hpp:35
@ EBT_VERTEX
Change the vertex mapping.
Definition EHardwareBufferFlags.hpp:33
E_PRIMITIVE_TYPE
Enumeration for all primitive types there are.
Definition EPrimitiveTypes.hpp:15
@ EPT_TRIANGLES
Explicitly set all vertices for each triangle.
Definition EPrimitiveTypes.hpp:37
E_HARDWARE_MAPPING
Definition EHardwareBufferFlags.hpp:14
@ EHM_NEVER
Don't store on the hardware.
Definition EHardwareBufferFlags.hpp:16
EMESH_BUFFER_TYPE
An enumeration for all types of built-in mesh buffers.
Definition EMeshBufferTypes.hpp:18
@ EMBT_LIGHTMAP
SMeshBufferLightMap (16 bit buffers)
Definition EMeshBufferTypes.hpp:23
@ EMBT_TANGENTS
SMeshBufferTangents (16 bit buffers)
Definition EMeshBufferTypes.hpp:26
@ EMBT_STANDARD
SMeshBuffer (16 bit buffers)
Definition EMeshBufferTypes.hpp:20
E_VERTEX_TYPE
Enumeration for all vertex types there are.
Definition S3DVertex.hpp:19
As of Nirtcpp 1.6, position2d is a synonym for vector2d.
Definition vector3d.hpp:11
unsigned short u16
16 bit unsigned variable.
Definition irrTypes.hpp:46
unsigned int u32
32 bit unsigned variable.
Definition irrTypes.hpp:64

Nirtcpp    @cppfx.xyz

Esvcpp    esv::print