arsa  2.7
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:
25  {
26  #ifdef _DEBUG
27  setDebugName("CMeshBuffer");
28  #endif
29  }
30 
31 
33 
35  {
36  return Material;
37  }
38 
39 
41 
43  {
44  return Material;
45  }
46 
47 
49 
50  virtual const void* getVertices() const _IRR_OVERRIDE_
51  {
52  return Vertices.const_pointer();
53  }
54 
55 
57 
58  virtual void* getVertices() _IRR_OVERRIDE_
59  {
60  return Vertices.pointer();
61  }
62 
63 
65 
67  {
68  return Vertices.size();
69  }
70 
72 
74  {
75  return video::EIT_16BIT;
76  }
77 
79 
81  {
82  return Indices.const_pointer();
83  }
84 
85 
87 
89  {
90  return Indices.pointer();
91  }
92 
93 
95 
97  {
98  return Indices.size();
99  }
100 
101 
103 
105  {
106  return BoundingBox;
107  }
108 
109 
111 
112  virtual void setBoundingBox(const core::aabbox3df& box) _IRR_OVERRIDE_
114  {
115  BoundingBox = box;
116  }
117 
118 
120 
122  {
123  if (!Vertices.empty())
124  {
125  BoundingBox.reset(Vertices[0].Pos);
126  const irr::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 
139  {
140  return T::getType();
141  }
142 
145  {
146  return Vertices[i].Pos;
147  }
148 
151  {
152  return Vertices[i].Pos;
153  }
154 
156  virtual const core::vector3df& getNormal(u32 i) const _IRR_OVERRIDE_
157  {
158  return Vertices[i].Normal;
159  }
160 
163  {
164  return Vertices[i].Normal;
165  }
166 
169  {
170  return Vertices[i].TCoords;
171  }
172 
175  {
176  return Vertices[i].TCoords;
177  }
178 
179 
181 
185  virtual void append(const void* const vertices, u32 numVertices, const u16* const indices, u32 numIndices) _IRR_OVERRIDE_
186  {
187  if (vertices == getVertices())
188  return;
189 
190  const u32 vertexCount = getVertexCount();
191  u32 i;
192 
193  Vertices.reallocate(vertexCount+numVertices);
194  for (i=0; i<numVertices; ++i)
195  {
196  Vertices.push_back(reinterpret_cast<const T*>(vertices)[i]);
197  BoundingBox.addInternalPoint(reinterpret_cast<const T*>(vertices)[i].Pos);
198  }
199 
200  Indices.reallocate(getIndexCount()+numIndices);
201  for (i=0; i<numIndices; ++i)
202  {
203  Indices.push_back(indices[i]+vertexCount);
204  }
205  }
206 
207 
209 
214  virtual void append(const IMeshBuffer* const other) _IRR_OVERRIDE_
215  {
216  /*
217  if (this==other)
218  return;
219 
220  const u32 vertexCount = getVertexCount();
221  u32 i;
222 
223  Vertices.reallocate(vertexCount+other->getVertexCount());
224  for (i=0; i<other->getVertexCount(); ++i)
225  {
226  Vertices.push_back(reinterpret_cast<const T*>(other->getVertices())[i]);
227  }
228 
229  Indices.reallocate(getIndexCount()+other->getIndexCount());
230  for (i=0; i<other->getIndexCount(); ++i)
231  {
232  Indices.push_back(other->getIndices()[i]+vertexCount);
233  }
234  BoundingBox.addInternalBox(other->getBoundingBox());
235  */
236  }
237 
238 
241  {
242  return MappingHint_Vertex;
243  }
244 
247  {
248  return MappingHint_Index;
249  }
250 
253  {
254  if (Buffer==EBT_VERTEX_AND_INDEX || Buffer==EBT_VERTEX)
255  MappingHint_Vertex=NewMappingHint;
256  if (Buffer==EBT_VERTEX_AND_INDEX || Buffer==EBT_INDEX)
257  MappingHint_Index=NewMappingHint;
258  }
259 
262  {
264  }
265 
268  {
269  return PrimitiveType;
270  }
271 
274  {
275  if (Buffer==EBT_VERTEX_AND_INDEX ||Buffer==EBT_VERTEX)
277  if (Buffer==EBT_VERTEX_AND_INDEX || Buffer==EBT_INDEX)
278  ++ChangedID_Index;
279  }
280 
282 
284 
286 
288 
291 
295 
306  };
307 
314 } // end namespace scene
315 } // end namespace irr
316 
317 #endif
318 
319 
virtual video::E_VERTEX_TYPE getVertexType() const _IRR_OVERRIDE_
Get type of vertex data stored in this buffer.
Definition: CMeshBuffer.h:138
Change the vertex mapping.
Template implementation of the IMeshBuffer interface.
Definition: CMeshBuffer.h:17
void reallocate(u32 new_size, bool canShrink=true)
Reallocates the array, make it bigger or smaller.
Definition: irrArray.h:66
virtual u32 getIndexCount() const _IRR_OVERRIDE_
Get number of indices.
Definition: CMeshBuffer.h:96
virtual const core::vector3df & getNormal(u32 i) const _IRR_OVERRIDE_
returns normal of vertex i
Definition: CMeshBuffer.h:156
E_PRIMITIVE_TYPE
Enumeration for all primitive types there are.
video::SMaterial Material
Material for this meshbuffer.
Definition: CMeshBuffer.h:297
virtual u32 getChangedID_Index() const _IRR_OVERRIDE_
Get the currently used ID for identification of changes.
Definition: CMeshBuffer.h:287
core::array< u16 > Indices
Indices into the vertices of this buffer.
Definition: CMeshBuffer.h:301
E_HARDWARE_MAPPING MappingHint_Vertex
hardware mapping hint
Definition: CMeshBuffer.h:293
virtual E_HARDWARE_MAPPING getHardwareMappingHint_Index() const _IRR_OVERRIDE_
get the current hardware mapping hint
Definition: CMeshBuffer.h:246
GLuint GLuint GLsizei GLenum const GLvoid * indices
Definition: SDL_opengl.h:1571
CMeshBuffer< video::S3DVertex > SMeshBuffer
Standard meshbuffer.
Definition: CMeshBuffer.h:309
const T * const_pointer() const
Gets a const pointer to the array.
Definition: irrArray.h:356
virtual video::SMaterial & getMaterial() _IRR_OVERRIDE_
Get material of this meshbuffer.
Definition: CMeshBuffer.h:42
virtual u32 getChangedID_Vertex() const _IRR_OVERRIDE_
Get the currently used ID for identification of changes.
Definition: CMeshBuffer.h:283
virtual void recalculateBoundingBox() _IRR_OVERRIDE_
Recalculate the bounding box.
Definition: CMeshBuffer.h:121
virtual void setPrimitiveType(E_PRIMITIVE_TYPE type) _IRR_OVERRIDE_
Describe what kind of primitive geometry is used by the meshbuffer.
Definition: CMeshBuffer.h:261
virtual const core::vector3df & getPosition(u32 i) const _IRR_OVERRIDE_
returns position of vertex i
Definition: CMeshBuffer.h:144
Everything in the Irrlicht Engine can be found in this namespace.
Definition: CARSADPad.h:6
Don't store on the hardware.
virtual u16 * getIndices() _IRR_OVERRIDE_
Get pointer to indices.
Definition: CMeshBuffer.h:88
virtual void append(const IMeshBuffer *const other) _IRR_OVERRIDE_
Append the meshbuffer to the current buffer.
Definition: CMeshBuffer.h:214
virtual const video::SMaterial & getMaterial() const _IRR_OVERRIDE_
Get material of this meshbuffer.
Definition: CMeshBuffer.h:34
virtual core::vector2df & getTCoords(u32 i) _IRR_OVERRIDE_
returns texture coord of vertex i
Definition: CMeshBuffer.h:174
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:111
virtual u32 getVertexCount() const _IRR_OVERRIDE_
Get number of vertices.
Definition: CMeshBuffer.h:66
bool empty() const
Check if array is empty.
Definition: irrArray.h:381
unsigned short u16
16 bit unsigned variable.
Definition: irrTypes.h:44
virtual const void * getVertices() const _IRR_OVERRIDE_
Get pointer to vertices.
Definition: CMeshBuffer.h:50
Struct for holding a mesh with a single material.
Definition: IMeshBuffer.h:39
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
Explicitly set all vertices for each triangle.
virtual E_PRIMITIVE_TYPE getPrimitiveType() const _IRR_OVERRIDE_
Get the kind of primitive geometry which is used by the meshbuffer.
Definition: CMeshBuffer.h:267
Change both vertex and index mapping to the same value.
E_HARDWARE_MAPPING MappingHint_Index
Definition: CMeshBuffer.h:294
virtual core::vector3df & getPosition(u32 i) _IRR_OVERRIDE_
returns position of vertex i
Definition: CMeshBuffer.h:150
u32 size() const
Get number of occupied elements of the array.
Definition: irrArray.h:364
core::aabbox3d< f32 > BoundingBox
Bounding box of this meshbuffer.
Definition: CMeshBuffer.h:303
CMeshBuffer< video::S3DVertex2TCoords > SMeshBufferLightMap
Meshbuffer with two texture coords per vertex, e.g. for lightmaps.
Definition: CMeshBuffer.h:311
virtual video::E_INDEX_TYPE getIndexType() const _IRR_OVERRIDE_
Get type of index data which is stored in this meshbuffer.
Definition: CMeshBuffer.h:73
virtual void * getVertices() _IRR_OVERRIDE_
Get pointer to vertices.
Definition: CMeshBuffer.h:58
virtual void setHardwareMappingHint(E_HARDWARE_MAPPING NewMappingHint, E_BUFFER_TYPE Buffer=EBT_VERTEX_AND_INDEX) _IRR_OVERRIDE_
set the hardware mapping hint, for driver
Definition: CMeshBuffer.h:252
virtual const core::aabbox3d< f32 > & getBoundingBox() const _IRR_OVERRIDE_
Get the axis aligned bounding box.
Definition: CMeshBuffer.h:104
Change the index mapping.
virtual void append(const void *const vertices, u32 numVertices, const u16 *const indices, u32 numIndices) _IRR_OVERRIDE_
Append the vertices and indices to the current buffer.
Definition: CMeshBuffer.h:185
void addInternalPoint(const vector3d< T > &p)
Adds a point to the bounding box.
Definition: aabbox3d.h:74
virtual E_HARDWARE_MAPPING getHardwareMappingHint_Vertex() const _IRR_OVERRIDE_
get the current hardware mapping hint
Definition: CMeshBuffer.h:240
#define _IRR_OVERRIDE_
Defines an override macro, to protect virtual functions from typos and other mismatches.
Definition: irrTypes.h:216
virtual void setDirty(E_BUFFER_TYPE Buffer=EBT_VERTEX_AND_INDEX) _IRR_OVERRIDE_
flags the mesh as changed, reloads hardware buffers
Definition: CMeshBuffer.h:273
virtual const u16 * getIndices() const _IRR_OVERRIDE_
Get pointer to indices.
Definition: CMeshBuffer.h:80
void setDebugName(const c8 *newName)
Sets the debug name of the object.
core::array< T > Vertices
Vertices of this buffer.
Definition: CMeshBuffer.h:299
GLuint GLuint GLsizei GLenum type
Definition: SDL_opengl.h:1571
virtual const core::vector2df & getTCoords(u32 i) const _IRR_OVERRIDE_
returns texture coord of vertex i
Definition: CMeshBuffer.h:168
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:313
#define const
Definition: zconf.h:217
virtual void setBoundingBox(const core::aabbox3df &box) _IRR_OVERRIDE_
Set the axis aligned bounding box.
Definition: CMeshBuffer.h:113
Struct for holding parameters for a material renderer.
Definition: SMaterial.h:304
T * pointer()
Gets a pointer to the array.
Definition: irrArray.h:348
E_PRIMITIVE_TYPE PrimitiveType
Primitive type used for rendering (triangles, lines, ...)
Definition: CMeshBuffer.h:305
CMeshBuffer()
Default constructor for empty meshbuffer.
Definition: CMeshBuffer.h:21
virtual core::vector3df & getNormal(u32 i) _IRR_OVERRIDE_
returns normal of vertex i
Definition: CMeshBuffer.h:162