Common.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright (C) 2009-2023, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma once
  6. #include <AnKi/Util/Ptr.h>
  7. #include <AnKi/Gr/Common.h>
  8. #include <AnKi/Shaders/Include/ModelTypes.h>
  9. namespace anki {
  10. // Forward
  11. class GrManager;
  12. class ResourceManager;
  13. class ResourceFilesystem;
  14. template<typename Type>
  15. class ResourcePointer;
  16. class TransferGpuAllocatorHandle;
  17. class PhysicsWorld;
  18. /// @addtogroup resource
  19. /// @{
  20. #define ANKI_RESOURCE_LOGI(...) ANKI_LOG("RSRC", kNormal, __VA_ARGS__)
  21. #define ANKI_RESOURCE_LOGE(...) ANKI_LOG("RSRC", kError, __VA_ARGS__)
  22. #define ANKI_RESOURCE_LOGW(...) ANKI_LOG("RSRC", kWarning, __VA_ARGS__)
  23. #define ANKI_RESOURCE_LOGF(...) ANKI_LOG("RSRC", kFatal, __VA_ARGS__)
  24. #define ANKI_RESOURCE_LOGV(...) ANKI_LOG("RSRC", kVerbose, __VA_ARGS__)
  25. class ResourceMemoryPool : public HeapMemoryPool, public MakeSingleton<ResourceMemoryPool>
  26. {
  27. template<typename>
  28. friend class MakeSingleton;
  29. private:
  30. ResourceMemoryPool(AllocAlignedCallback allocCb, void* allocCbUserData)
  31. : HeapMemoryPool(allocCb, allocCbUserData, "ResourceMemPool")
  32. {
  33. }
  34. ~ResourceMemoryPool() = default;
  35. };
  36. ANKI_DEFINE_SUBMODULE_UTIL_CONTAINERS(Resource, ResourceMemoryPool)
  37. /// Deleter for ResourcePtr.
  38. template<typename T>
  39. class ResourcePtrDeleter
  40. {
  41. public:
  42. void operator()(T* ptr);
  43. };
  44. /// Smart pointer for resources.
  45. template<typename T>
  46. using ResourcePtr = IntrusivePtr<T, ResourcePtrDeleter<T>>;
  47. // NOTE: Add resources in 3 places
  48. #define ANKI_INSTANTIATE_RESOURCE(rsrc_, name_) \
  49. class rsrc_; \
  50. using name_ = ResourcePtr<rsrc_>;
  51. #define ANKI_INSTANSIATE_RESOURCE_DELIMITER()
  52. #include <AnKi/Resource/InstantiationMacros.h>
  53. #undef ANKI_INSTANTIATE_RESOURCE
  54. #undef ANKI_INSTANSIATE_RESOURCE_DELIMITER
  55. /// An alias that denotes a ResourceFilesystem path.
  56. using ResourceFilename = CString;
  57. /// @}
  58. } // end namespace anki