CmCoreGpuObjectManager.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. #pragma once
  2. #include "CmPrerequisites.h"
  3. #include "CmModule.h"
  4. namespace CamelotEngine
  5. {
  6. // TODO - Add debug option that would remember a call stack for each resource initialization,
  7. // so when we fail to release one we know which one it is.
  8. class CM_EXPORT CoreGpuObjectManager : public Module<CoreGpuObjectManager>
  9. {
  10. public:
  11. CoreGpuObjectManager();
  12. ~CoreGpuObjectManager();
  13. UINT64 registerObject(CoreGpuObject* object);
  14. void unregisterObject(CoreGpuObject* object);
  15. void registerObjectToDestroy(std::shared_ptr<CoreGpuObject> object);
  16. void unregisterObjectToDestroy(std::shared_ptr<CoreGpuObject> object);
  17. private:
  18. // Keeps a list of ALL loaded core GPU objects
  19. UINT64 mNextAvailableID;
  20. map<UINT64, CoreGpuObject*>::type mObjects;
  21. CM_MUTEX(mObjectsMutex);
  22. // Keeps a list of GPU objects scheduled to be destroyed. We need a reference
  23. // to the object here, otherwise the object may reach reference count of 0 and be
  24. // deleted before its scheduled destroy() method is called. Object is added to the list
  25. // when destroy() is initialized, and removed when it is finished.
  26. map<UINT64, std::shared_ptr<CoreGpuObject>>::type mObjectsToDestroy;
  27. CM_MUTEX(mObjectsToDestroyMutex);
  28. };
  29. }