123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312 |
- // 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<video::S3DVertex> *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<f32>& 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; i<Indices.size(); ++i)
- BoundingBox.addInternalPoint((*Vertices)[Indices[i]].Pos);
- }
- }
- //! returns position of vertex i
- virtual const core::vector3df& getPosition(u32 i) const IRR_OVERRIDE
- {
- IRR_DEBUG_BREAK_IF(!Vertices);
- return (*Vertices)[Indices[i]].Pos;
- }
- //! returns position of vertex i
- virtual core::vector3df& getPosition(u32 i) IRR_OVERRIDE
- {
- IRR_DEBUG_BREAK_IF(!Vertices);
- return (*Vertices)[Indices[i]].Pos;
- }
- //! returns normal of vertex i
- virtual const core::vector3df& getNormal(u32 i) const IRR_OVERRIDE
- {
- IRR_DEBUG_BREAK_IF(!Vertices);
- return (*Vertices)[Indices[i]].Normal;
- }
- //! returns normal of vertex i
- virtual core::vector3df& getNormal(u32 i) IRR_OVERRIDE
- {
- IRR_DEBUG_BREAK_IF(!Vertices);
- return (*Vertices)[Indices[i]].Normal;
- }
- //! returns texture coord of vertex i
- virtual const core::vector2df& getTCoords(u32 i) const IRR_OVERRIDE
- {
- IRR_DEBUG_BREAK_IF(!Vertices);
- return (*Vertices)[Indices[i]].TCoords;
- }
- //! returns texture coord of vertex i
- virtual core::vector2df& getTCoords(u32 i) IRR_OVERRIDE
- {
- IRR_DEBUG_BREAK_IF(!Vertices);
- return (*Vertices)[Indices[i]].TCoords;
- }
- //! returns color of vertex i
- virtual video::SColor& getColor(u32 i) IRR_OVERRIDE
- {
- IRR_DEBUG_BREAK_IF(!Vertices);
- return (*Vertices)[Indices[i]].Color;
- }
- //! returns color of vertex i
- virtual const video::SColor& getColor(u32 i) const IRR_OVERRIDE
- {
- IRR_DEBUG_BREAK_IF(!Vertices);
- return (*Vertices)[Indices[i]].Color;
- }
- //! append the vertices and indices to the current buffer
- virtual void append(const void* const vertices, u32 numVertices, const u16* const indices, u32 numIndices, bool updateBoundingBox) IRR_OVERRIDE
- {
- // can't do that as it doesn't own the vertex memory
- }
- //! append the meshbuffer to the current buffer
- virtual void append(const IMeshBuffer* const other, bool updateBoundingBox) IRR_OVERRIDE
- {
- // can't do that as it doesn't own the vertex memory
- }
- //! get the current hardware mapping hint
- virtual E_HARDWARE_MAPPING getHardwareMappingHint_Vertex() const IRR_OVERRIDE
- {
- return MappingHintVertex;
- }
- //! get the current hardware mapping hint
- virtual E_HARDWARE_MAPPING getHardwareMappingHint_Index() const IRR_OVERRIDE
- {
- return MappingHintIndex;
- }
- //! set the hardware mapping hint, for driver
- virtual void setHardwareMappingHint( E_HARDWARE_MAPPING NewMappingHint, E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX ) IRR_OVERRIDE
- {
- if (buffer==EBT_VERTEX_AND_INDEX || buffer==EBT_VERTEX)
- MappingHintVertex=NewMappingHint;
- if (buffer==EBT_VERTEX_AND_INDEX || buffer==EBT_INDEX)
- MappingHintIndex=NewMappingHint;
- }
- //! Describe what kind of primitive geometry is used by the meshbuffer
- virtual void setPrimitiveType(E_PRIMITIVE_TYPE type) IRR_OVERRIDE
- {
- PrimitiveType = type;
- }
- //! Get the kind of primitive geometry which is used by the meshbuffer
- virtual E_PRIMITIVE_TYPE getPrimitiveType() const IRR_OVERRIDE
- {
- return PrimitiveType;
- }
- //! flags the mesh as changed, reloads hardware buffers
- virtual void setDirty(E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX) IRR_OVERRIDE
- {
- if (buffer==EBT_VERTEX_AND_INDEX || buffer==EBT_VERTEX)
- ++ChangedID_Vertex;
- if (buffer==EBT_VERTEX_AND_INDEX || buffer==EBT_INDEX)
- ++ChangedID_Index;
- }
- //! Get the currently used ID for identification of changes.
- /** This shouldn't be used for anything outside the VideoDriver. */
- virtual u32 getChangedID_Vertex() const IRR_OVERRIDE {return ChangedID_Vertex;}
- //! Get the currently used ID for identification of changes.
- /** This shouldn't be used for anything outside the VideoDriver. */
- virtual u32 getChangedID_Index() const IRR_OVERRIDE {return ChangedID_Index;}
- //! Returns type of the class implementing the IMeshBuffer
- virtual EMESH_BUFFER_TYPE getType() const IRR_OVERRIDE
- {
- return EMBT_SHARED;
- }
- //! Create copy of the meshbuffer
- virtual IMeshBuffer* createClone(int cloneFlags) const IRR_OVERRIDE
- {
- SSharedMeshBuffer * clone = new SSharedMeshBuffer();
- if (cloneFlags & ECF_VERTICES)
- {
- clone->Vertices = 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<video::S3DVertex> *Vertices;
- //! Array of indices
- core::array<u16> 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
|