IDynamicMeshBuffer.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. // Copyright (C) 2008-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 __I_DYNAMIC_MESH_BUFFER_H_INCLUDED__
  5. #define __I_DYNAMIC_MESH_BUFFER_H_INCLUDED__
  6. #include "IMeshBuffer.h"
  7. #include "IVertexBuffer.h"
  8. #include "IIndexBuffer.h"
  9. namespace irr
  10. {
  11. namespace scene
  12. {
  13. /** a dynamic meshBuffer */
  14. class IDynamicMeshBuffer : public IMeshBuffer
  15. {
  16. public:
  17. virtual IVertexBuffer &getVertexBuffer() const =0;
  18. virtual IIndexBuffer &getIndexBuffer() const =0;
  19. virtual void setVertexBuffer(IVertexBuffer *vertexBuffer) =0;
  20. virtual void setIndexBuffer(IIndexBuffer *indexBuffer) =0;
  21. //! Get the material of this meshbuffer
  22. /** \return Material of this buffer. */
  23. virtual video::SMaterial& getMaterial() _IRR_OVERRIDE_ =0;
  24. //! Get the material of this meshbuffer
  25. /** \return Material of this buffer. */
  26. virtual const video::SMaterial& getMaterial() const _IRR_OVERRIDE_ =0;
  27. //! Get the axis aligned bounding box of this meshbuffer.
  28. /** \return Axis aligned bounding box of this buffer. */
  29. virtual const core::aabbox3df& getBoundingBox() const _IRR_OVERRIDE_ =0;
  30. //! Set axis aligned bounding box
  31. /** \param box User defined axis aligned bounding box to use
  32. for this buffer. */
  33. virtual void setBoundingBox(const core::aabbox3df& box) _IRR_OVERRIDE_ =0;
  34. //! Recalculates the bounding box. Should be called if the mesh changed.
  35. virtual void recalculateBoundingBox() _IRR_OVERRIDE_ =0;
  36. //! Append the vertices and indices to the current buffer
  37. /** Only works for compatible vertex types.
  38. \param vertices Pointer to a vertex array.
  39. \param numVertices Number of vertices in the array.
  40. \param indices Pointer to index array.
  41. \param numIndices Number of indices in array. */
  42. virtual void append(const void* const vertices, u32 numVertices, const u16* const indices, u32 numIndices) _IRR_OVERRIDE_
  43. {
  44. }
  45. //! Append the meshbuffer to the current buffer
  46. /** Only works for compatible vertex types
  47. \param other Buffer to append to this one. */
  48. virtual void append(const IMeshBuffer* const other) _IRR_OVERRIDE_
  49. {
  50. }
  51. // ------------------- To be removed? ------------------- //
  52. //! get the current hardware mapping hint
  53. virtual E_HARDWARE_MAPPING getHardwareMappingHint_Vertex() const _IRR_OVERRIDE_
  54. {
  55. return getVertexBuffer().getHardwareMappingHint();
  56. }
  57. //! get the current hardware mapping hint
  58. virtual E_HARDWARE_MAPPING getHardwareMappingHint_Index() const _IRR_OVERRIDE_
  59. {
  60. return getIndexBuffer().getHardwareMappingHint();
  61. }
  62. //! set the hardware mapping hint, for driver
  63. virtual void setHardwareMappingHint( E_HARDWARE_MAPPING NewMappingHint, E_BUFFER_TYPE Buffer=EBT_VERTEX_AND_INDEX ) _IRR_OVERRIDE_
  64. {
  65. if (Buffer==EBT_VERTEX_AND_INDEX || Buffer==EBT_VERTEX)
  66. getVertexBuffer().setHardwareMappingHint(NewMappingHint);
  67. if (Buffer==EBT_VERTEX_AND_INDEX || Buffer==EBT_INDEX)
  68. getIndexBuffer().setHardwareMappingHint(NewMappingHint);
  69. }
  70. //! flags the mesh as changed, reloads hardware buffers
  71. virtual void setDirty(E_BUFFER_TYPE Buffer=EBT_VERTEX_AND_INDEX) _IRR_OVERRIDE_
  72. {
  73. if (Buffer==EBT_VERTEX_AND_INDEX || Buffer==EBT_VERTEX)
  74. getVertexBuffer().setDirty();
  75. if (Buffer==EBT_VERTEX_AND_INDEX || Buffer==EBT_INDEX)
  76. getIndexBuffer().setDirty();
  77. }
  78. virtual u32 getChangedID_Vertex() const _IRR_OVERRIDE_
  79. {
  80. return getVertexBuffer().getChangedID();
  81. }
  82. virtual u32 getChangedID_Index() const _IRR_OVERRIDE_
  83. {
  84. return getIndexBuffer().getChangedID();
  85. }
  86. // ------------------- Old interface ------------------- //
  87. //! Get type of vertex data which is stored in this meshbuffer.
  88. /** \return Vertex type of this buffer. */
  89. virtual video::E_VERTEX_TYPE getVertexType() const _IRR_OVERRIDE_
  90. {
  91. return getVertexBuffer().getType();
  92. }
  93. //! Get access to vertex data. The data is an array of vertices.
  94. /** Which vertex type is used can be determined by getVertexType().
  95. \return Pointer to array of vertices. */
  96. virtual const void* getVertices() const _IRR_OVERRIDE_
  97. {
  98. return getVertexBuffer().getData();
  99. }
  100. //! Get access to vertex data. The data is an array of vertices.
  101. /** Which vertex type is used can be determined by getVertexType().
  102. \return Pointer to array of vertices. */
  103. virtual void* getVertices() _IRR_OVERRIDE_
  104. {
  105. return getVertexBuffer().getData();
  106. }
  107. //! Get amount of vertices in meshbuffer.
  108. /** \return Number of vertices in this buffer. */
  109. virtual u32 getVertexCount() const _IRR_OVERRIDE_
  110. {
  111. return getVertexBuffer().size();
  112. }
  113. //! Get type of index data which is stored in this meshbuffer.
  114. /** \return Index type of this buffer. */
  115. virtual video::E_INDEX_TYPE getIndexType() const _IRR_OVERRIDE_
  116. {
  117. return getIndexBuffer().getType();
  118. }
  119. //! Get access to indices.
  120. /** \return Pointer to indices array. */
  121. virtual const u16* getIndices() const _IRR_OVERRIDE_
  122. {
  123. return (u16*)getIndexBuffer().getData();
  124. }
  125. //! Get access to indices.
  126. /** \return Pointer to indices array. */
  127. virtual u16* getIndices() _IRR_OVERRIDE_
  128. {
  129. return (u16*)getIndexBuffer().getData();
  130. }
  131. //! Get amount of indices in this meshbuffer.
  132. /** \return Number of indices in this buffer. */
  133. virtual u32 getIndexCount() const _IRR_OVERRIDE_
  134. {
  135. return getIndexBuffer().size();
  136. }
  137. //! returns position of vertex i
  138. virtual const core::vector3df& getPosition(u32 i) const _IRR_OVERRIDE_
  139. {
  140. return getVertexBuffer()[i].Pos;
  141. }
  142. //! returns position of vertex i
  143. virtual core::vector3df& getPosition(u32 i) _IRR_OVERRIDE_
  144. {
  145. return getVertexBuffer()[i].Pos;
  146. }
  147. //! returns texture coords of vertex i
  148. virtual const core::vector2df& getTCoords(u32 i) const _IRR_OVERRIDE_
  149. {
  150. return getVertexBuffer()[i].TCoords;
  151. }
  152. //! returns texture coords of vertex i
  153. virtual core::vector2df& getTCoords(u32 i) _IRR_OVERRIDE_
  154. {
  155. return getVertexBuffer()[i].TCoords;
  156. }
  157. //! returns normal of vertex i
  158. virtual const core::vector3df& getNormal(u32 i) const _IRR_OVERRIDE_
  159. {
  160. return getVertexBuffer()[i].Normal;
  161. }
  162. //! returns normal of vertex i
  163. virtual core::vector3df& getNormal(u32 i) _IRR_OVERRIDE_
  164. {
  165. return getVertexBuffer()[i].Normal;
  166. }
  167. };
  168. } // end namespace scene
  169. } // end namespace irr
  170. #endif