Nirtcpp 2.1.0
Nirtcpp is a high-performance c++ graphics engine.
Loading...
Searching...
No Matches
CVertexBuffer.hpp
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 nirtcpp/nirtcpp.hpp
4
5#ifndef NIRT_C_VERTEX_BUFFER_HPP_INCLUDED
6#define NIRT_C_VERTEX_BUFFER_HPP_INCLUDED
7
8#include <nirtcpp/core/engine/IVertexBuffer.hpp>
9
10
11namespace nirt
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 void push_back(const video::S3DVertex2TCoords &element) =0;
29 virtual void push_back(const video::S3DVertexTangents &element) =0;
30 virtual void setValue(u32 index, const video::S3DVertex &value) =0;
31 virtual void setValue(u32 index, const video::S3DVertex2TCoords &value) =0;
32 virtual void setValue(u32 index, const video::S3DVertexTangents &value) =0;
33
34 virtual video::S3DVertex& operator [](u32 index) = 0;
35 virtual video::S3DVertex& operator [](const u32 index) const =0;
36 virtual video::S3DVertex& getLast() =0;
37 virtual void set_used(u32 usedNow) =0;
38 virtual void reallocate(u32 new_size, bool canShrink=true) =0;
39 virtual u32 allocated_size() const =0;
40 virtual void* pointer() =0;
41 virtual const void* const_pointer() const =0;
42 virtual video::E_VERTEX_TYPE getType() const =0;
43 };
44
45 template <class T>
46 class CSpecificVertexList : public IVertexList
47 {
48 public:
49 core::array<T> Vertices;
50
51 virtual u32 stride() const override {return sizeof(T);}
52
53 virtual u32 size() const override {return Vertices.size();}
54
55 virtual void push_back (const video::S3DVertex &element) override
56 {Vertices.push_back(element);}
57 virtual void push_back(const video::S3DVertex2TCoords &element) override
58 {Vertices.push_back(element);}
59 virtual void push_back(const video::S3DVertexTangents &element) override
60 {Vertices.push_back(element);}
61
62 virtual void setValue(u32 index, const video::S3DVertex &value) override
63 {Vertices[index] = value;}
64 virtual void setValue(u32 index, const video::S3DVertex2TCoords &value) override
65 {Vertices[index] = value;}
66 virtual void setValue(u32 index, const video::S3DVertexTangents &value) override
67 {Vertices[index] = value;}
68
69 virtual video::S3DVertex& operator [](u32 index) override
70 {return (video::S3DVertex&)Vertices[index];}
71
72 virtual video::S3DVertex& operator [](const u32 index) const override
73 {return (video::S3DVertex&)Vertices[index];}
74
75 virtual video::S3DVertex& getLast() override
76 {return (video::S3DVertex&)Vertices.getLast();}
77
78 virtual void set_used(u32 usedNow) override
79 {Vertices.set_used(usedNow);}
80
81 virtual void reallocate(u32 new_size, bool canShrink) override
82 {Vertices.reallocate(new_size, canShrink);}
83
84 virtual u32 allocated_size() const override
85 {
86 return Vertices.allocated_size();
87 }
88
89 virtual void* pointer() override {return Vertices.pointer();}
90 virtual const void* const_pointer() const override {return Vertices.const_pointer();}
91
92 virtual video::E_VERTEX_TYPE getType() const override {return T::getType();}
93 };
94
95 public:
96 IVertexList *Vertices;
97
98 CVertexBuffer(video::E_VERTEX_TYPE vertexType) : Vertices(0),
99 MappingHint(EHM_NEVER), ChangedID(1)
100 {
101 setType(vertexType);
102 }
103
104 CVertexBuffer(const IVertexBuffer &VertexBufferCopy) :
105 Vertices(0), MappingHint(EHM_NEVER),
106 ChangedID(1)
107 {
108 setType(VertexBufferCopy.getType());
109 reallocate(VertexBufferCopy.size());
110
111 for (u32 n=0;n<VertexBufferCopy.size();++n)
112 push_back(VertexBufferCopy[n]);
113 }
114
115 virtual ~CVertexBuffer()
116 {
117 delete Vertices;
118 }
119
120 virtual void setType(video::E_VERTEX_TYPE vertexType) override
121 {
122 if ( Vertices && Vertices->getType() == vertexType )
123 return;
124
125 IVertexList *NewVertices=0;
126
127 switch (vertexType)
128 {
130 {
131 NewVertices=new CSpecificVertexList<video::S3DVertex>;
132 break;
133 }
135 {
136 NewVertices=new CSpecificVertexList<video::S3DVertex2TCoords>;
137 break;
138 }
140 {
141 NewVertices=new CSpecificVertexList<video::S3DVertexTangents>;
142 break;
143 }
144 }
145 if (Vertices)
146 {
147 NewVertices->reallocate( Vertices->size() );
148
149 switch (Vertices->getType()) // old type
150 {
152 {
153 for(u32 n=0;n<Vertices->size();++n)
154 NewVertices->push_back((*Vertices)[n]);
155 break;
156 }
158 {
159 for(u32 n=0;n<Vertices->size();++n)
160 NewVertices->push_back((video::S3DVertex2TCoords&)(*Vertices)[n]);
161 break;
162 }
164 {
165 for(u32 n=0;n<Vertices->size();++n)
166 NewVertices->push_back((video::S3DVertexTangents&)(*Vertices)[n]);
167 break;
168 }
169 }
170
171 delete Vertices;
172 }
173
174 Vertices=NewVertices;
175 }
176
177 virtual void* getData() override {return Vertices->pointer();}
178 virtual const void* getData() const override {return Vertices->const_pointer();}
179
180 virtual video::E_VERTEX_TYPE getType() const override {return Vertices->getType();}
181
182 virtual u32 stride() const override {return Vertices->stride();}
183
184 virtual u32 size() const override
185 {
186 return Vertices->size();
187 }
188
189 virtual void push_back (const video::S3DVertex &element) override
190 {
191 Vertices->push_back(element);
192 }
193
194 virtual void push_back(const video::S3DVertex2TCoords &element) override
195 {
196 Vertices->push_back(element);
197 }
198
199 virtual void push_back(const video::S3DVertexTangents &element) override
200 {
201 Vertices->push_back(element);
202 }
203
204 virtual void setValue(u32 index, const video::S3DVertex &value) override
205 {
206 Vertices->setValue(index, value);
207 }
208
209 virtual void setValue(u32 index, const video::S3DVertex2TCoords &value) override
210 {
211 Vertices->setValue(index, value);
212 }
213
214 virtual void setValue(u32 index, const video::S3DVertexTangents &value) override
215 {
216 Vertices->setValue(index, value);
217 }
218
219 virtual video::S3DVertex& operator [](u32 index) override
220 {
221 return (*Vertices)[index];
222 }
223
224 virtual video::S3DVertex& operator [](const u32 index) const override
225 {
226 return (*Vertices)[index];
227 }
228
229 virtual video::S3DVertex& getLast() override
230 {
231 return Vertices->getLast();
232 }
233
234 virtual void set_used(u32 usedNow) override
235 {
236 Vertices->set_used(usedNow);
237 }
238
239 virtual void reallocate(u32 new_size, bool canShrink=true) override
240 {
241 Vertices->reallocate(new_size, canShrink);
242 }
243
244 virtual u32 allocated_size() const override
245 {
246 return Vertices->allocated_size();
247 }
248
251 {
252 return MappingHint;
253 }
254
256 virtual void setHardwareMappingHint( E_HARDWARE_MAPPING NewMappingHint ) override
257 {
258 MappingHint=NewMappingHint;
259 }
260
262 virtual void setDirty() override
263 {
264 ++ChangedID;
265 }
266
268
269 virtual u32 getChangedID() const override {return ChangedID;}
270
271 E_HARDWARE_MAPPING MappingHint;
272 u32 ChangedID;
273 };
274
275
276} // end namespace scene
277} // end namespace nirt
278
279#endif
Axis aligned bounding box in 3d dimensional space.
Definition aabbox3d.hpp:22
Definition CVertexBuffer.hpp:17
virtual void setDirty() override
flags the mesh as changed, reloads hardware buffers
Definition CVertexBuffer.hpp:262
virtual u32 stride() const override
Number of bytes per element.
Definition CVertexBuffer.hpp:182
virtual void push_back(const video::S3DVertex &element) override
Add vertex to end.
Definition CVertexBuffer.hpp:189
virtual const void * getData() const override
Const pointer to first element.
Definition CVertexBuffer.hpp:178
virtual video::S3DVertex & operator[](u32 index) override
Direct access to elements. Risky to use!
Definition CVertexBuffer.hpp:219
virtual void setHardwareMappingHint(E_HARDWARE_MAPPING NewMappingHint) override
set the hardware mapping hint, for driver
Definition CVertexBuffer.hpp:256
virtual E_HARDWARE_MAPPING getHardwareMappingHint() const override
get the current hardware mapping hint
Definition CVertexBuffer.hpp:250
virtual u32 size() const override
Number of elements.
Definition CVertexBuffer.hpp:184
virtual void setValue(u32 index, const video::S3DVertex &value) override
Set value at index. Buffer must be already large enough that element exists.
Definition CVertexBuffer.hpp:204
virtual void * getData() override
Pointer to first element of vertex data.
Definition CVertexBuffer.hpp:177
virtual u32 getChangedID() const override
Get the currently used ID for identification of changes.
Definition CVertexBuffer.hpp:269
Definition IVertexBuffer.hpp:19
virtual u32 size() const =0
Number of elements.
Vertex with two texture coordinates.
Definition S3DVertex.hpp:116
Vertex with a tangent and binormal vector.
Definition S3DVertex.hpp:199
standard vertex used by the Nirtcpp engine.
Definition S3DVertex.hpp:45
E_HARDWARE_MAPPING
Definition EHardwareBufferFlags.hpp:14
@ EHM_NEVER
Don't store on the hardware.
Definition EHardwareBufferFlags.hpp:16
E_VERTEX_TYPE
Enumeration for all vertex types there are.
Definition S3DVertex.hpp:19
@ EVT_2TCOORDS
Vertex with two texture coordinates, video::S3DVertex2TCoords.
Definition S3DVertex.hpp:25
@ EVT_STANDARD
Standard vertex type used by the Nirtcpp engine, video::S3DVertex.
Definition S3DVertex.hpp:21
@ EVT_TANGENTS
Vertex with a tangent and binormal vector, video::S3DVertexTangents.
Definition S3DVertex.hpp:31
As of Nirtcpp 1.6, position2d is a synonym for vector2d.
Definition vector3d.hpp:11
unsigned int u32
32 bit unsigned variable.
Definition irrTypes.hpp:64

Nirtcpp    @cppfx.xyz

Esvcpp    esv::print