Go to the documentation of this file.00001
00002
00003
00004
00005 #ifndef __S_SHARED_MESH_BUFFER_H_INCLUDED__
00006 #define __S_SHARED_MESH_BUFFER_H_INCLUDED__
00007
00008 #include "irrArray.h"
00009 #include "IMeshBuffer.h"
00010
00011 namespace irr
00012 {
00013 namespace scene
00014 {
00016 struct SSharedMeshBuffer : public IMeshBuffer
00017 {
00019 SSharedMeshBuffer() : IMeshBuffer(), Vertices(0), ChangedID_Vertex(1), ChangedID_Index(1), MappingHintVertex(EHM_NEVER), MappingHintIndex(EHM_NEVER)
00020 {
00021 #ifdef _DEBUG
00022 setDebugName("SSharedMeshBuffer");
00023 #endif
00024 }
00025
00027 SSharedMeshBuffer(core::array<video::S3DVertex> *vertices) : IMeshBuffer(), Vertices(vertices)
00028 {
00029 #ifdef _DEBUG
00030 setDebugName("SSharedMeshBuffer");
00031 #endif
00032 }
00033
00035 virtual const video::SMaterial& getMaterial() const
00036 {
00037 return Material;
00038 }
00039
00041 virtual video::SMaterial& getMaterial()
00042 {
00043 return Material;
00044 }
00045
00047 virtual const void* getVertices() const
00048 {
00049 if (Vertices)
00050 return Vertices->const_pointer();
00051 else
00052 return 0;
00053 }
00054
00056 virtual void* getVertices()
00057 {
00058 if (Vertices)
00059 return Vertices->pointer();
00060 else
00061 return 0;
00062 }
00063
00065 virtual u32 getVertexCount() const
00066 {
00067 if (Vertices)
00068 return Vertices->size();
00069 else
00070 return 0;
00071 }
00072
00074 virtual const u16* getIndices() const
00075 {
00076 return Indices.const_pointer();
00077 }
00078
00080 virtual u16* getIndices()
00081 {
00082 return Indices.pointer();
00083 }
00084
00086 virtual u32 getIndexCount() const
00087 {
00088 return Indices.size();
00089 }
00090
00092 virtual video::E_INDEX_TYPE getIndexType() const
00093 {
00094 return video::EIT_16BIT;
00095 }
00096
00098 virtual const core::aabbox3d<f32>& getBoundingBox() const
00099 {
00100 return BoundingBox;
00101 }
00102
00104 virtual void setBoundingBox( const core::aabbox3df& box)
00105 {
00106 BoundingBox = box;
00107 }
00108
00110 virtual video::E_VERTEX_TYPE getVertexType() const
00111 {
00112 return video::EVT_STANDARD;
00113 }
00114
00116 virtual void recalculateBoundingBox()
00117 {
00118 if (!Vertices || Vertices->empty() || Indices.empty())
00119 BoundingBox.reset(0,0,0);
00120 else
00121 {
00122 BoundingBox.reset((*Vertices)[Indices[0]].Pos);
00123 for (u32 i=1; i<Indices.size(); ++i)
00124 BoundingBox.addInternalPoint((*Vertices)[Indices[i]].Pos);
00125 }
00126 }
00127
00129 virtual const core::vector3df& getPosition(u32 i) const
00130 {
00131 _IRR_DEBUG_BREAK_IF(!Vertices);
00132 return (*Vertices)[Indices[i]].Pos;
00133 }
00134
00136 virtual core::vector3df& getPosition(u32 i)
00137 {
00138 _IRR_DEBUG_BREAK_IF(!Vertices);
00139 return (*Vertices)[Indices[i]].Pos;
00140 }
00141
00143 virtual const core::vector3df& getNormal(u32 i) const
00144 {
00145 _IRR_DEBUG_BREAK_IF(!Vertices);
00146 return (*Vertices)[Indices[i]].Normal;
00147 }
00148
00150 virtual core::vector3df& getNormal(u32 i)
00151 {
00152 _IRR_DEBUG_BREAK_IF(!Vertices);
00153 return (*Vertices)[Indices[i]].Normal;
00154 }
00155
00157 virtual const core::vector2df& getTCoords(u32 i) const
00158 {
00159 _IRR_DEBUG_BREAK_IF(!Vertices);
00160 return (*Vertices)[Indices[i]].TCoords;
00161 }
00162
00164 virtual core::vector2df& getTCoords(u32 i)
00165 {
00166 _IRR_DEBUG_BREAK_IF(!Vertices);
00167 return (*Vertices)[Indices[i]].TCoords;
00168 }
00169
00171 virtual void append(const void* const vertices, u32 numVertices, const u16* const indices, u32 numIndices) {}
00172
00174 virtual void append(const IMeshBuffer* const other) {}
00175
00177 virtual E_HARDWARE_MAPPING getHardwareMappingHint_Vertex() const
00178 {
00179 return MappingHintVertex;
00180 }
00181
00183 virtual E_HARDWARE_MAPPING getHardwareMappingHint_Index() const
00184 {
00185 return MappingHintIndex;
00186 }
00187
00189 virtual void setHardwareMappingHint( E_HARDWARE_MAPPING NewMappingHint, E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX )
00190 {
00191 if (buffer==EBT_VERTEX_AND_INDEX || buffer==EBT_VERTEX)
00192 MappingHintVertex=NewMappingHint;
00193 if (buffer==EBT_VERTEX_AND_INDEX || buffer==EBT_INDEX)
00194 MappingHintIndex=NewMappingHint;
00195 }
00196
00198 virtual void setDirty(E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX)
00199 {
00200 if (buffer==EBT_VERTEX_AND_INDEX || buffer==EBT_VERTEX)
00201 ++ChangedID_Vertex;
00202 if (buffer==EBT_VERTEX_AND_INDEX || buffer==EBT_INDEX)
00203 ++ChangedID_Index;
00204 }
00205
00207
00208 virtual u32 getChangedID_Vertex() const {return ChangedID_Vertex;}
00209
00211
00212 virtual u32 getChangedID_Index() const {return ChangedID_Index;}
00213
00215 video::SMaterial Material;
00216
00218 core::array<video::S3DVertex> *Vertices;
00219
00221 core::array<u16> Indices;
00222
00224 u32 ChangedID_Vertex;
00225
00227 u32 ChangedID_Index;
00228
00230 core::aabbox3df BoundingBox;
00231
00233 E_HARDWARE_MAPPING MappingHintVertex;
00234 E_HARDWARE_MAPPING MappingHintIndex;
00235 };
00236
00237
00238 }
00239 }
00240
00241 #endif
00242