// Copyright (C) 2002-2012 Nikolaus Gebhardt // This file is part of the "Irrlicht Engine". // For conditions of distribution and use, see copyright notice in irrlicht.h #ifndef S_SHARED_MESH_BUFFER_H_INCLUDED #define S_SHARED_MESH_BUFFER_H_INCLUDED #include "irrArray.h" #include "IMeshBuffer.h" namespace irr { namespace scene { //! Implementation of the IMeshBuffer interface with shared vertex list struct SSharedMeshBuffer : public IMeshBuffer { //! constructor SSharedMeshBuffer() : IMeshBuffer() , Vertices(0), ChangedID_Vertex(1), ChangedID_Index(1) , MappingHintVertex(EHM_NEVER), MappingHintIndex(EHM_NEVER) , PrimitiveType(EPT_TRIANGLES) { #ifdef _DEBUG setDebugName("SSharedMeshBuffer"); #endif } //! constructor SSharedMeshBuffer(core::array *vertices) : IMeshBuffer(), Vertices(vertices), ChangedID_Vertex(1), ChangedID_Index(1), MappingHintVertex(EHM_NEVER), MappingHintIndex(EHM_NEVER) { #ifdef _DEBUG setDebugName("SSharedMeshBuffer"); #endif } //! returns the material of this meshbuffer virtual const video::SMaterial& getMaterial() const IRR_OVERRIDE { return Material; } //! returns the material of this meshbuffer virtual video::SMaterial& getMaterial() IRR_OVERRIDE { return Material; } //! returns pointer to vertices virtual const void* getVertices() const IRR_OVERRIDE { if (Vertices) return Vertices->const_pointer(); else return 0; } //! returns pointer to vertices virtual void* getVertices() IRR_OVERRIDE { if (Vertices) return Vertices->pointer(); else return 0; } //! returns amount of vertices virtual u32 getVertexCount() const IRR_OVERRIDE { if (Vertices) return Vertices->size(); else return 0; } //! returns pointer to indices virtual const u16* getIndices() const IRR_OVERRIDE { return Indices.const_pointer(); } //! returns pointer to indices virtual u16* getIndices() IRR_OVERRIDE { return Indices.pointer(); } //! returns amount of indices virtual u32 getIndexCount() const IRR_OVERRIDE { return Indices.size(); } //! Get type of index data which is stored in this meshbuffer. virtual video::E_INDEX_TYPE getIndexType() const IRR_OVERRIDE { return video::EIT_16BIT; } //! returns an axis aligned bounding box virtual const core::aabbox3d& getBoundingBox() const IRR_OVERRIDE { return BoundingBox; } //! set user axis aligned bounding box virtual void setBoundingBox( const core::aabbox3df& box) IRR_OVERRIDE { BoundingBox = box; } //! returns which type of vertex data is stored. virtual video::E_VERTEX_TYPE getVertexType() const IRR_OVERRIDE { return video::EVT_STANDARD; } //! recalculates the bounding box. should be called if the mesh changed. virtual void recalculateBoundingBox() IRR_OVERRIDE { if (!Vertices || Vertices->empty() || Indices.empty()) BoundingBox.reset(0,0,0); else { BoundingBox.reset((*Vertices)[Indices[0]].Pos); for (u32 i=1; iVertices = Vertices; clone->BoundingBox = BoundingBox; } if (cloneFlags & ECF_INDICES) { clone->Indices = Indices; } clone->Material = Material; clone->MappingHintVertex = MappingHintVertex; clone->MappingHintIndex = MappingHintIndex; clone->PrimitiveType = PrimitiveType; return clone; } //! Material of this meshBuffer video::SMaterial Material; //! Shared Array of vertices core::array *Vertices; //! Array of indices core::array Indices; //! ID used for hardware buffer management u32 ChangedID_Vertex; //! ID used for hardware buffer management u32 ChangedID_Index; //! Bounding box core::aabbox3df BoundingBox; //! hardware mapping hint E_HARDWARE_MAPPING MappingHintVertex; E_HARDWARE_MAPPING MappingHintIndex; //! Primitive type used for rendering (triangles, lines, ...) E_PRIMITIVE_TYPE PrimitiveType; }; } // end namespace scene } // end namespace irr #endif