CmMesh.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #pragma once
  2. #include "CmPrerequisites.h"
  3. #include "CmResource.h"
  4. #include "CmMeshData.h"
  5. #include "CmVertexIndexData.h"
  6. #include "CmRenderOperation.h"
  7. namespace CamelotEngine
  8. {
  9. struct CM_EXPORT SubMesh
  10. {
  11. SubMesh():
  12. indexOffset(0), indexCount(0)
  13. { }
  14. SubMesh(UINT32 indexOffset, UINT32 indexCount):
  15. indexOffset(indexOffset), indexCount(indexCount)
  16. { }
  17. UINT32 indexOffset;
  18. UINT32 indexCount;
  19. };
  20. class CM_EXPORT Mesh : public Resource
  21. {
  22. public:
  23. virtual ~Mesh();
  24. void initialize();
  25. virtual void initialize_internal();
  26. /**
  27. * @brief Mesh data that is used for initializing the mesh. Needs to be set before calling load.
  28. */
  29. void setMeshData(MeshDataPtr meshData);
  30. void setMeshData_internal(MeshDataPtr meshData);
  31. /**
  32. * @brief Gets the mesh data from the GPU. This method is slow so be careful when you call it.
  33. */
  34. MeshDataPtr getMeshData();
  35. void getMeshData_internal(AsyncOp& asyncOp);
  36. RenderOperation getRenderOperation(UINT32 subMeshIdx = 0) const;
  37. private:
  38. Mesh();
  39. VertexData* mVertexData;
  40. IndexData* mIndexData;
  41. vector<SubMesh>::type mSubMeshes;
  42. void throwIfNotRenderThread() const;
  43. /************************************************************************/
  44. /* SERIALIZATION */
  45. /************************************************************************/
  46. public:
  47. friend class MeshRTTI;
  48. static RTTITypeBase* getRTTIStatic();
  49. virtual RTTITypeBase* getRTTI() const;
  50. /************************************************************************/
  51. /* STATICS */
  52. /************************************************************************/
  53. private:
  54. static MeshPtr createEmpty();
  55. /**
  56. * @brief Returns empty mesh data. (Technically it is not empty,
  57. * as 0 sized buffers will cause problems, so it contains 3 indices
  58. * and 1 vertex).
  59. */
  60. static MeshDataPtr getNullMeshData();
  61. public:
  62. static MeshPtr create();
  63. };
  64. }