BsMeshBase.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. #include "BsGpuResource.h"
  4. #include "BsDrawOps.h"
  5. #include "BsSubMesh.h"
  6. namespace BansheeEngine
  7. {
  8. /**
  9. * @brief Type of buffers used by a mesh. These options usually affect performance and
  10. * you should specify static if you don't plan on modifying the mesh often,
  11. * otherwise specify dynamic.
  12. */
  13. enum class MeshBufferType
  14. {
  15. Static,
  16. Dynamic
  17. };
  18. /**
  19. * @brief Base class all mesh implementations derive from. Meshes hold geometry information,
  20. * normally in the form of one or serveral index or vertex buffers. Different mesh implementations
  21. * might choose to manage those buffers differently.
  22. *
  23. * @note Core thread only unless noted otherwise.
  24. */
  25. class BS_CORE_EXPORT MeshBase : public GpuResource
  26. {
  27. public:
  28. /**
  29. * @brief Constructs a new mesh with no sub-meshes.
  30. *
  31. * @param numVertices Number of vertices in the mesh.
  32. * @param numIndices Number of indices in the mesh.
  33. * @param drawOp Determines how should the provided indices be interpreted by the pipeline. Default option is triangles,
  34. * where three indices represent a single triangle.
  35. */
  36. MeshBase(UINT32 numVertices, UINT32 numIndices, DrawOperationType drawOp = DOT_TRIANGLE_LIST);
  37. /**
  38. * @brief Constructs a new mesh with one or multiple sub-meshes. (When using just one sub-mesh it is equivalent
  39. * to using the other overload).
  40. *
  41. * @param numVertices Number of vertices in the mesh.
  42. * @param numIndices Number of indices in the mesh.
  43. * @param subMeshes Defines how are indices separated into sub-meshes, and how are those sub-meshes rendered.
  44. */
  45. MeshBase(UINT32 numVertices, UINT32 numIndices, const Vector<SubMesh>& subMeshes);
  46. virtual ~MeshBase();
  47. /**
  48. * @brief Retrieves a sub-mesh containing data used for rendering a
  49. * certain portion of this mesh. If no sub-meshes are specified manually
  50. * a special sub-mesh containing all indices is returned.
  51. *
  52. * @note Thread safe.
  53. */
  54. const SubMesh& getSubMesh(UINT32 subMeshIdx = 0) const;
  55. /**
  56. * @brief Retrieves a total number of sub-meshes in this mesh.
  57. *
  58. * @note Thread safe.
  59. */
  60. UINT32 getNumSubMeshes() const;
  61. /**
  62. * @brief Returns maximum number of vertices the mesh may store.
  63. *
  64. * @note Thread safe.
  65. */
  66. UINT32 getNumVertices() const { return mNumVertices; }
  67. /**
  68. * @brief Returns maximum number of indices the mesh may store.
  69. *
  70. * @note Thread safe.
  71. */
  72. UINT32 getNumIndices() const { return mNumIndices; }
  73. /**
  74. * @brief Get vertex data used for rendering.
  75. *
  76. * @note Core thread only. Internal method.
  77. */
  78. virtual std::shared_ptr<VertexData> _getVertexData() const = 0;
  79. /**
  80. * @brief Get index data used for rendering.
  81. *
  82. * @note Core thread only. Internal method.
  83. */
  84. virtual IndexBufferPtr _getIndexBuffer() const = 0;
  85. /**
  86. * @brief Returns an offset into the vertex buffers that is returned
  87. * by getVertexData that signifies where this meshes vertices
  88. * begin.
  89. *
  90. * @note Used when multiple meshes share the same buffers.
  91. *
  92. * Core thread only. Internal method.
  93. */
  94. virtual UINT32 _getVertexOffset() const { return 0; }
  95. /**
  96. * @brief Returns an offset into the index buffer that is returned
  97. * by getIndexData that signifies where this meshes indices
  98. * begin.
  99. *
  100. * @note Used when multiple meshes share the same buffers.
  101. *
  102. * Core thread only. Internal method.
  103. */
  104. virtual UINT32 _getIndexOffset() const { return 0; }
  105. /**
  106. * @brief Called whenever this mesh starts being used on the GPU.
  107. *
  108. * @note Needs to be called after all commands referencing this
  109. * mesh have been sent to the GPU.
  110. *
  111. * Core thread only. Internal method.
  112. */
  113. virtual void _notifyUsedOnGPU() { }
  114. /************************************************************************/
  115. /* PROXIES */
  116. /************************************************************************/
  117. /**
  118. * @brief Gets mesh proxy object unique to this mesh. Each Mesh
  119. * has one proxy. Mesh will update the proxy as changes to Mesh occur.
  120. */
  121. virtual MeshProxy& _getMeshProxy(UINT32 subMeshIdx) = 0;
  122. protected:
  123. Vector<SubMesh> mSubMeshes; // Immutable
  124. UINT32 mNumVertices; // Immutable
  125. UINT32 mNumIndices; // Immutable
  126. /************************************************************************/
  127. /* SERIALIZATION */
  128. /************************************************************************/
  129. private:
  130. MeshBase(); // Serialization only
  131. public:
  132. friend class MeshBaseRTTI;
  133. static RTTITypeBase* getRTTIStatic();
  134. virtual RTTITypeBase* getRTTI() const;
  135. };
  136. }