1 // Copyright (C) 2002-2012 Nikolaus Gebhardt
\r
2 // This file is part of the "Irrlicht Engine".
\r
3 // For conditions of distribution and use, see copyright notice in irrlicht.h
\r
5 #ifndef __S_SHARED_MESH_BUFFER_H_INCLUDED__
\r
6 #define __S_SHARED_MESH_BUFFER_H_INCLUDED__
\r
8 #include "irrArray.h"
\r
9 #include "IMeshBuffer.h"
\r
15 //! Implementation of the IMeshBuffer interface with shared vertex list
\r
16 struct SSharedMeshBuffer : public IMeshBuffer
\r
19 SSharedMeshBuffer()
\r
21 , Vertices(0), ChangedID_Vertex(1), ChangedID_Index(1)
\r
22 , MappingHintVertex(EHM_NEVER), MappingHintIndex(EHM_NEVER)
\r
23 , PrimitiveType(EPT_TRIANGLES)
\r
26 setDebugName("SSharedMeshBuffer");
\r
31 SSharedMeshBuffer(core::array<video::S3DVertex> *vertices) : IMeshBuffer(), Vertices(vertices), ChangedID_Vertex(1), ChangedID_Index(1), MappingHintVertex(EHM_NEVER), MappingHintIndex(EHM_NEVER)
\r
34 setDebugName("SSharedMeshBuffer");
\r
38 //! returns the material of this meshbuffer
\r
39 virtual const video::SMaterial& getMaterial() const _IRR_OVERRIDE_
\r
44 //! returns the material of this meshbuffer
\r
45 virtual video::SMaterial& getMaterial() _IRR_OVERRIDE_
\r
50 //! returns pointer to vertices
\r
51 virtual const void* getVertices() const _IRR_OVERRIDE_
\r
54 return Vertices->const_pointer();
\r
59 //! returns pointer to vertices
\r
60 virtual void* getVertices() _IRR_OVERRIDE_
\r
63 return Vertices->pointer();
\r
68 //! returns amount of vertices
\r
69 virtual u32 getVertexCount() const _IRR_OVERRIDE_
\r
72 return Vertices->size();
\r
77 //! returns pointer to indices
\r
78 virtual const u16* getIndices() const _IRR_OVERRIDE_
\r
80 return Indices.const_pointer();
\r
83 //! returns pointer to indices
\r
84 virtual u16* getIndices() _IRR_OVERRIDE_
\r
86 return Indices.pointer();
\r
89 //! returns amount of indices
\r
90 virtual u32 getIndexCount() const _IRR_OVERRIDE_
\r
92 return Indices.size();
\r
95 //! Get type of index data which is stored in this meshbuffer.
\r
96 virtual video::E_INDEX_TYPE getIndexType() const _IRR_OVERRIDE_
\r
98 return video::EIT_16BIT;
\r
101 //! returns an axis aligned bounding box
\r
102 virtual const core::aabbox3d<f32>& getBoundingBox() const _IRR_OVERRIDE_
\r
104 return BoundingBox;
\r
107 //! set user axis aligned bounding box
\r
108 virtual void setBoundingBox( const core::aabbox3df& box) _IRR_OVERRIDE_
\r
113 //! returns which type of vertex data is stored.
\r
114 virtual video::E_VERTEX_TYPE getVertexType() const _IRR_OVERRIDE_
\r
116 return video::EVT_STANDARD;
\r
119 //! recalculates the bounding box. should be called if the mesh changed.
\r
120 virtual void recalculateBoundingBox() _IRR_OVERRIDE_
\r
122 if (!Vertices || Vertices->empty() || Indices.empty())
\r
123 BoundingBox.reset(0,0,0);
\r
126 BoundingBox.reset((*Vertices)[Indices[0]].Pos);
\r
127 for (u32 i=1; i<Indices.size(); ++i)
\r
128 BoundingBox.addInternalPoint((*Vertices)[Indices[i]].Pos);
\r
132 //! returns position of vertex i
\r
133 virtual const core::vector3df& getPosition(u32 i) const _IRR_OVERRIDE_
\r
135 _IRR_DEBUG_BREAK_IF(!Vertices);
\r
136 return (*Vertices)[Indices[i]].Pos;
\r
139 //! returns position of vertex i
\r
140 virtual core::vector3df& getPosition(u32 i) _IRR_OVERRIDE_
\r
142 _IRR_DEBUG_BREAK_IF(!Vertices);
\r
143 return (*Vertices)[Indices[i]].Pos;
\r
146 //! returns normal of vertex i
\r
147 virtual const core::vector3df& getNormal(u32 i) const _IRR_OVERRIDE_
\r
149 _IRR_DEBUG_BREAK_IF(!Vertices);
\r
150 return (*Vertices)[Indices[i]].Normal;
\r
153 //! returns normal of vertex i
\r
154 virtual core::vector3df& getNormal(u32 i) _IRR_OVERRIDE_
\r
156 _IRR_DEBUG_BREAK_IF(!Vertices);
\r
157 return (*Vertices)[Indices[i]].Normal;
\r
160 //! returns texture coord of vertex i
\r
161 virtual const core::vector2df& getTCoords(u32 i) const _IRR_OVERRIDE_
\r
163 _IRR_DEBUG_BREAK_IF(!Vertices);
\r
164 return (*Vertices)[Indices[i]].TCoords;
\r
167 //! returns texture coord of vertex i
\r
168 virtual core::vector2df& getTCoords(u32 i) _IRR_OVERRIDE_
\r
170 _IRR_DEBUG_BREAK_IF(!Vertices);
\r
171 return (*Vertices)[Indices[i]].TCoords;
\r
174 //! append the vertices and indices to the current buffer
\r
175 virtual void append(const void* const vertices, u32 numVertices, const u16* const indices, u32 numIndices) _IRR_OVERRIDE_ {}
\r
176 //! append the meshbuffer to the current buffer
\r
177 virtual void append(const IMeshBuffer* const other) _IRR_OVERRIDE_ {}
\r
179 //! get the current hardware mapping hint
\r
180 virtual E_HARDWARE_MAPPING getHardwareMappingHint_Vertex() const _IRR_OVERRIDE_
\r
182 return MappingHintVertex;
\r
185 //! get the current hardware mapping hint
\r
186 virtual E_HARDWARE_MAPPING getHardwareMappingHint_Index() const _IRR_OVERRIDE_
\r
188 return MappingHintIndex;
\r
191 //! set the hardware mapping hint, for driver
\r
192 virtual void setHardwareMappingHint( E_HARDWARE_MAPPING NewMappingHint, E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX ) _IRR_OVERRIDE_
\r
194 if (buffer==EBT_VERTEX_AND_INDEX || buffer==EBT_VERTEX)
\r
195 MappingHintVertex=NewMappingHint;
\r
196 if (buffer==EBT_VERTEX_AND_INDEX || buffer==EBT_INDEX)
\r
197 MappingHintIndex=NewMappingHint;
\r
200 //! Describe what kind of primitive geometry is used by the meshbuffer
\r
201 virtual void setPrimitiveType(E_PRIMITIVE_TYPE type) _IRR_OVERRIDE_
\r
203 PrimitiveType = type;
\r
206 //! Get the kind of primitive geometry which is used by the meshbuffer
\r
207 virtual E_PRIMITIVE_TYPE getPrimitiveType() const _IRR_OVERRIDE_
\r
209 return PrimitiveType;
\r
212 //! flags the mesh as changed, reloads hardware buffers
\r
213 virtual void setDirty(E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX) _IRR_OVERRIDE_
\r
215 if (buffer==EBT_VERTEX_AND_INDEX || buffer==EBT_VERTEX)
\r
216 ++ChangedID_Vertex;
\r
217 if (buffer==EBT_VERTEX_AND_INDEX || buffer==EBT_INDEX)
\r
221 //! Get the currently used ID for identification of changes.
\r
222 /** This shouldn't be used for anything outside the VideoDriver. */
\r
223 virtual u32 getChangedID_Vertex() const _IRR_OVERRIDE_ {return ChangedID_Vertex;}
\r
225 //! Get the currently used ID for identification of changes.
\r
226 /** This shouldn't be used for anything outside the VideoDriver. */
\r
227 virtual u32 getChangedID_Index() const _IRR_OVERRIDE_ {return ChangedID_Index;}
\r
229 //! Material of this meshBuffer
\r
230 video::SMaterial Material;
\r
232 //! Shared Array of vertices
\r
233 core::array<video::S3DVertex> *Vertices;
\r
235 //! Array of indices
\r
236 core::array<u16> Indices;
\r
238 //! ID used for hardware buffer management
\r
239 u32 ChangedID_Vertex;
\r
241 //! ID used for hardware buffer management
\r
242 u32 ChangedID_Index;
\r
245 core::aabbox3df BoundingBox;
\r
247 //! hardware mapping hint
\r
248 E_HARDWARE_MAPPING MappingHintVertex;
\r
249 E_HARDWARE_MAPPING MappingHintIndex;
\r
251 //! Primitive type used for rendering (triangles, lines, ...)
\r
252 E_PRIMITIVE_TYPE PrimitiveType;
\r
256 } // end namespace scene
\r
257 } // end namespace irr
\r