Nirtcpp 2.1.0
Nirtcpp is a high-performance c++ graphics engine.
Loading...
Searching...
No Matches
SSharedMeshBuffer.hpp
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 nirtcpp/nirtcpp.hpp
4
5#ifndef S_SHARED_MESH_BUFFER_HPP_INCLUDED
6#define S_SHARED_MESH_BUFFER_HPP_INCLUDED
7
8#include <nirtcpp/core/engine/irrArray.hpp>
9#include <nirtcpp/core/engine/IMeshBuffer.hpp>
10
11namespace nirt
12{
13namespace scene
14{
17 {
18 public:
21 : IMeshBuffer()
23 , MappingHintVertex(EHM_NEVER), MappingHintIndex(EHM_NEVER)
25 {
26 #ifdef _DEBUG
27 setDebugName("SSharedMeshBuffer");
28 #endif
29 }
30
33 {
34 #ifdef _DEBUG
35 setDebugName("SSharedMeshBuffer");
36 #endif
37 }
38
39 public:
41 virtual const video::SMaterial& getMaterial() const override
42 {
43 return Material;
44 }
45
47 virtual video::SMaterial& getMaterial() override
48 {
49 return Material;
50 }
51
53 virtual const void* getVertices() const override
54 {
55 if (Vertices)
56 return Vertices->const_pointer();
57 else
58 return 0;
59 }
60
62 virtual void* getVertices() override
63 {
64 if (Vertices)
65 return Vertices->pointer();
66 else
67 return 0;
68 }
69
71 virtual u32 getVertexCount() const override
72 {
73 if (Vertices)
74 return Vertices->size();
75 else
76 return 0;
77 }
78
80 virtual const u16* getIndices() const override
81 {
82 return Indices.const_pointer();
83 }
84
86 virtual u16* getIndices() override
87 {
88 return Indices.pointer();
89 }
90
92 virtual u32 getIndexCount() const override
93 {
94 return Indices.size();
95 }
96
98 virtual video::E_INDEX_TYPE getIndexType() const override
99 {
100 return video::EIT_16BIT;
101 }
102
104 virtual const core::aabbox3d<f32>& getBoundingBox() const override
105 {
106 return BoundingBox;
107 }
108
110 virtual void setBoundingBox( const core::aabbox3df& box) override
111 {
112 BoundingBox = box;
113 }
114
116 virtual video::E_VERTEX_TYPE getVertexType() const override
117 {
118 return video::EVT_STANDARD;
119 }
120
122 virtual void recalculateBoundingBox() override
123 {
124 if (!Vertices || Vertices->empty() || Indices.empty())
125 BoundingBox.reset(0,0,0);
126 else
127 {
128 BoundingBox.reset((*Vertices)[Indices[0]].Pos);
129 for (u32 i=1; i<Indices.size(); ++i)
131 }
132 }
133
135 virtual const core::vector3df& getPosition(u32 i) const override
136 {
137 NIRT_DEBUG_BREAK_IF(!Vertices);
138 return (*Vertices)[Indices[i]].Pos;
139 }
140
142 virtual core::vector3df& getPosition(u32 i) override
143 {
144 NIRT_DEBUG_BREAK_IF(!Vertices);
145 return (*Vertices)[Indices[i]].Pos;
146 }
147
149 virtual const core::vector3df& getNormal(u32 i) const override
150 {
151 NIRT_DEBUG_BREAK_IF(!Vertices);
152 return (*Vertices)[Indices[i]].Normal;
153 }
154
156 virtual core::vector3df& getNormal(u32 i) override
157 {
158 NIRT_DEBUG_BREAK_IF(!Vertices);
159 return (*Vertices)[Indices[i]].Normal;
160 }
161
163 virtual const core::vector2df& getTCoords(u32 i) const override
164 {
165 NIRT_DEBUG_BREAK_IF(!Vertices);
166 return (*Vertices)[Indices[i]].TCoords;
167 }
168
170 virtual core::vector2df& getTCoords(u32 i) override
171 {
172 NIRT_DEBUG_BREAK_IF(!Vertices);
173 return (*Vertices)[Indices[i]].TCoords;
174 }
175
177 virtual video::SColor& getColor(u32 i) override
178 {
179 NIRT_DEBUG_BREAK_IF(!Vertices);
180 return (*Vertices)[Indices[i]].Color;
181 }
182
184 virtual const video::SColor& getColor(u32 i) const override
185 {
186 NIRT_DEBUG_BREAK_IF(!Vertices);
187 return (*Vertices)[Indices[i]].Color;
188 }
189
190
192 virtual void append(const void* const vertices, u32 numVertices, const u16* const indices, u32 numIndices) override
193 {
194 // can't do that as it doesn't own the vertex memory
195 }
196
198 virtual void append(const IMeshBuffer* const other) override
199 {
200 // can't do that as it doesn't own the vertex memory
201 }
202
205 {
206 return MappingHintVertex;
207 }
208
211 {
212 return MappingHintIndex;
213 }
214
216 virtual void setHardwareMappingHint( E_HARDWARE_MAPPING NewMappingHint, E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX ) override
217 {
218 if (buffer==EBT_VERTEX_AND_INDEX || buffer==EBT_VERTEX)
219 MappingHintVertex=NewMappingHint;
220 if (buffer==EBT_VERTEX_AND_INDEX || buffer==EBT_INDEX)
221 MappingHintIndex=NewMappingHint;
222 }
223
225 virtual void setPrimitiveType(E_PRIMITIVE_TYPE type) override
226 {
227 PrimitiveType = type;
228 }
229
231 virtual E_PRIMITIVE_TYPE getPrimitiveType() const override
232 {
233 return PrimitiveType;
234 }
235
237 virtual void setDirty(E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX) override
238 {
239 if (buffer==EBT_VERTEX_AND_INDEX || buffer==EBT_VERTEX)
241 if (buffer==EBT_VERTEX_AND_INDEX || buffer==EBT_INDEX)
243 }
244
246
247 virtual u32 getChangedID_Vertex() const override {return ChangedID_Vertex;}
248
250
251 virtual u32 getChangedID_Index() const override {return ChangedID_Index;}
252
254 virtual EMESH_BUFFER_TYPE getType() const override
255 {
256 return EMBT_SHARED;
257 }
258
260 virtual IMeshBuffer* createClone(int cloneFlags) const override
261 {
262 SSharedMeshBuffer * clone = new SSharedMeshBuffer();
263
264 if (cloneFlags & ECF_VERTICES)
265 {
266 clone->Vertices = Vertices;
267 clone->BoundingBox = BoundingBox;
268 }
269
270 if (cloneFlags & ECF_INDICES)
271 {
272 clone->Indices = Indices;
273 }
274
275 clone->Material = Material;
277 clone->MappingHintIndex = MappingHintIndex;
279
280 return clone;
281 }
282
283 public:
286
289
292
295
298
301
304 E_HARDWARE_MAPPING MappingHintIndex;
305
308 };
309
310} // end namespace scene
311} // end namespace nirt
312
313#endif
void setDebugName(const c8 *newName)
Sets the debug name of the object.
Definition IReferenceCounted.hpp:163
Axis aligned bounding box in 3d dimensional space.
Definition aabbox3d.hpp:22
void addInternalPoint(const vector3d< T > &p)
Adds a point to the bounding box.
Definition aabbox3d.hpp:74
void reset(T x, T y, T z)
Resets the bounding box to a one-point box.
Definition aabbox3d.hpp:50
u32 size() const
Get number of occupied elements of the array.
Definition irrArray.hpp:397
const T * const_pointer() const
Gets a const pointer to the array.
Definition irrArray.hpp:389
bool empty() const
Check if array is empty.
Definition irrArray.hpp:414
T * pointer()
Gets a pointer to the array.
Definition irrArray.hpp:381
Class for holding a mesh with a single material.
Definition IMeshBuffer.hpp:41
@ ECF_INDICES
clone the vertices (or copy pointer for SSharedMeshBuffer)
Definition IMeshBuffer.hpp:205
Implementation of the IMeshBuffer interface with shared vertex list.
Definition SSharedMeshBuffer.hpp:17
virtual E_HARDWARE_MAPPING getHardwareMappingHint_Vertex() const override
get the current hardware mapping hint
Definition SSharedMeshBuffer.hpp:204
virtual u32 getIndexCount() const override
returns amount of indices
Definition SSharedMeshBuffer.hpp:92
virtual const u16 * getIndices() const override
returns pointer to indices
Definition SSharedMeshBuffer.hpp:80
virtual u32 getVertexCount() const override
returns amount of vertices
Definition SSharedMeshBuffer.hpp:71
virtual const video::SMaterial & getMaterial() const override
returns the material of this meshbuffer
Definition SSharedMeshBuffer.hpp:41
virtual const core::vector3df & getNormal(u32 i) const override
returns normal of vertex i
Definition SSharedMeshBuffer.hpp:149
virtual void append(const IMeshBuffer *const other) override
append the meshbuffer to the current buffer
Definition SSharedMeshBuffer.hpp:198
virtual core::vector3df & getPosition(u32 i) override
returns position of vertex i
Definition SSharedMeshBuffer.hpp:142
virtual void setHardwareMappingHint(E_HARDWARE_MAPPING NewMappingHint, E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX) override
set the hardware mapping hint, for driver
Definition SSharedMeshBuffer.hpp:216
virtual video::SMaterial & getMaterial() override
returns the material of this meshbuffer
Definition SSharedMeshBuffer.hpp:47
SSharedMeshBuffer()
constructor
Definition SSharedMeshBuffer.hpp:20
virtual IMeshBuffer * createClone(int cloneFlags) const override
Create copy of the meshbuffer.
Definition SSharedMeshBuffer.hpp:260
virtual core::vector3df & getNormal(u32 i) override
returns normal of vertex i
Definition SSharedMeshBuffer.hpp:156
virtual core::vector2df & getTCoords(u32 i) override
returns texture coord of vertex i
Definition SSharedMeshBuffer.hpp:170
virtual video::SColor & getColor(u32 i) override
returns color of vertex i
Definition SSharedMeshBuffer.hpp:177
core::array< video::S3DVertex > * Vertices
Shared Array of vertices.
Definition SSharedMeshBuffer.hpp:288
virtual const video::SColor & getColor(u32 i) const override
returns color of vertex i
Definition SSharedMeshBuffer.hpp:184
virtual void setPrimitiveType(E_PRIMITIVE_TYPE type) override
Describe what kind of primitive geometry is used by the meshbuffer.
Definition SSharedMeshBuffer.hpp:225
virtual void append(const void *const vertices, u32 numVertices, const u16 *const indices, u32 numIndices) override
append the vertices and indices to the current buffer
Definition SSharedMeshBuffer.hpp:192
E_PRIMITIVE_TYPE PrimitiveType
Primitive type used for rendering (triangles, lines, ...)
Definition SSharedMeshBuffer.hpp:307
virtual void setBoundingBox(const core::aabbox3df &box) override
set user axis aligned bounding box
Definition SSharedMeshBuffer.hpp:110
virtual video::E_INDEX_TYPE getIndexType() const override
Get type of index data which is stored in this meshbuffer.
Definition SSharedMeshBuffer.hpp:98
virtual E_HARDWARE_MAPPING getHardwareMappingHint_Index() const override
get the current hardware mapping hint
Definition SSharedMeshBuffer.hpp:210
u32 ChangedID_Vertex
ID used for hardware buffer management.
Definition SSharedMeshBuffer.hpp:294
virtual u16 * getIndices() override
returns pointer to indices
Definition SSharedMeshBuffer.hpp:86
virtual u32 getChangedID_Index() const override
Get the currently used ID for identification of changes.
Definition SSharedMeshBuffer.hpp:251
virtual const core::vector3df & getPosition(u32 i) const override
returns position of vertex i
Definition SSharedMeshBuffer.hpp:135
virtual video::E_VERTEX_TYPE getVertexType() const override
returns which type of vertex data is stored.
Definition SSharedMeshBuffer.hpp:116
virtual const core::aabbox3d< f32 > & getBoundingBox() const override
returns an axis aligned bounding box
Definition SSharedMeshBuffer.hpp:104
virtual void recalculateBoundingBox() override
recalculates the bounding box. should be called if the mesh changed.
Definition SSharedMeshBuffer.hpp:122
virtual const core::vector2df & getTCoords(u32 i) const override
returns texture coord of vertex i
Definition SSharedMeshBuffer.hpp:163
video::SMaterial Material
Material of this meshBuffer.
Definition SSharedMeshBuffer.hpp:285
virtual void setDirty(E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX) override
flags the mesh as changed, reloads hardware buffers
Definition SSharedMeshBuffer.hpp:237
SSharedMeshBuffer(core::array< video::S3DVertex > *vertices)
constructor
Definition SSharedMeshBuffer.hpp:32
u32 ChangedID_Index
ID used for hardware buffer management.
Definition SSharedMeshBuffer.hpp:297
E_HARDWARE_MAPPING MappingHintVertex
hardware mapping hint
Definition SSharedMeshBuffer.hpp:303
core::aabbox3df BoundingBox
Bounding box.
Definition SSharedMeshBuffer.hpp:300
virtual E_PRIMITIVE_TYPE getPrimitiveType() const override
Get the kind of primitive geometry which is used by the meshbuffer.
Definition SSharedMeshBuffer.hpp:231
virtual const void * getVertices() const override
returns pointer to vertices
Definition SSharedMeshBuffer.hpp:53
core::array< u16 > Indices
Array of indices.
Definition SSharedMeshBuffer.hpp:291
virtual EMESH_BUFFER_TYPE getType() const override
Returns type of the class implementing the IMeshBuffer.
Definition SSharedMeshBuffer.hpp:254
virtual u32 getChangedID_Vertex() const override
Get the currently used ID for identification of changes.
Definition SSharedMeshBuffer.hpp:247
virtual void * getVertices() override
returns pointer to vertices
Definition SSharedMeshBuffer.hpp:62
Class representing a 32 bit ARGB color.
Definition SColor.hpp:317
Class for holding parameters for a material renderer.
Definition SMaterial.hpp:304
E_BUFFER_TYPE
Definition EHardwareBufferFlags.hpp:29
@ EBT_VERTEX_AND_INDEX
Change both vertex and index mapping to the same value.
Definition EHardwareBufferFlags.hpp:37
@ EBT_INDEX
Change the index mapping.
Definition EHardwareBufferFlags.hpp:35
@ EBT_VERTEX
Change the vertex mapping.
Definition EHardwareBufferFlags.hpp:33
E_PRIMITIVE_TYPE
Enumeration for all primitive types there are.
Definition EPrimitiveTypes.hpp:15
@ EPT_TRIANGLES
Explicitly set all vertices for each triangle.
Definition EPrimitiveTypes.hpp:37
E_HARDWARE_MAPPING
Definition EHardwareBufferFlags.hpp:14
@ EHM_NEVER
Don't store on the hardware.
Definition EHardwareBufferFlags.hpp:16
EMESH_BUFFER_TYPE
An enumeration for all types of built-in mesh buffers.
Definition EMeshBufferTypes.hpp:18
E_VERTEX_TYPE
Enumeration for all vertex types there are.
Definition S3DVertex.hpp:19
@ EVT_STANDARD
Standard vertex type used by the Nirtcpp engine, video::S3DVertex.
Definition S3DVertex.hpp:21
As of Nirtcpp 1.6, position2d is a synonym for vector2d.
Definition vector3d.hpp:11
unsigned short u16
16 bit unsigned variable.
Definition irrTypes.hpp:46
unsigned int u32
32 bit unsigned variable.
Definition irrTypes.hpp:64

Nirtcpp    @cppfx.xyz

Esvcpp    esv::print