Irrlicht 3D Engine
CMeshBuffer.h
Go to the documentation of this file.
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 irrlicht.h
4 
5 #ifndef __T_MESH_BUFFER_H_INCLUDED__
6 #define __T_MESH_BUFFER_H_INCLUDED__
7 
8 #include "irrArray.h"
9 #include "IMeshBuffer.h"
10 
11 namespace irr
12 {
13 namespace scene
14 {
16  template <class T>
17  class CMeshBuffer : public IMeshBuffer
18  {
19  public:
22  {
23  #ifdef _DEBUG
24  setDebugName("SMeshBuffer");
25  #endif
26  }
27 
28 
30 
31  virtual const video::SMaterial& getMaterial() const
32  {
33  return Material;
34  }
35 
36 
38 
40  {
41  return Material;
42  }
43 
44 
46 
47  virtual const void* getVertices() const
48  {
49  return Vertices.const_pointer();
50  }
51 
52 
54 
55  virtual void* getVertices()
56  {
57  return Vertices.pointer();
58  }
59 
60 
62 
63  virtual u32 getVertexCount() const
64  {
65  return Vertices.size();
66  }
67 
69 
71  {
72  return video::EIT_16BIT;
73  }
74 
76 
77  virtual const u16* getIndices() const
78  {
79  return Indices.const_pointer();
80  }
81 
82 
84 
85  virtual u16* getIndices()
86  {
87  return Indices.pointer();
88  }
89 
90 
92 
93  virtual u32 getIndexCount() const
94  {
95  return Indices.size();
96  }
97 
98 
100 
101  virtual const core::aabbox3d<f32>& getBoundingBox() const
102  {
103  return BoundingBox;
104  }
105 
106 
108 
109  virtual void setBoundingBox(const core::aabbox3df& box)
111  {
112  BoundingBox = box;
113  }
114 
115 
117 
118  virtual void recalculateBoundingBox()
119  {
120  if (Vertices.empty())
121  BoundingBox.reset(0,0,0);
122  else
123  {
124  BoundingBox.reset(Vertices[0].Pos);
125  for (u32 i=1; i<Vertices.size(); ++i)
127  }
128  }
129 
130 
132 
134  {
135  return T().getType();
136  }
137 
139  virtual const core::vector3df& getPosition(u32 i) const
140  {
141  return Vertices[i].Pos;
142  }
143 
146  {
147  return Vertices[i].Pos;
148  }
149 
151  virtual const core::vector3df& getNormal(u32 i) const
152  {
153  return Vertices[i].Normal;
154  }
155 
158  {
159  return Vertices[i].Normal;
160  }
161 
163  virtual const core::vector2df& getTCoords(u32 i) const
164  {
165  return Vertices[i].TCoords;
166  }
167 
170  {
171  return Vertices[i].TCoords;
172  }
173 
174 
176 
180  virtual void append(const void* const vertices, u32 numVertices, const u16* const indices, u32 numIndices)
181  {
182  if (vertices == getVertices())
183  return;
184 
185  const u32 vertexCount = getVertexCount();
186  u32 i;
187 
188  Vertices.reallocate(vertexCount+numVertices);
189  for (i=0; i<numVertices; ++i)
190  {
191  Vertices.push_back(reinterpret_cast<const T*>(vertices)[i]);
192  BoundingBox.addInternalPoint(reinterpret_cast<const T*>(vertices)[i].Pos);
193  }
194 
195  Indices.reallocate(getIndexCount()+numIndices);
196  for (i=0; i<numIndices; ++i)
197  {
198  Indices.push_back(indices[i]+vertexCount);
199  }
200  }
201 
202 
204 
209  virtual void append(const IMeshBuffer* const other)
210  {
211  /*
212  if (this==other)
213  return;
214 
215  const u32 vertexCount = getVertexCount();
216  u32 i;
217 
218  Vertices.reallocate(vertexCount+other->getVertexCount());
219  for (i=0; i<other->getVertexCount(); ++i)
220  {
221  Vertices.push_back(reinterpret_cast<const T*>(other->getVertices())[i]);
222  }
223 
224  Indices.reallocate(getIndexCount()+other->getIndexCount());
225  for (i=0; i<other->getIndexCount(); ++i)
226  {
227  Indices.push_back(other->getIndices()[i]+vertexCount);
228  }
229  BoundingBox.addInternalBox(other->getBoundingBox());
230  */
231  }
232 
233 
236  {
237  return MappingHint_Vertex;
238  }
239 
242  {
243  return MappingHint_Index;
244  }
245 
248  {
249  if (Buffer==EBT_VERTEX_AND_INDEX || Buffer==EBT_VERTEX)
250  MappingHint_Vertex=NewMappingHint;
251  if (Buffer==EBT_VERTEX_AND_INDEX || Buffer==EBT_INDEX)
252  MappingHint_Index=NewMappingHint;
253  }
254 
255 
258  {
259  if (Buffer==EBT_VERTEX_AND_INDEX ||Buffer==EBT_VERTEX)
261  if (Buffer==EBT_VERTEX_AND_INDEX || Buffer==EBT_INDEX)
262  ++ChangedID_Index;
263  }
264 
266 
267  virtual u32 getChangedID_Vertex() const {return ChangedID_Vertex;}
268 
270 
271  virtual u32 getChangedID_Index() const {return ChangedID_Index;}
272 
275 
279 
288  };
289 
296 } // end namespace scene
297 } // end namespace irr
298 
299 #endif
300 
301 
virtual const core::vector3df & getNormal(u32 i) const
returns normal of vertex i
Definition: CMeshBuffer.h:151
Change the vertex mapping.
virtual u32 getChangedID_Vertex() const
Get the currently used ID for identification of changes.
Definition: CMeshBuffer.h:267
Template implementation of the IMeshBuffer interface.
Definition: CMeshBuffer.h:17
virtual void setHardwareMappingHint(E_HARDWARE_MAPPING NewMappingHint, E_BUFFER_TYPE Buffer=EBT_VERTEX_AND_INDEX)
set the hardware mapping hint, for driver
Definition: CMeshBuffer.h:247
virtual u32 getChangedID_Index() const
Get the currently used ID for identification of changes.
Definition: CMeshBuffer.h:271
virtual core::vector3df & getNormal(u32 i)
returns normal of vertex i
Definition: CMeshBuffer.h:157
void reallocate(u32 new_size, bool canShrink=true)
Reallocates the array, make it bigger or smaller.
Definition: irrArray.h:67
virtual void setBoundingBox(const core::aabbox3df &box)
Set the axis aligned bounding box.
Definition: CMeshBuffer.h:110
video::SMaterial Material
Material for this meshbuffer.
Definition: CMeshBuffer.h:281
virtual E_HARDWARE_MAPPING getHardwareMappingHint_Vertex() const
get the current hardware mapping hint
Definition: CMeshBuffer.h:235
core::array< u16 > Indices
Indices into the vertices of this buffer.
Definition: CMeshBuffer.h:285
E_HARDWARE_MAPPING MappingHint_Vertex
hardware mapping hint
Definition: CMeshBuffer.h:277
CMeshBuffer< video::S3DVertex > SMeshBuffer
Standard meshbuffer.
Definition: CMeshBuffer.h:291
const T * const_pointer() const
Gets a const pointer to the array.
Definition: irrArray.h:360
virtual video::E_VERTEX_TYPE getVertexType() const
Get type of vertex data stored in this buffer.
Definition: CMeshBuffer.h:133
virtual void append(const IMeshBuffer *const other)
Append the meshbuffer to the current buffer.
Definition: CMeshBuffer.h:209
Everything in the Irrlicht Engine can be found in this namespace.
Definition: aabbox3d.h:12
virtual core::vector3df & getPosition(u32 i)
returns position of vertex i
Definition: CMeshBuffer.h:145
Don&#39;t store on the hardware.
virtual const core::vector2df & getTCoords(u32 i) const
returns texture coord of vertex i
Definition: CMeshBuffer.h:163
void reset(T x, T y, T z)
Resets the bounding box to a one-point box.
Definition: aabbox3d.h:50
void push_back(const T &element)
Adds an element at back of array.
Definition: irrArray.h:112
bool empty() const
Check if array is empty.
Definition: irrArray.h:385
unsigned short u16
16 bit unsigned variable.
Definition: irrTypes.h:40
virtual u16 * getIndices()
Get pointer to indices.
Definition: CMeshBuffer.h:85
virtual u32 getVertexCount() const
Get number of vertices.
Definition: CMeshBuffer.h:63
Struct for holding a mesh with a single material.
Definition: IMeshBuffer.h:39
virtual const void * getVertices() const
Get pointer to vertices.
Definition: CMeshBuffer.h:47
virtual void append(const void *const vertices, u32 numVertices, const u16 *const indices, u32 numIndices)
Append the vertices and indices to the current buffer.
Definition: CMeshBuffer.h:180
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:58
virtual void * getVertices()
Get pointer to vertices.
Definition: CMeshBuffer.h:55
Change both vertex and index mapping to the same value.
E_HARDWARE_MAPPING MappingHint_Index
Definition: CMeshBuffer.h:278
virtual u32 getIndexCount() const
Get number of indices.
Definition: CMeshBuffer.h:93
u32 size() const
Get number of occupied elements of the array.
Definition: irrArray.h:368
core::aabbox3d< f32 > BoundingBox
Bounding box of this meshbuffer.
Definition: CMeshBuffer.h:287
virtual video::E_INDEX_TYPE getIndexType() const
Get type of index data which is stored in this meshbuffer.
Definition: CMeshBuffer.h:70
CMeshBuffer< video::S3DVertex2TCoords > SMeshBufferLightMap
Meshbuffer with two texture coords per vertex, e.g. for lightmaps.
Definition: CMeshBuffer.h:293
virtual void recalculateBoundingBox()
Recalculate the bounding box.
Definition: CMeshBuffer.h:118
virtual const core::aabbox3d< f32 > & getBoundingBox() const
Get the axis aligned bounding box.
Definition: CMeshBuffer.h:101
Change the index mapping.
void addInternalPoint(const vector3d< T > &p)
Adds a point to the bounding box.
Definition: aabbox3d.h:74
void setDebugName(const c8 *newName)
Sets the debug name of the object.
core::array< T > Vertices
Vertices of this buffer.
Definition: CMeshBuffer.h:283
virtual const core::vector3df & getPosition(u32 i) const
returns position of vertex i
Definition: CMeshBuffer.h:139
virtual video::SMaterial & getMaterial()
Get material of this meshbuffer.
Definition: CMeshBuffer.h:39
virtual const video::SMaterial & getMaterial() const
Get material of this meshbuffer.
Definition: CMeshBuffer.h:31
E_VERTEX_TYPE
Enumeration for all vertex types there are.
Definition: S3DVertex.h:18
CMeshBuffer< video::S3DVertexTangents > SMeshBufferTangents
Meshbuffer with vertices having tangents stored, e.g. for normal mapping.
Definition: CMeshBuffer.h:295
virtual const u16 * getIndices() const
Get pointer to indices.
Definition: CMeshBuffer.h:77
virtual E_HARDWARE_MAPPING getHardwareMappingHint_Index() const
get the current hardware mapping hint
Definition: CMeshBuffer.h:241
Struct for holding parameters for a material renderer.
Definition: SMaterial.h:226
T * pointer()
Gets a pointer to the array.
Definition: irrArray.h:352
virtual core::vector2df & getTCoords(u32 i)
returns texture coord of vertex i
Definition: CMeshBuffer.h:169
CMeshBuffer()
Default constructor for empty meshbuffer.
Definition: CMeshBuffer.h:21
virtual void setDirty(E_BUFFER_TYPE Buffer=EBT_VERTEX_AND_INDEX)
flags the mesh as changed, reloads hardware buffers
Definition: CMeshBuffer.h:257