IDynamicMeshBuffer.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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 IRR_I_DYNAMIC_MESH_BUFFER_H_INCLUDED
  5. #define IRR_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. // ------------------- Old interface ------------------- //
  22. // That stuff could also be in CDynamicMeshBuffer
  23. // I suppose it was put here to show that the information
  24. // is now basically handled by the vertex/index buffers instead
  25. // of the meshbuffer itself.
  26. //! get the current hardware mapping hint
  27. virtual E_HARDWARE_MAPPING getHardwareMappingHint_Vertex() const IRR_OVERRIDE
  28. {
  29. return getVertexBuffer().getHardwareMappingHint();
  30. }
  31. //! get the current hardware mapping hint
  32. virtual E_HARDWARE_MAPPING getHardwareMappingHint_Index() const IRR_OVERRIDE
  33. {
  34. return getIndexBuffer().getHardwareMappingHint();
  35. }
  36. //! set the hardware mapping hint, for driver
  37. virtual void setHardwareMappingHint( E_HARDWARE_MAPPING NewMappingHint, E_BUFFER_TYPE Buffer=EBT_VERTEX_AND_INDEX ) IRR_OVERRIDE
  38. {
  39. if (Buffer==EBT_VERTEX_AND_INDEX || Buffer==EBT_VERTEX)
  40. getVertexBuffer().setHardwareMappingHint(NewMappingHint);
  41. if (Buffer==EBT_VERTEX_AND_INDEX || Buffer==EBT_INDEX)
  42. getIndexBuffer().setHardwareMappingHint(NewMappingHint);
  43. }
  44. //! flags the mesh as changed, reloads hardware buffers
  45. virtual void setDirty(E_BUFFER_TYPE Buffer=EBT_VERTEX_AND_INDEX) IRR_OVERRIDE
  46. {
  47. if (Buffer==EBT_VERTEX_AND_INDEX || Buffer==EBT_VERTEX)
  48. getVertexBuffer().setDirty();
  49. if (Buffer==EBT_VERTEX_AND_INDEX || Buffer==EBT_INDEX)
  50. getIndexBuffer().setDirty();
  51. }
  52. virtual u32 getChangedID_Vertex() const IRR_OVERRIDE
  53. {
  54. return getVertexBuffer().getChangedID();
  55. }
  56. virtual u32 getChangedID_Index() const IRR_OVERRIDE
  57. {
  58. return getIndexBuffer().getChangedID();
  59. }
  60. //! Get type of vertex data which is stored in this meshbuffer.
  61. /** \return Vertex type of this buffer. */
  62. virtual video::E_VERTEX_TYPE getVertexType() const IRR_OVERRIDE
  63. {
  64. return getVertexBuffer().getType();
  65. }
  66. //! Get access to vertex data. The data is an array of vertices.
  67. /** Which vertex type is used can be determined by getVertexType().
  68. \return Pointer to array of vertices. */
  69. virtual const void* getVertices() const IRR_OVERRIDE
  70. {
  71. return getVertexBuffer().getData();
  72. }
  73. //! Get access to vertex data. The data is an array of vertices.
  74. /** Which vertex type is used can be determined by getVertexType().
  75. \return Pointer to array of vertices. */
  76. virtual void* getVertices() IRR_OVERRIDE
  77. {
  78. return getVertexBuffer().getData();
  79. }
  80. //! Get amount of vertices in meshbuffer.
  81. /** \return Number of vertices in this buffer. */
  82. virtual u32 getVertexCount() const IRR_OVERRIDE
  83. {
  84. return getVertexBuffer().size();
  85. }
  86. //! Get type of index data which is stored in this meshbuffer.
  87. /** \return Index type of this buffer. */
  88. virtual video::E_INDEX_TYPE getIndexType() const IRR_OVERRIDE
  89. {
  90. return getIndexBuffer().getType();
  91. }
  92. //! Get access to indices.
  93. /** \return Pointer to indices array. */
  94. virtual const u16* getIndices() const IRR_OVERRIDE
  95. {
  96. return (u16*)getIndexBuffer().getData();
  97. }
  98. //! Get access to indices.
  99. /** \return Pointer to indices array. */
  100. virtual u16* getIndices() IRR_OVERRIDE
  101. {
  102. return (u16*)getIndexBuffer().getData();
  103. }
  104. //! Get amount of indices in this meshbuffer.
  105. /** \return Number of indices in this buffer. */
  106. virtual u32 getIndexCount() const IRR_OVERRIDE
  107. {
  108. return getIndexBuffer().size();
  109. }
  110. //! returns position of vertex i
  111. virtual const core::vector3df& getPosition(u32 i) const IRR_OVERRIDE
  112. {
  113. return getVertexBuffer()[i].Pos;
  114. }
  115. //! returns position of vertex i
  116. virtual core::vector3df& getPosition(u32 i) IRR_OVERRIDE
  117. {
  118. return getVertexBuffer()[i].Pos;
  119. }
  120. //! returns texture coords of vertex i
  121. virtual const core::vector2df& getTCoords(u32 i) const IRR_OVERRIDE
  122. {
  123. return getVertexBuffer()[i].TCoords;
  124. }
  125. //! returns texture coords of vertex i
  126. virtual core::vector2df& getTCoords(u32 i) IRR_OVERRIDE
  127. {
  128. return getVertexBuffer()[i].TCoords;
  129. }
  130. //! returns normal of vertex i
  131. virtual const core::vector3df& getNormal(u32 i) const IRR_OVERRIDE
  132. {
  133. return getVertexBuffer()[i].Normal;
  134. }
  135. //! returns normal of vertex i
  136. virtual core::vector3df& getNormal(u32 i) IRR_OVERRIDE
  137. {
  138. return getVertexBuffer()[i].Normal;
  139. }
  140. //! returns color of vertex i
  141. virtual video::SColor& getColor(u32 i) IRR_OVERRIDE
  142. {
  143. return getVertexBuffer()[i].Color;
  144. }
  145. //! returns color of vertex i
  146. virtual const video::SColor& getColor(u32 i) const IRR_OVERRIDE
  147. {
  148. return getVertexBuffer()[i].Color;
  149. }
  150. };
  151. } // end namespace scene
  152. } // end namespace irr
  153. #endif