// Copyright (C) 2002-2007 Nikolaus Gebhardt // This file is part of the "Irrlicht Engine". // For conditions of distribution and use, see copyright notice in irrlicht.h #ifndef __T_MESH_BUFFER_H_INCLUDED__ #define __T_MESH_BUFFER_H_INCLUDED__ #include "irrArray.h" #include "IMeshBuffer.h" namespace irr { namespace scene { //! Template implementation of the IMeshBuffer interface template class CMeshBuffer : public IMeshBuffer { public: //! constructor CMeshBuffer():ChangedID(1),MappingHint(EHM_NEVER) // everything's default constructed { #ifdef _DEBUG setDebugName("SMeshBuffer"); #endif } //! returns the material of this meshbuffer virtual const video::SMaterial& getMaterial() const { return Material; } //! returns the material of this meshbuffer virtual video::SMaterial& getMaterial() { return Material; } //! returns pointer to vertices virtual const void* getVertices() const { return Vertices.const_pointer(); } //! returns pointer to vertices virtual void* getVertices() { return Vertices.pointer(); } //! returns amount of vertices virtual u32 getVertexCount() const { return Vertices.size(); } //! returns pointer to Indices virtual const u16* getIndices() const { return Indices.const_pointer(); } //! returns pointer to Indices virtual u16* getIndices() { return Indices.pointer(); } //! returns amount of indices virtual u32 getIndexCount() const { return Indices.size(); } //! returns an axis aligned bounding box virtual const core::aabbox3d& getBoundingBox() const { return BoundingBox; } //! set user axis aligned bounding box virtual void setBoundingBox(const core::aabbox3df& box) { BoundingBox = box; } //! recalculates the bounding box. should be called if the mesh changed. virtual void recalculateBoundingBox() { if (Vertices.empty()) BoundingBox.reset(0,0,0); else { BoundingBox.reset(Vertices[0].Pos); for (u32 i=1; i(vertices)[i]); BoundingBox.addInternalPoint(reinterpret_cast(vertices)[i].Pos); } Indices.reallocate(getIndexCount()+numIndices); for (i=0; igetVertexCount()); for (i=0; igetVertexCount(); ++i) { Vertices.push_back(reinterpret_cast(other->getVertices())[i]); } Indices.reallocate(getIndexCount()+other->getIndexCount()); for (i=0; igetIndexCount(); ++i) { Indices.push_back(other->getIndices()[i]+vertexCount); } BoundingBox.addInternalBox(other->getBoundingBox()); } //! get the current hardware mapping hint virtual const E_HARDWARE_MAPPING getHardwareMappingHint() const { return MappingHint; } //! set the hardware mapping hint, for driver virtual void setHardwareMappingHint( E_HARDWARE_MAPPING NewMappingHint ) { MappingHint=NewMappingHint; } //! flags the mesh as changed, reloads hardware buffers virtual void setDirty(E_BUFFER_TYPE Buffer=EBT_VERTEX_AND_INDEX) {ChangedID++;} virtual const u32 getChangedID() const {return ChangedID;} u32 ChangedID; //! hardware mapping hint E_HARDWARE_MAPPING MappingHint; //! Material for this meshbuffer. video::SMaterial Material; //! Vertices of this buffer core::array Vertices; //! Indices into the vertices of this buffer. core::array Indices; //! Bounding box of this meshbuffer. core::aabbox3d BoundingBox; }; typedef CMeshBuffer SMeshBuffer; typedef CMeshBuffer SMeshBufferLightMap; typedef CMeshBuffer SMeshBufferTangents; } // end namespace scene } // end namespace irr #endif