CmMeshBase.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #pragma once
  2. #include "CmPrerequisites.h"
  3. #include "CmGpuResource.h"
  4. #include "CmDrawOps.h"
  5. #include "CmSubMesh.h"
  6. namespace CamelotFramework
  7. {
  8. enum class MeshBufferType
  9. {
  10. Static,
  11. Dynamic
  12. };
  13. class CM_EXPORT MeshBase : public GpuResource
  14. {
  15. public:
  16. MeshBase(UINT32 numVertices, UINT32 numIndices, DrawOperationType drawOp = DOT_TRIANGLE_LIST);
  17. virtual ~MeshBase();
  18. void clearSubMeshes();
  19. void addSubMesh(UINT32 indexOffset, UINT32 indexCount, DrawOperationType drawOp = DOT_TRIANGLE_LIST);
  20. /**
  21. * @brief Sets a set of sub-meshes containing data used for rendering a
  22. * certain portion of this mesh. Overwrites any previous sub-meshes.
  23. *
  24. * @note Sim thread only.
  25. */
  26. void setSubMeshes(const Vector<SubMesh>::type& subMeshes);
  27. /**
  28. * @brief Retrieves a sub-mesh containing data used for rendering a
  29. * certain portion of this mesh.
  30. *
  31. * @note Sim thread only.
  32. */
  33. const SubMesh& getSubMesh(UINT32 subMeshIdx = 0) const;
  34. /**
  35. * @brief Retrieves a total number of sub-meshes in this mesh.
  36. *
  37. * @note Sim thread only.
  38. */
  39. UINT32 getNumSubMeshes() const;
  40. UINT32 getNumVertices() const { return mNumVertices; }
  41. UINT32 getNumIndices() const { return mNumIndices; }
  42. /**
  43. * @brief Get vertex data used for rendering.
  44. *
  45. * @note Core thread only. Internal method.
  46. */
  47. virtual std::shared_ptr<VertexData> getVertexData() const = 0;
  48. /**
  49. * @brief Get index data used for rendering.
  50. *
  51. * @note Core thread only. Internal method.
  52. */
  53. virtual std::shared_ptr<IndexData> getIndexData() const = 0;
  54. /**
  55. * @brief Returns an offset into the vertex buffers that is returned
  56. * by getVertexData that signifies where this meshes vertices
  57. * begin.
  58. *
  59. * @note Used when multiple meshes share the same buffers.
  60. *
  61. * Core thread only. Internal method.
  62. */
  63. virtual UINT32 getVertexOffset() const { return 0; }
  64. /**
  65. * @brief Returns an offset into the index buffer that is returned
  66. * by getIndexData that signifies where this meshes indices
  67. * begin.
  68. *
  69. * @note Used when multiple meshes share the same buffers.
  70. *
  71. * Core thread only. Internal method.
  72. */
  73. virtual UINT32 getIndexOffset() const { return 0; }
  74. /**
  75. * @brief Called whenever this mesh starts being used on the GPU.
  76. *
  77. * @note Needs to be called after all commands referencing this
  78. * mesh have been sent to the GPU.
  79. *
  80. * Core thread only. Internal method.
  81. */
  82. virtual void notifyUsedOnGPU() { }
  83. protected:
  84. Vector<SubMesh>::type mSubMeshes; // Sim thread
  85. SubMesh mDefaultSubMesh; // Immutable
  86. UINT32 mNumVertices; // Immutable
  87. UINT32 mNumIndices; // Immutable
  88. /************************************************************************/
  89. /* SERIALIZATION */
  90. /************************************************************************/
  91. private:
  92. MeshBase(); // Serialization only
  93. public:
  94. friend class MeshBaseRTTI;
  95. static RTTITypeBase* getRTTIStatic();
  96. virtual RTTITypeBase* getRTTI() const;
  97. };
  98. }