Irrlicht 3D Engine
 
Loading...
Searching...
No Matches
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
11namespace irr
12{
13namespace 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:
41 core::array<T> Vertices;
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
77 {
78 setType(vertexType);
79 }
80
81 CVertexBuffer(const IVertexBuffer &VertexBufferCopy) :
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
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 {
105 {
106 NewVertices=new CSpecificVertexList<video::S3DVertex>;
107 break;
108 }
110 {
111 NewVertices=new CSpecificVertexList<video::S3DVertex2TCoords>;
112 break;
113 }
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
Axis aligned bounding box in 3d dimensional space.
Definition aabbox3d.h:22
virtual u32 allocated_size() const
virtual video::S3DVertex & operator[](const u32 index) const
virtual video::S3DVertex * pointer()
virtual E_HARDWARE_MAPPING getHardwareMappingHint() const
get the current hardware mapping hint
virtual void set_used(u32 usedNow)
virtual void reallocate(u32 new_size)
virtual video::S3DVertex & getLast()
virtual void setHardwareMappingHint(E_HARDWARE_MAPPING NewMappingHint)
set the hardware mapping hint, for driver
virtual void push_back(const video::S3DVertex &element)
virtual u32 size() const
E_HARDWARE_MAPPING MappingHint
virtual void setType(video::E_VERTEX_TYPE vertexType)
CVertexBuffer(const IVertexBuffer &VertexBufferCopy)
virtual u32 getChangedID() const
Get the currently used ID for identification of changes.
virtual void setDirty()
flags the mesh as changed, reloads hardware buffers
CVertexBuffer(video::E_VERTEX_TYPE vertexType)
virtual u32 stride() const
virtual video::E_VERTEX_TYPE getType() const
virtual video::E_VERTEX_TYPE getType() const =0
virtual u32 size() const =0
@ EHM_NEVER
Don't store on the hardware.
E_VERTEX_TYPE
Enumeration for all vertex types there are.
Definition S3DVertex.h:19
@ EVT_2TCOORDS
Vertex with two texture coordinates, video::S3DVertex2TCoords.
Definition S3DVertex.h:25
@ EVT_TANGENTS
Vertex with a tangent and binormal vector, video::S3DVertexTangents.
Definition S3DVertex.h:29
@ EVT_STANDARD
Standard vertex type used by the Irrlicht engine, video::S3DVertex.
Definition S3DVertex.h:21
Everything in the Irrlicht Engine can be found in this namespace.
Definition aabbox3d.h:13
unsigned int u32
32 bit unsigned variable.
Definition irrTypes.h:58
standard vertex used by the Irrlicht engine.
Definition S3DVertex.h:43