CmMesh.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #pragma once
  2. #include "CmPrerequisites.h"
  3. #include "CmMeshBase.h"
  4. #include "CmMeshData.h"
  5. #include "CmVertexData.h"
  6. #include "CmIndexData.h"
  7. #include "CmDrawOps.h"
  8. #include "CmSubMesh.h"
  9. namespace CamelotFramework
  10. {
  11. class CM_EXPORT Mesh : public MeshBase
  12. {
  13. public:
  14. virtual ~Mesh();
  15. /**
  16. * @copydoc GpuResource::writeSubresource
  17. */
  18. virtual void writeSubresource(UINT32 subresourceIdx, const GpuResourceData& data, bool discardEntireBuffer);
  19. /**
  20. * @copydoc GpuResource::readSubresource
  21. */
  22. virtual void readSubresource(UINT32 subresourceIdx, GpuResourceData& data);
  23. /**
  24. * @brief Allocates a buffer you may use for storage when reading a subresource. You
  25. * need to allocate such a buffer if you are calling "readSubresource".
  26. *
  27. * @note This method is thread safe.
  28. */
  29. MeshDataPtr allocateSubresourceBuffer(UINT32 subresourceIdx) const;
  30. /**
  31. * @brief TODO - Currently does nothing. But normally it should provide a way to map subresource index to
  32. * a specific submesh or buffer stream. Right now you can only work with entire mesh at once, not its subsets.
  33. */
  34. void mapFromSubresourceIdx(UINT32 subresourceIdx) const {}
  35. /**
  36. * @brief TODO - Currently does nothing. But normally it should provide a way to map submesh or stream index to
  37. * a specific subresource index. Right now you can only work with entire mesh at once, not its subsets.
  38. */
  39. UINT32 mapToSubresourceIdx() const { return 0; }
  40. const AABox& getBounds() const;
  41. const AABox& getBounds(UINT32 submeshIdx) const;
  42. /**
  43. * @copydoc MeshBase::getVertexData
  44. */
  45. virtual std::shared_ptr<VertexData> getVertexData() const;
  46. /**
  47. * @copydoc MeshBase::getIndexData
  48. */
  49. virtual std::shared_ptr<IndexData> getIndexData() const;
  50. /**
  51. * @brief Returns a dummy mesh, containing just one triangle. Don't modify the returned mesh.
  52. */
  53. static HMesh dummy();
  54. protected:
  55. friend class MeshManager;
  56. Mesh(UINT32 numVertices, UINT32 numIndices,
  57. const VertexDataDescPtr& vertexDesc, MeshBufferType bufferType = MeshBufferType::Static,
  58. DrawOperationType drawOp = DOT_TRIANGLE_LIST, IndexBuffer::IndexType indexType = IndexBuffer::IT_32BIT);
  59. Mesh(UINT32 numVertices, UINT32 numIndices, const VertexDataDescPtr& vertexDesc, const MeshDataPtr& initialMeshData,
  60. MeshBufferType bufferType = MeshBufferType::Static, DrawOperationType drawOp = DOT_TRIANGLE_LIST,
  61. IndexBuffer::IndexType indexType = IndexBuffer::IT_32BIT);
  62. Mesh(const MeshDataPtr& initialMeshData,
  63. MeshBufferType bufferType = MeshBufferType::Static, DrawOperationType drawOp = DOT_TRIANGLE_LIST);
  64. std::shared_ptr<VertexData> mVertexData; // Core thread
  65. std::shared_ptr<IndexData> mIndexData; // Core thread
  66. VertexDataDescPtr mVertexDesc; // Immutable
  67. MeshBufferType mBufferType; // Immutable
  68. IndexBuffer::IndexType mIndexType; // Immutable
  69. MeshDataPtr mTempInitialMeshData; // Immutable
  70. /**
  71. * @copydoc Resource::initialize_internal()
  72. */
  73. virtual void initialize_internal();
  74. /**
  75. * @copydoc Resource::destroy_internal()
  76. */
  77. virtual void destroy_internal();
  78. /************************************************************************/
  79. /* SERIALIZATION */
  80. /************************************************************************/
  81. private:
  82. Mesh(); // Serialization only
  83. public:
  84. friend class MeshRTTI;
  85. static RTTITypeBase* getRTTIStatic();
  86. virtual RTTITypeBase* getRTTI() const;
  87. /************************************************************************/
  88. /* STATICS */
  89. /************************************************************************/
  90. public:
  91. static HMesh create(UINT32 numVertices, UINT32 numIndices,
  92. const VertexDataDescPtr& vertexDesc, MeshBufferType bufferType = MeshBufferType::Static,
  93. DrawOperationType drawOp = DOT_TRIANGLE_LIST, IndexBuffer::IndexType indexType = IndexBuffer::IT_32BIT);
  94. static HMesh create(UINT32 numVertices, UINT32 numIndices, const VertexDataDescPtr& vertexDesc, const MeshDataPtr& initialMeshData,
  95. MeshBufferType bufferType = MeshBufferType::Static, DrawOperationType drawOp = DOT_TRIANGLE_LIST,
  96. IndexBuffer::IndexType indexType = IndexBuffer::IT_32BIT);
  97. static HMesh create(const MeshDataPtr& initialMeshData, MeshBufferType bufferType = MeshBufferType::Static,
  98. DrawOperationType drawOp = DOT_TRIANGLE_LIST);
  99. };
  100. }