CmMesh.h 3.4 KB

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