Common.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 ImGUI
  7. #include <AnKi/Ui/ImGuiConfig.h>
  8. #include <ImGui/imgui.h>
  9. #include <AnKi/Util/Allocator.h>
  10. #include <AnKi/Util/Ptr.h>
  11. #include <AnKi/Gr/TextureView.h>
  12. namespace anki {
  13. // Forward
  14. class UiManager;
  15. /// @addtogroup ui
  16. /// @{
  17. #define ANKI_UI_LOGI(...) ANKI_LOG("UI ", NORMAL, __VA_ARGS__)
  18. #define ANKI_UI_LOGE(...) ANKI_LOG("UI ", ERROR, __VA_ARGS__)
  19. #define ANKI_UI_LOGW(...) ANKI_LOG("UI ", WARNING, __VA_ARGS__)
  20. #define ANKI_UI_LOGF(...) ANKI_LOG("UI ", FATAL, __VA_ARGS__)
  21. using UiAllocator = HeapAllocator<U8>;
  22. #define ANKI_UI_OBJECT_FW(name_) \
  23. class name_; \
  24. using name_##Ptr = IntrusivePtr<name_>;
  25. ANKI_UI_OBJECT_FW(Font)
  26. ANKI_UI_OBJECT_FW(Canvas)
  27. ANKI_UI_OBJECT_FW(UiImmediateModeBuilder)
  28. #undef ANKI_UI_OBJECT
  29. inline Vec2 toAnki(const ImVec2& v)
  30. {
  31. return Vec2(v.x, v.y);
  32. }
  33. /// This is what someone should push to ImGui::Image() function.
  34. class UiImageId
  35. {
  36. friend class Canvas;
  37. public:
  38. UiImageId(TextureViewPtr textureView, Bool pointSampling = false)
  39. {
  40. m_bits.m_textureViewPtr = ptrToNumber(textureView.get()) & 0x7FFFFFFFFFFFFFFFllu;
  41. m_bits.m_pointSampling = pointSampling;
  42. }
  43. operator void*() const
  44. {
  45. return numberToPtr<void*>(m_allBits);
  46. }
  47. private:
  48. class Bits
  49. {
  50. public:
  51. U64 m_textureViewPtr : 63;
  52. U64 m_pointSampling : 1;
  53. };
  54. union
  55. {
  56. Bits m_bits;
  57. U64 m_allBits;
  58. };
  59. UiImageId(void* ptr)
  60. : m_allBits(ptrToNumber(ptr))
  61. {
  62. ANKI_ASSERT(ptr);
  63. }
  64. };
  65. static_assert(sizeof(UiImageId) == sizeof(void*), "See file");
  66. /// @}
  67. } // end namespace anki