2
0

imgui_impl_null.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // dear imgui: Null Platform+Renderer Backends
  2. // This is designed if you need to use a blind Dear Imgui context with no input and no output.
  3. // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
  4. // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
  5. // Learn about Dear ImGui:
  6. // - FAQ https://dearimgui.com/faq
  7. // - Getting Started https://dearimgui.com/getting-started
  8. // - Documentation https://dearimgui.com/docs (same as your local docs/ folder).
  9. // - Introduction, links and more at the top of imgui.cpp
  10. // CHANGELOG
  11. // (minor and older changes stripped away, please see git history for details)
  12. // 2025-11-17: Initial version.
  13. #include "imgui.h"
  14. #ifndef IMGUI_DISABLE
  15. #include "imgui_impl_null.h"
  16. // Clang/GCC warnings with -Weverything
  17. #if defined(__clang__)
  18. #pragma clang diagnostic ignored "-Wold-style-cast" // warning: use of old-style cast // yes, they are more terse.
  19. #endif
  20. IMGUI_IMPL_API bool ImGui_ImplNull_Init()
  21. {
  22. ImGui_ImplNullPlatform_Init();
  23. ImGui_ImplNullRender_Init();
  24. return true;
  25. }
  26. IMGUI_IMPL_API void ImGui_ImplNull_Shutdown()
  27. {
  28. ImGui_ImplNullRender_Shutdown();
  29. ImGui_ImplNullPlatform_Shutdown();
  30. }
  31. IMGUI_IMPL_API void ImGui_ImplNull_NewFrame()
  32. {
  33. ImGui_ImplNullPlatform_NewFrame();
  34. ImGui_ImplNullRender_NewFrame();
  35. }
  36. IMGUI_IMPL_API bool ImGui_ImplNullPlatform_Init()
  37. {
  38. ImGuiIO& io = ImGui::GetIO();
  39. io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors;
  40. return true;
  41. }
  42. IMGUI_IMPL_API void ImGui_ImplNullPlatform_Shutdown()
  43. {
  44. ImGuiIO& io = ImGui::GetIO();
  45. io.BackendFlags &= ~ImGuiBackendFlags_HasMouseCursors;
  46. }
  47. IMGUI_IMPL_API void ImGui_ImplNullPlatform_NewFrame()
  48. {
  49. ImGuiIO& io = ImGui::GetIO();
  50. io.DisplaySize = ImVec2(1920, 1080);
  51. io.DeltaTime = 1.0f / 60.0f;
  52. }
  53. IMGUI_IMPL_API bool ImGui_ImplNullRender_Init()
  54. {
  55. ImGuiIO& io = ImGui::GetIO();
  56. io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset;
  57. io.BackendFlags |= ImGuiBackendFlags_RendererHasTextures;
  58. return true;
  59. }
  60. IMGUI_IMPL_API void ImGui_ImplNullRender_Shutdown()
  61. {
  62. ImGuiIO& io = ImGui::GetIO();
  63. io.BackendFlags &= ~ImGuiBackendFlags_RendererHasVtxOffset;
  64. io.BackendFlags &= ~ImGuiBackendFlags_RendererHasTextures;
  65. }
  66. IMGUI_IMPL_API void ImGui_ImplNullRender_NewFrame()
  67. {
  68. }
  69. static void ImGui_ImplNullRender_UpdateTexture(ImTextureData* tex)
  70. {
  71. if (tex->Status == ImTextureStatus_WantCreate || tex->Status == ImTextureStatus_WantDestroy)
  72. tex->SetStatus(ImTextureStatus_OK);
  73. if (tex->Status == ImTextureStatus_WantDestroy)
  74. {
  75. tex->SetTexID(ImTextureID_Invalid);
  76. tex->SetStatus(ImTextureStatus_Destroyed);
  77. }
  78. }
  79. IMGUI_IMPL_API void ImGui_ImplNullRender_RenderDrawData(ImDrawData* draw_data)
  80. {
  81. if (draw_data->Textures != nullptr)
  82. for (ImTextureData* tex : *draw_data->Textures)
  83. if (tex->Status != ImTextureStatus_OK)
  84. ImGui_ImplNullRender_UpdateTexture(tex);
  85. }
  86. #endif // #ifndef IMGUI_DISABLE