Common.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // Copyright (C) 2009-2021, 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/Allocator.h>
  7. #include <AnKi/Util/DynamicArray.h>
  8. #include <AnKi/Util/String.h>
  9. #include <AnKi/Util/Ptr.h>
  10. #include <AnKi/Gr/Enums.h>
  11. #include <AnKi/Shaders/Include/ModelTypes.h>
  12. namespace anki {
  13. // Forward
  14. class GrManager;
  15. class ResourceManager;
  16. class ResourceFilesystem;
  17. template<typename Type>
  18. class ResourcePointer;
  19. class TransferGpuAllocatorHandle;
  20. /// @addtogroup resource
  21. /// @{
  22. #define ANKI_RESOURCE_LOGI(...) ANKI_LOG("RSRC", NORMAL, __VA_ARGS__)
  23. #define ANKI_RESOURCE_LOGE(...) ANKI_LOG("RSRC", ERROR, __VA_ARGS__)
  24. #define ANKI_RESOURCE_LOGW(...) ANKI_LOG("RSRC", WARNING, __VA_ARGS__)
  25. #define ANKI_RESOURCE_LOGF(...) ANKI_LOG("RSRC", FATAL, __VA_ARGS__)
  26. /// @name Constants
  27. /// @{
  28. enum class RayType : U8
  29. {
  30. SHADOWS,
  31. GI,
  32. REFLECTIONS,
  33. PATH_TRACING,
  34. COUNT,
  35. FIRST = 0
  36. };
  37. ANKI_ENUM_ALLOW_NUMERIC_OPERATIONS(RayType)
  38. enum class RayTypeBit : U8
  39. {
  40. NONE,
  41. SHADOWS = 1 << 0,
  42. GI = 1 << 1,
  43. REFLECTIONS = 1 << 2,
  44. PATH_TRACING = 1 << 3,
  45. ALL = SHADOWS | GI | REFLECTIONS | PATH_TRACING
  46. };
  47. ANKI_ENUM_ALLOW_NUMERIC_OPERATIONS(RayTypeBit)
  48. /// @}
  49. /// Deleter for ResourcePtr.
  50. template<typename T>
  51. class ResourcePtrDeleter
  52. {
  53. public:
  54. void operator()(T* ptr);
  55. };
  56. /// Smart pointer for resources.
  57. template<typename T>
  58. using ResourcePtr = IntrusivePtr<T, ResourcePtrDeleter<T>>;
  59. // NOTE: Add resources in 3 places
  60. #define ANKI_INSTANTIATE_RESOURCE(rsrc_, name_) \
  61. class rsrc_; \
  62. using name_ = ResourcePtr<rsrc_>;
  63. #define ANKI_INSTANSIATE_RESOURCE_DELIMITER()
  64. #include <AnKi/Resource/InstantiationMacros.h>
  65. #undef ANKI_INSTANTIATE_RESOURCE
  66. #undef ANKI_INSTANSIATE_RESOURCE_DELIMITER
  67. template<typename T>
  68. using ResourceAllocator = HeapAllocator<T>;
  69. template<typename T>
  70. using TempResourceAllocator = StackAllocator<T>;
  71. /// An alias that denotes a ResourceFilesystem path.
  72. using ResourceFilename = CString;
  73. /// @}
  74. } // end namespace anki