LCOV - code coverage report
Current view: top level - usr/include/irrlicht - SMesh.h (source / functions) Hit Total Coverage
Test: report Lines: 22 45 48.9 %
Date: 2015-07-11 18:23:49 Functions: 8 13 61.5 %

          Line data    Source code
       1             : // Copyright (C) 2002-2012 Nikolaus Gebhardt
       2             : // This file is part of the "Irrlicht Engine".
       3             : // For conditions of distribution and use, see copyright notice in irrlicht.h
       4             : 
       5             : #ifndef __S_MESH_H_INCLUDED__
       6             : #define __S_MESH_H_INCLUDED__
       7             : 
       8             : #include "IMesh.h"
       9             : #include "IMeshBuffer.h"
      10             : #include "aabbox3d.h"
      11             : #include "irrArray.h"
      12             : 
      13             : namespace irr
      14             : {
      15             : namespace scene
      16             : {
      17             :         //! Simple implementation of the IMesh interface.
      18             :         struct SMesh : public IMesh
      19             :         {
      20             :                 //! constructor
      21      105932 :                 SMesh()
      22      105932 :                 {
      23             :                         #ifdef _DEBUG
      24             :                         setDebugName("SMesh");
      25             :                         #endif
      26      105932 :                 }
      27             : 
      28             :                 //! destructor
      29      214721 :                 virtual ~SMesh()
      30      214722 :                 {
      31             :                         // drop buffers
      32      621346 :                         for (u32 i=0; i<MeshBuffers.size(); ++i)
      33      513985 :                                 MeshBuffers[i]->drop();
      34      214721 :                 }
      35             : 
      36             :                 //! clean mesh
      37           0 :                 virtual void clear()
      38             :                 {
      39           0 :                         for (u32 i=0; i<MeshBuffers.size(); ++i)
      40           0 :                                 MeshBuffers[i]->drop();
      41           0 :                         MeshBuffers.clear();
      42           0 :                         BoundingBox.reset ( 0.f, 0.f, 0.f );
      43           0 :                 }
      44             : 
      45             : 
      46             :                 //! returns amount of mesh buffers.
      47     1790868 :                 virtual u32 getMeshBufferCount() const
      48             :                 {
      49     1790868 :                         return MeshBuffers.size();
      50             :                 }
      51             : 
      52             :                 //! returns pointer to a mesh buffer
      53     5083594 :                 virtual IMeshBuffer* getMeshBuffer(u32 nr) const
      54             :                 {
      55     5083594 :                         return MeshBuffers[nr];
      56             :                 }
      57             : 
      58             :                 //! returns a meshbuffer which fits a material
      59             :                 /** reverse search */
      60           0 :                 virtual IMeshBuffer* getMeshBuffer( const video::SMaterial & material) const
      61             :                 {
      62           0 :                         for (s32 i = (s32)MeshBuffers.size()-1; i >= 0; --i)
      63             :                         {
      64           0 :                                 if ( material == MeshBuffers[i]->getMaterial())
      65           0 :                                         return MeshBuffers[i];
      66             :                         }
      67             : 
      68           0 :                         return 0;
      69             :                 }
      70             : 
      71             :                 //! returns an axis aligned bounding box
      72       59776 :                 virtual const core::aabbox3d<f32>& getBoundingBox() const
      73             :                 {
      74       59776 :                         return BoundingBox;
      75             :                 }
      76             : 
      77             :                 //! set user axis aligned bounding box
      78      109100 :                 virtual void setBoundingBox( const core::aabbox3df& box)
      79             :                 {
      80      109100 :                         BoundingBox = box;
      81      109100 :                 }
      82             : 
      83             :                 //! recalculates the bounding box
      84             :                 void recalculateBoundingBox()
      85             :                 {
      86             :                         if (MeshBuffers.size())
      87             :                         {
      88             :                                 BoundingBox = MeshBuffers[0]->getBoundingBox();
      89             :                                 for (u32 i=1; i<MeshBuffers.size(); ++i)
      90             :                                         BoundingBox.addInternalBox(MeshBuffers[i]->getBoundingBox());
      91             :                         }
      92             :                         else
      93             :                                 BoundingBox.reset(0.0f, 0.0f, 0.0f);
      94             :                 }
      95             : 
      96             :                 //! adds a MeshBuffer
      97             :                 /** The bounding box is not updated automatically. */
      98      511926 :                 void addMeshBuffer(IMeshBuffer* buf)
      99             :                 {
     100      511926 :                         if (buf)
     101             :                         {
     102      511926 :                                 buf->grab();
     103      511926 :                                 MeshBuffers.push_back(buf);
     104             :                         }
     105      511926 :                 }
     106             : 
     107             :                 //! sets a flag of all contained materials to a new value
     108           0 :                 virtual void setMaterialFlag(video::E_MATERIAL_FLAG flag, bool newvalue)
     109             :                 {
     110           0 :                         for (u32 i=0; i<MeshBuffers.size(); ++i)
     111           0 :                                 MeshBuffers[i]->getMaterial().setFlag(flag, newvalue);
     112           0 :                 }
     113             : 
     114             :                 //! set the hardware mapping hint, for driver
     115           0 :                 virtual void setHardwareMappingHint( E_HARDWARE_MAPPING newMappingHint, E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX )
     116             :                 {
     117           0 :                         for (u32 i=0; i<MeshBuffers.size(); ++i)
     118           0 :                                 MeshBuffers[i]->setHardwareMappingHint(newMappingHint, buffer);
     119           0 :                 }
     120             : 
     121             :                 //! flags the meshbuffer as changed, reloads hardware buffers
     122           0 :                 virtual void setDirty(E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX)
     123             :                 {
     124           0 :                         for (u32 i=0; i<MeshBuffers.size(); ++i)
     125           0 :                                 MeshBuffers[i]->setDirty(buffer);
     126           0 :                 }
     127             : 
     128             :                 //! The meshbuffers of this mesh
     129             :                 core::array<IMeshBuffer*> MeshBuffers;
     130             : 
     131             :                 //! The bounding box of this mesh
     132             :                 core::aabbox3d<f32> BoundingBox;
     133             :         };
     134             : 
     135             : 
     136             : } // end namespace scene
     137             : } // end namespace irr
     138             : 
     139             : #endif
     140             : 

Generated by: LCOV version 1.11