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