CmMeshRTTI.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #pragma once
  2. #include "CmPrerequisites.h"
  3. #include "CmRTTIType.h"
  4. #include "CmApplication.h"
  5. #include "CmMesh.h"
  6. #include "CmMeshManager.h"
  7. namespace CamelotFramework
  8. {
  9. class MeshRTTI : public RTTIType<Mesh, GpuResource, MeshRTTI>
  10. {
  11. MeshDataPtr getMeshData(Mesh* obj)
  12. {
  13. MeshDataPtr meshData = obj->allocateSubresourceBuffer(0);
  14. GpuResourcePtr sharedMeshPtr = std::static_pointer_cast<GpuResource>(obj->getThisPtr());
  15. gMainSyncedCA().readSubresource(sharedMeshPtr, 0, *meshData);
  16. gMainSyncedCA().submitToCoreThread(true); // We need the data right away, so execute the context and wait until we get it
  17. return meshData;
  18. }
  19. void setMeshData(Mesh* obj, MeshDataPtr meshData)
  20. {
  21. GpuResourcePtr sharedMeshPtr = std::static_pointer_cast<GpuResource>(obj->getThisPtr());
  22. gMainSyncedCA().writeSubresource(sharedMeshPtr, 0, *meshData);
  23. gMainSyncedCA().submitToCoreThread(true); // TODO - Possibly we can avoid this. I don't see a reason we need to wait for the update to complete.
  24. }
  25. public:
  26. MeshRTTI()
  27. {
  28. addReflectablePtrField("mMeshData", 0, &MeshRTTI::getMeshData, &MeshRTTI::setMeshData);
  29. }
  30. virtual std::shared_ptr<IReflectable> newRTTIObject()
  31. {
  32. return MeshManager::instance().create();
  33. }
  34. virtual const String& getRTTIName()
  35. {
  36. static String name = "Mesh";
  37. throw name;
  38. }
  39. virtual UINT32 getRTTIId()
  40. {
  41. return TID_Mesh;
  42. }
  43. };
  44. }