// 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 __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: //! Default constructor for empty meshbuffer CMeshBuffer() : ChangedID_Vertex(1), ChangedID_Index(1) , MappingHint_Vertex(EHM_NEVER), MappingHint_Index(EHM_NEVER) , HWBuffer(NULL) , PrimitiveType(EPT_TRIANGLES) { #ifdef _DEBUG setDebugName("CMeshBuffer"); #endif } //! Get material of this meshbuffer /** \return Material of this buffer */ const video::SMaterial& getMaterial() const override { return Material; } //! Get material of this meshbuffer /** \return Material of this buffer */ video::SMaterial& getMaterial() override { return Material; } //! Get pointer to vertices /** \return Pointer to vertices. */ const void* getVertices() const override { return Vertices.const_pointer(); } //! Get pointer to vertices /** \return Pointer to vertices. */ void* getVertices() override { return Vertices.pointer(); } //! Get number of vertices /** \return Number of vertices. */ u32 getVertexCount() const override { return Vertices.size(); } //! Get type of index data which is stored in this meshbuffer. /** \return Index type of this buffer. */ video::E_INDEX_TYPE getIndexType() const override { return video::EIT_16BIT; } //! Get pointer to indices /** \return Pointer to indices. */ const u16* getIndices() const override { return Indices.const_pointer(); } //! Get pointer to indices /** \return Pointer to indices. */ u16* getIndices() override { return Indices.pointer(); } //! Get number of indices /** \return Number of indices. */ u32 getIndexCount() const override { return Indices.size(); } //! Get the axis aligned bounding box /** \return Axis aligned bounding box of this buffer. */ const core::aabbox3d& getBoundingBox() const override { return BoundingBox; } //! Set the axis aligned bounding box /** \param box New axis aligned bounding box for this buffer. */ //! set user axis aligned bounding box void setBoundingBox(const core::aabbox3df& box) override { BoundingBox = box; } //! Recalculate the bounding box. /** should be called if the mesh changed. */ void recalculateBoundingBox() override { if (!Vertices.empty()) { BoundingBox.reset(Vertices[0].Pos); const irr::u32 vsize = Vertices.size(); for (u32 i=1; i(vertices)[i]); BoundingBox.addInternalPoint(static_cast(vertices)[i].Pos); } Indices.reallocate(getIndexCount()+numIndices); for (i=0; i Vertices; //! Indices into the vertices of this buffer. core::array Indices; //! Bounding box of this meshbuffer. core::aabbox3d BoundingBox; //! Primitive type used for rendering (triangles, lines, ...) E_PRIMITIVE_TYPE PrimitiveType; }; //! Standard meshbuffer typedef CMeshBuffer SMeshBuffer; //! Meshbuffer with two texture coords per vertex, e.g. for lightmaps typedef CMeshBuffer SMeshBufferLightMap; //! Meshbuffer with vertices having tangents stored, e.g. for normal mapping typedef CMeshBuffer SMeshBufferTangents; } // end namespace scene } // end namespace irr #endif