CmMesh.h 3.1 KB

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