ImGuiConfig.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. // Copyright (C) 2009-present, 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/Assert.h>
  7. #include <AnKi/Math/Vec.h>
  8. #include <AnKi/Gr/Texture.h>
  9. #include <AnKi/Gr/ShaderProgram.h>
  10. #define IM_ASSERT(_EXPR) ANKI_ASSERT(_EXPR)
  11. #define IMGUI_DISABLE_OBSOLETE_FUNCTIONS 1
  12. #define IMGUI_DISABLE_DEFAULT_ALLOCATORS 1
  13. #define IMGUI_USE_WCHAR32 1
  14. #define IM_VEC2_CLASS_EXTRA \
  15. ImVec2(const anki::Vec2& f) \
  16. { \
  17. x = f.x; \
  18. y = f.y; \
  19. } \
  20. operator anki::Vec2() const \
  21. { \
  22. return anki::Vec2(x, y); \
  23. }
  24. #define IM_VEC4_CLASS_EXTRA \
  25. ImVec4(const anki::Vec4& f) \
  26. { \
  27. x = f.x; \
  28. y = f.y; \
  29. z = f.z; \
  30. w = f.w; \
  31. } \
  32. operator anki::Vec4() const \
  33. { \
  34. return anki::Vec4(x, y, z, w); \
  35. }
  36. // TLS context.
  37. struct ImGuiContext;
  38. namespace anki {
  39. extern thread_local ImGuiContext* g_imguiTlsCtx;
  40. } // end namespace anki
  41. #define GImGui anki::g_imguiTlsCtx
  42. // ImTextureID
  43. namespace anki {
  44. struct AnKiImTextureID_Invalid
  45. {
  46. };
  47. /// Implements a custom ImTextureID
  48. class AnKiImTextureID
  49. {
  50. public:
  51. Texture* m_texture = nullptr;
  52. TextureSubresourceDesc m_textureSubresource = TextureSubresourceDesc::all();
  53. ShaderProgram* m_customProgram = nullptr;
  54. Array<U8, 64> m_extraFastConstants = {};
  55. U8 m_extraFastConstantsSize = 0;
  56. Bool m_pointSampling = false;
  57. Bool m_textureIsRefcounted = false; ///< Only set for ImGui internal textures. Don't touch it.
  58. AnKiImTextureID() = default;
  59. AnKiImTextureID(const AnKiImTextureID& b) = default;
  60. AnKiImTextureID(Texture* tex)
  61. : m_texture(tex)
  62. {
  63. ANKI_ASSERT(tex);
  64. }
  65. explicit AnKiImTextureID(AnKiImTextureID_Invalid)
  66. {
  67. *this = AnKiImTextureID();
  68. }
  69. AnKiImTextureID& operator=(AnKiImTextureID_Invalid)
  70. {
  71. *this = AnKiImTextureID();
  72. return *this;
  73. }
  74. AnKiImTextureID& operator=(const AnKiImTextureID& b) = default;
  75. Bool operator==(const AnKiImTextureID& b) const
  76. {
  77. return m_texture == b.m_texture;
  78. }
  79. Bool operator==(AnKiImTextureID_Invalid) const
  80. {
  81. return m_texture == nullptr;
  82. }
  83. Bool operator!=(AnKiImTextureID_Invalid) const
  84. {
  85. return m_texture != nullptr;
  86. }
  87. operator intptr_t() const
  88. {
  89. return intptr_t(this);
  90. }
  91. void setExtraFastConstants(const void* ptr, PtrSize fastConstantsSize)
  92. {
  93. ANKI_ASSERT(ptr);
  94. ANKI_ASSERT(fastConstantsSize > 0 && fastConstantsSize < sizeof(m_extraFastConstants));
  95. m_extraFastConstantsSize = U8(fastConstantsSize);
  96. memcpy(m_extraFastConstants.getBegin(), ptr, fastConstantsSize);
  97. }
  98. };
  99. static_assert(std::is_trivially_destructible_v<AnKiImTextureID>, "For some reason ImGui doesn't work otherwise");
  100. } // end namespace anki
  101. #define ImTextureID anki::AnKiImTextureID
  102. #define ImTextureID_Invalid anki::AnKiImTextureID_Invalid()