Irrlicht 3D Engine
CVertexBuffer.h
Go to the documentation of this file.
1 // Copyright (C) 2008-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 __C_VERTEX_BUFFER_H_INCLUDED__
6 #define __C_VERTEX_BUFFER_H_INCLUDED__
7 
8 #include "IVertexBuffer.h"
9 
10 
11 namespace irr
12 {
13 namespace scene
14 {
15 
17  {
18  class IVertexList
19  {
20  public:
21  virtual ~IVertexList(){};
22 
23  virtual u32 stride() const =0;
24 
25  virtual u32 size() const =0;
26 
27  virtual void push_back (const video::S3DVertex &element) =0;
28  virtual video::S3DVertex& operator [](const u32 index) const =0;
29  virtual video::S3DVertex& getLast() =0;
30  virtual void set_used(u32 usedNow) =0;
31  virtual void reallocate(u32 new_size) =0;
32  virtual u32 allocated_size() const =0;
33  virtual video::S3DVertex* pointer() =0;
34  virtual video::E_VERTEX_TYPE getType() const =0;
35  };
36 
37  template <class T>
38  class CSpecificVertexList : public IVertexList
39  {
40  public:
42 
43  virtual u32 stride() const {return sizeof(T);}
44 
45  virtual u32 size() const {return Vertices.size();}
46 
47  virtual void push_back (const video::S3DVertex &element)
48  {Vertices.push_back((T&)element);}
49 
50  virtual video::S3DVertex& operator [](const u32 index) const
51  {return (video::S3DVertex&)Vertices[index];}
52 
53  virtual video::S3DVertex& getLast()
54  {return (video::S3DVertex&)Vertices.getLast();}
55 
56  virtual void set_used(u32 usedNow)
57  {Vertices.set_used(usedNow);}
58 
59  virtual void reallocate(u32 new_size)
60  {Vertices.reallocate(new_size);}
61 
62  virtual u32 allocated_size() const
63  {
64  return Vertices.allocated_size();
65  }
66 
67  virtual video::S3DVertex* pointer() {return Vertices.pointer();}
68 
69  virtual video::E_VERTEX_TYPE getType() const {return T().getType();}
70  };
71 
72  public:
73  IVertexList *Vertices;
74 
75  CVertexBuffer(video::E_VERTEX_TYPE vertexType) : Vertices(0),
77  {
78  setType(vertexType);
79  }
80 
81  CVertexBuffer(const IVertexBuffer &VertexBufferCopy) :
82  Vertices(0), MappingHint(EHM_NEVER),
83  ChangedID(1)
84  {
85  setType(VertexBufferCopy.getType());
86  reallocate(VertexBufferCopy.size());
87 
88  for (u32 n=0;n<VertexBufferCopy.size();++n)
89  push_back(VertexBufferCopy[n]);
90  }
91 
92  virtual ~CVertexBuffer()
93  {
94  delete Vertices;
95  }
96 
97 
98  virtual void setType(video::E_VERTEX_TYPE vertexType)
99  {
100  IVertexList *NewVertices=0;
101 
102  switch (vertexType)
103  {
104  case video::EVT_STANDARD:
105  {
106  NewVertices=new CSpecificVertexList<video::S3DVertex>;
107  break;
108  }
109  case video::EVT_2TCOORDS:
110  {
111  NewVertices=new CSpecificVertexList<video::S3DVertex2TCoords>;
112  break;
113  }
114  case video::EVT_TANGENTS:
115  {
116  NewVertices=new CSpecificVertexList<video::S3DVertexTangents>;
117  break;
118  }
119  }
120  if (Vertices)
121  {
122  NewVertices->reallocate( Vertices->size() );
123 
124  for(u32 n=0;n<Vertices->size();++n)
125  NewVertices->push_back((*Vertices)[n]);
126 
127  delete Vertices;
128  }
129 
130  Vertices=NewVertices;
131  }
132 
133  virtual void* getData() {return Vertices->pointer();}
134 
135  virtual video::E_VERTEX_TYPE getType() const {return Vertices->getType();}
136 
137  virtual u32 stride() const {return Vertices->stride();}
138 
139  virtual u32 size() const
140  {
141  return Vertices->size();
142  }
143 
144  virtual void push_back (const video::S3DVertex &element)
145  {
146  Vertices->push_back(element);
147  }
148 
149  virtual video::S3DVertex& operator [](const u32 index) const
150  {
151  return (*Vertices)[index];
152  }
153 
155  {
156  return Vertices->getLast();
157  }
158 
159  virtual void set_used(u32 usedNow)
160  {
161  Vertices->set_used(usedNow);
162  }
163 
164  virtual void reallocate(u32 new_size)
165  {
166  Vertices->reallocate(new_size);
167  }
168 
169  virtual u32 allocated_size() const
170  {
171  return Vertices->allocated_size();
172  }
173 
175  {
176  return Vertices->pointer();
177  }
178 
181  {
182  return MappingHint;
183  }
184 
186  virtual void setHardwareMappingHint( E_HARDWARE_MAPPING NewMappingHint )
187  {
188  MappingHint=NewMappingHint;
189  }
190 
192  virtual void setDirty()
193  {
194  ++ChangedID;
195  }
196 
198 
199  virtual u32 getChangedID() const {return ChangedID;}
200 
203  };
204 
205 
206 } // end namespace scene
207 } // end namespace irr
208 
209 #endif
210 
virtual void setType(video::E_VERTEX_TYPE vertexType)
Definition: CVertexBuffer.h:98
virtual u32 size() const =0
void set_used(u32 usedNow)
Sets the size of the array and allocates new elements if necessary.
Definition: irrArray.h:257
void reallocate(u32 new_size, bool canShrink=true)
Reallocates the array, make it bigger or smaller.
Definition: irrArray.h:67
virtual E_HARDWARE_MAPPING getHardwareMappingHint() const
get the current hardware mapping hint
virtual video::S3DVertex & operator[](const u32 index) const
CVertexBuffer(video::E_VERTEX_TYPE vertexType)
Definition: CVertexBuffer.h:75
virtual video::S3DVertex & getLast()
Everything in the Irrlicht Engine can be found in this namespace.
Definition: aabbox3d.h:12
Don&#39;t store on the hardware.
u32 allocated_size() const
Get amount of memory allocated.
Definition: irrArray.h:377
virtual u32 stride() const
T & getLast()
Gets last element.
Definition: irrArray.h:333
Vertex with two texture coordinates, video::S3DVertex2TCoords.
Definition: S3DVertex.h:25
virtual void set_used(u32 usedNow)
void push_back(const T &element)
Adds an element at back of array.
Definition: irrArray.h:112
Vertex with a tangent and binormal vector, video::S3DVertexTangents.
Definition: S3DVertex.h:29
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:58
Standard vertex type used by the Irrlicht engine, video::S3DVertex.
Definition: S3DVertex.h:21
virtual video::E_VERTEX_TYPE getType() const =0
u32 size() const
Get number of occupied elements of the array.
Definition: irrArray.h:368
standard vertex used by the Irrlicht engine.
Definition: S3DVertex.h:42
CVertexBuffer(const IVertexBuffer &VertexBufferCopy)
Definition: CVertexBuffer.h:81
virtual u32 getChangedID() const
Get the currently used ID for identification of changes.
virtual void setDirty()
flags the mesh as changed, reloads hardware buffers
virtual void push_back(const video::S3DVertex &element)
E_HARDWARE_MAPPING MappingHint
virtual u32 size() const
E_VERTEX_TYPE
Enumeration for all vertex types there are.
Definition: S3DVertex.h:18
virtual video::S3DVertex * pointer()
virtual void * getData()
virtual video::E_VERTEX_TYPE getType() const
virtual u32 allocated_size() const
virtual void setHardwareMappingHint(E_HARDWARE_MAPPING NewMappingHint)
set the hardware mapping hint, for driver
T * pointer()
Gets a pointer to the array.
Definition: irrArray.h:352
virtual void reallocate(u32 new_size)