SSharedMeshBuffer.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. #ifndef __S_SHARED_MESH_BUFFER_H_INCLUDED__
  5. #define __S_SHARED_MESH_BUFFER_H_INCLUDED__
  6. #include "irrArray.h"
  7. #include "IMeshBuffer.h"
  8. namespace irr
  9. {
  10. namespace scene
  11. {
  12. //! Implementation of the IMeshBuffer interface with shared vertex list
  13. struct SSharedMeshBuffer : public IMeshBuffer
  14. {
  15. //! constructor
  16. SSharedMeshBuffer() : IMeshBuffer(), Vertices(0), ChangedID_Vertex(1), ChangedID_Index(1), MappingHintVertex(EHM_NEVER), MappingHintIndex(EHM_NEVER)
  17. {
  18. #ifdef _DEBUG
  19. setDebugName("SSharedMeshBuffer");
  20. #endif
  21. }
  22. //! constructor
  23. SSharedMeshBuffer(core::array<video::S3DVertex> *vertices) : IMeshBuffer(), Vertices(vertices)
  24. {
  25. #ifdef _DEBUG
  26. setDebugName("SSharedMeshBuffer");
  27. #endif
  28. }
  29. //! returns the material of this meshbuffer
  30. virtual const video::SMaterial& getMaterial() const
  31. {
  32. return Material;
  33. }
  34. //! returns the material of this meshbuffer
  35. virtual video::SMaterial& getMaterial()
  36. {
  37. return Material;
  38. }
  39. //! returns pointer to vertices
  40. virtual const void* getVertices() const
  41. {
  42. if (Vertices)
  43. return Vertices->const_pointer();
  44. else
  45. return 0;
  46. }
  47. //! returns pointer to vertices
  48. virtual void* getVertices()
  49. {
  50. if (Vertices)
  51. return Vertices->pointer();
  52. else
  53. return 0;
  54. }
  55. //! returns amount of vertices
  56. virtual u32 getVertexCount() const
  57. {
  58. if (Vertices)
  59. return Vertices->size();
  60. else
  61. return 0;
  62. }
  63. //! returns pointer to Indices
  64. virtual const u16* getIndices() const
  65. {
  66. return Indices.const_pointer();
  67. }
  68. //! returns pointer to Indices
  69. virtual u16* getIndices()
  70. {
  71. return Indices.pointer();
  72. }
  73. //! returns amount of indices
  74. virtual u32 getIndexCount() const
  75. {
  76. return Indices.size();
  77. }
  78. //! Get type of index data which is stored in this meshbuffer.
  79. virtual video::E_INDEX_TYPE getIndexType() const
  80. {
  81. return video::EIT_16BIT;
  82. }
  83. //! returns an axis aligned bounding box
  84. virtual const core::aabbox3d<f32>& getBoundingBox() const
  85. {
  86. return BoundingBox;
  87. }
  88. //! set user axis aligned bounding box
  89. virtual void setBoundingBox( const core::aabbox3df& box)
  90. {
  91. BoundingBox = box;
  92. }
  93. //! returns which type of vertex data is stored.
  94. virtual video::E_VERTEX_TYPE getVertexType() const
  95. {
  96. return video::EVT_STANDARD;
  97. }
  98. //! recalculates the bounding box. should be called if the mesh changed.
  99. virtual void recalculateBoundingBox()
  100. {
  101. if (!Vertices || Vertices->empty() || Indices.empty())
  102. BoundingBox.reset(0,0,0);
  103. else
  104. {
  105. BoundingBox.reset((*Vertices)[Indices[0]].Pos);
  106. for (u32 i=1; i<Indices.size(); ++i)
  107. BoundingBox.addInternalPoint((*Vertices)[Indices[i]].Pos);
  108. }
  109. }
  110. //! returns position of vertex i
  111. virtual const core::vector3df& getPosition(u32 i) const
  112. {
  113. _IRR_DEBUG_BREAK_IF(!Vertices);
  114. return (*Vertices)[Indices[i]].Pos;
  115. }
  116. //! returns position of vertex i
  117. virtual core::vector3df& getPosition(u32 i)
  118. {
  119. _IRR_DEBUG_BREAK_IF(!Vertices);
  120. return (*Vertices)[Indices[i]].Pos;
  121. }
  122. //! returns normal of vertex i
  123. virtual const core::vector3df& getNormal(u32 i) const
  124. {
  125. _IRR_DEBUG_BREAK_IF(!Vertices);
  126. return (*Vertices)[Indices[i]].Normal;
  127. }
  128. //! returns normal of vertex i
  129. virtual core::vector3df& getNormal(u32 i)
  130. {
  131. _IRR_DEBUG_BREAK_IF(!Vertices);
  132. return (*Vertices)[Indices[i]].Normal;
  133. }
  134. //! returns texture coord of vertex i
  135. virtual const core::vector2df& getTCoords(u32 i) const
  136. {
  137. _IRR_DEBUG_BREAK_IF(!Vertices);
  138. return (*Vertices)[Indices[i]].TCoords;
  139. }
  140. //! returns texture coord of vertex i
  141. virtual core::vector2df& getTCoords(u32 i)
  142. {
  143. _IRR_DEBUG_BREAK_IF(!Vertices);
  144. return (*Vertices)[Indices[i]].TCoords;
  145. }
  146. //! append the vertices and indices to the current buffer
  147. virtual void append(const void* const vertices, u32 numVertices, const u16* const indices, u32 numIndices) {}
  148. //! append the meshbuffer to the current buffer
  149. virtual void append(const IMeshBuffer* const other) {}
  150. //! get the current hardware mapping hint
  151. virtual E_HARDWARE_MAPPING getHardwareMappingHint_Vertex() const
  152. {
  153. return MappingHintVertex;
  154. }
  155. //! get the current hardware mapping hint
  156. virtual E_HARDWARE_MAPPING getHardwareMappingHint_Index() const
  157. {
  158. return MappingHintIndex;
  159. }
  160. //! set the hardware mapping hint, for driver
  161. virtual void setHardwareMappingHint( E_HARDWARE_MAPPING NewMappingHint, E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX )
  162. {
  163. if (buffer==EBT_VERTEX_AND_INDEX || buffer==EBT_VERTEX)
  164. MappingHintVertex=NewMappingHint;
  165. if (buffer==EBT_VERTEX_AND_INDEX || buffer==EBT_INDEX)
  166. MappingHintIndex=NewMappingHint;
  167. }
  168. //! flags the mesh as changed, reloads hardware buffers
  169. virtual void setDirty(E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX)
  170. {
  171. if (buffer==EBT_VERTEX_AND_INDEX || buffer==EBT_VERTEX)
  172. ++ChangedID_Vertex;
  173. if (buffer==EBT_VERTEX_AND_INDEX || buffer==EBT_INDEX)
  174. ++ChangedID_Index;
  175. }
  176. //! Get the currently used ID for identification of changes.
  177. /** This shouldn't be used for anything outside the VideoDriver. */
  178. virtual u32 getChangedID_Vertex() const {return ChangedID_Vertex;}
  179. //! Get the currently used ID for identification of changes.
  180. /** This shouldn't be used for anything outside the VideoDriver. */
  181. virtual u32 getChangedID_Index() const {return ChangedID_Index;}
  182. //! Material of this meshBuffer
  183. video::SMaterial Material;
  184. //! Shared Array of vertices
  185. core::array<video::S3DVertex> *Vertices;
  186. //! Array of Indices
  187. core::array<u16> Indices;
  188. //! ID used for hardware buffer management
  189. u32 ChangedID_Vertex;
  190. //! ID used for hardware buffer management
  191. u32 ChangedID_Index;
  192. //! Bounding box
  193. core::aabbox3df BoundingBox;
  194. //! hardware mapping hint
  195. E_HARDWARE_MAPPING MappingHintVertex;
  196. E_HARDWARE_MAPPING MappingHintIndex;
  197. };
  198. } // end namespace scene
  199. } // end namespace irr
  200. #endif