CmMeshBase.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #pragma once
  2. #include "CmPrerequisites.h"
  3. #include "CmGpuResource.h"
  4. #include "CmDrawOps.h"
  5. #include "CmSubMesh.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. class CM_EXPORT MeshBase : public GpuResource
  24. {
  25. public:
  26. /**
  27. * @brief Constructs a new instance.
  28. * @param numVertices Number of vertices in the mesh.
  29. * @param numIndices Number of indices in the mesh.
  30. * @param drawOp Determines how should the provided indices be interpreted by the pipeline. Default option is triangles,
  31. * where three indices represent a single triangle.
  32. */
  33. MeshBase(UINT32 numVertices, UINT32 numIndices, DrawOperationType drawOp = DOT_TRIANGLE_LIST);
  34. virtual ~MeshBase();
  35. /**
  36. * @brief Removes all sub-meshes in the mesh. All indices in the mesh will be assumed to
  37. * belong to a single mesh.
  38. *
  39. * @note Sim thread only.
  40. */
  41. void clearSubMeshes();
  42. /**
  43. * @brief Allows you to mark a part of the mesh as a sub-mesh so you may draw that part separately.
  44. *
  45. * @note Sim thread only.
  46. */
  47. void addSubMesh(UINT32 indexOffset, UINT32 indexCount, DrawOperationType drawOp = DOT_TRIANGLE_LIST);
  48. /**
  49. * @brief Sets a set of sub-meshes containing data used for rendering a
  50. * certain portion of this mesh. Overwrites any previous sub-meshes.
  51. *
  52. * @note Sim thread only.
  53. */
  54. void setSubMeshes(const Vector<SubMesh>& subMeshes);
  55. /**
  56. * @brief Retrieves a sub-mesh containing data used for rendering a
  57. * certain portion of this mesh. If no sub-meshes are specified manually
  58. * a special sub-mesh containing all indices is returned.
  59. *
  60. * @note Sim thread only.
  61. */
  62. const SubMesh& getSubMesh(UINT32 subMeshIdx = 0) const;
  63. /**
  64. * @brief Retrieves a total number of sub-meshes in this mesh.
  65. *
  66. * @note Sim thread only.
  67. */
  68. UINT32 getNumSubMeshes() const;
  69. UINT32 getNumVertices() const { return mNumVertices; }
  70. UINT32 getNumIndices() const { return mNumIndices; }
  71. /**
  72. * @brief Get vertex data used for rendering.
  73. *
  74. * @note Core thread only. Internal method.
  75. */
  76. virtual std::shared_ptr<VertexData> _getVertexData() const = 0;
  77. /**
  78. * @brief Get index data used for rendering.
  79. *
  80. * @note Core thread only. Internal method.
  81. */
  82. virtual std::shared_ptr<IndexData> _getIndexData() const = 0;
  83. /**
  84. * @brief Returns an offset into the vertex buffers that is returned
  85. * by getVertexData that signifies where this meshes vertices
  86. * begin.
  87. *
  88. * @note Used when multiple meshes share the same buffers.
  89. *
  90. * Core thread only. Internal method.
  91. */
  92. virtual UINT32 _getVertexOffset() const { return 0; }
  93. /**
  94. * @brief Returns an offset into the index buffer that is returned
  95. * by getIndexData that signifies where this meshes indices
  96. * begin.
  97. *
  98. * @note Used when multiple meshes share the same buffers.
  99. *
  100. * Core thread only. Internal method.
  101. */
  102. virtual UINT32 _getIndexOffset() const { return 0; }
  103. /**
  104. * @brief Called whenever this mesh starts being used on the GPU.
  105. *
  106. * @note Needs to be called after all commands referencing this
  107. * mesh have been sent to the GPU.
  108. *
  109. * Core thread only. Internal method.
  110. */
  111. virtual void _notifyUsedOnGPU() { }
  112. protected:
  113. Vector<SubMesh> mSubMeshes; // Sim thread
  114. SubMesh mDefaultSubMesh; // Immutable
  115. UINT32 mNumVertices; // Immutable
  116. UINT32 mNumIndices; // Immutable
  117. /************************************************************************/
  118. /* SERIALIZATION */
  119. /************************************************************************/
  120. private:
  121. MeshBase(); // Serialization only
  122. public:
  123. friend class MeshBaseRTTI;
  124. static RTTITypeBase* getRTTIStatic();
  125. virtual RTTITypeBase* getRTTI() const;
  126. };
  127. }