2
0

CmMeshBase.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. /**
  41. * @brief Get vertex data used for rendering.
  42. *
  43. * @note Core thread only. Internal method.
  44. */
  45. virtual std::shared_ptr<VertexData> getVertexData() const = 0;
  46. /**
  47. * @brief Get index data used for rendering.
  48. *
  49. * @note Core thread only. Internal method.
  50. */
  51. virtual std::shared_ptr<IndexData> getIndexData() const = 0;
  52. /**
  53. * @brief Returns an offset into the vertex buffers that is returned
  54. * by getVertexData that signifies where this meshes vertices
  55. * begin.
  56. *
  57. * @note Used when multiple meshes share the same buffers.
  58. *
  59. * Core thread only. Internal method.
  60. */
  61. virtual UINT32 getVertexOffset() const { return 0; }
  62. /**
  63. * @brief Returns an offset into the index buffer that is returned
  64. * by getIndexData that signifies where this meshes indices
  65. * begin.
  66. *
  67. * @note Used when multiple meshes share the same buffers.
  68. *
  69. * Core thread only. Internal method.
  70. */
  71. virtual UINT32 getIndexOffset() const { return 0; }
  72. /**
  73. * @brief Called whenever this mesh starts being used on the GPU.
  74. *
  75. * @note Needs to be called after all commands referencing this
  76. * mesh have been sent to the GPU.
  77. *
  78. * Core thread only. Internal method.
  79. */
  80. virtual void notifyUsedOnGPU() { }
  81. protected:
  82. Vector<SubMesh>::type mSubMeshes; // Sim thread
  83. SubMesh mDefaultSubMesh; // Immutable
  84. UINT32 mNumVertices; // Immutable
  85. UINT32 mNumIndices; // Immutable
  86. /************************************************************************/
  87. /* SERIALIZATION */
  88. /************************************************************************/
  89. private:
  90. MeshBase(); // Serialization only
  91. public:
  92. friend class MeshBaseRTTI;
  93. static RTTITypeBase* getRTTIStatic();
  94. virtual RTTITypeBase* getRTTI() const;
  95. };
  96. }