From 08fbbd9624b652d39e82a59b5680622ed42bd428 Mon Sep 17 00:00:00 2001 From: Sharadh Rajaraman Date: Mon, 28 Sep 2026 16:30:10 +0100 Subject: [PATCH] backends: prepare for inclusion in a C++20 module purview Each backend becomes its own module that imports 'imgui' and includes its header and source in the purview. Do the same preparation as for the core: - Skip system, platform and graphics API includes under IMGUI_CXX_MODULE, because the module includes them in its global module fragment. - Skip the forward declarations of platform types (GLFWwindow, SDL_Window, ID3D11Device...). Declared in the purview, they would be new types attached to the backend module instead of the real ones. For the same reason, sdl2 drops the elaborated 'struct _SDL_GameController'. - Wrap each header's API in IMGUI_EXPORT_BEGIN/END. - win32: export ImGui_ImplWin32_WndProcHandler() under IMGUI_CXX_MODULE. The header keeps it commented out to avoid pulling in , but a module user can't forward-declare it themselves. - glfw: skip the local GetIO(ImGuiContext*) declaration, because 'imgui' exports it. --- backends/imgui_impl_allegro5.cpp | 2 ++ backends/imgui_impl_allegro5.h | 4 ++++ backends/imgui_impl_android.cpp | 2 ++ backends/imgui_impl_android.h | 4 ++++ backends/imgui_impl_dx10.cpp | 2 ++ backends/imgui_impl_dx10.h | 4 ++++ backends/imgui_impl_dx11.cpp | 2 ++ backends/imgui_impl_dx11.h | 4 ++++ backends/imgui_impl_dx12.cpp | 2 ++ backends/imgui_impl_dx12.h | 5 +++++ backends/imgui_impl_dx9.cpp | 2 ++ backends/imgui_impl_dx9.h | 4 ++++ backends/imgui_impl_glfw.cpp | 4 ++++ backends/imgui_impl_glfw.h | 5 ++++- backends/imgui_impl_glut.cpp | 2 ++ backends/imgui_impl_glut.h | 2 ++ backends/imgui_impl_null.h | 2 ++ backends/imgui_impl_opengl2.cpp | 6 ++++++ backends/imgui_impl_opengl2.h | 2 ++ backends/imgui_impl_opengl3.cpp | 6 ++++++ backends/imgui_impl_opengl3.h | 4 +++- backends/imgui_impl_qnx.cpp | 2 ++ backends/imgui_impl_qnx.h | 4 ++++ backends/imgui_impl_sdl2.cpp | 6 +++++- backends/imgui_impl_sdl2.h | 6 +++++- backends/imgui_impl_sdl3.cpp | 2 ++ backends/imgui_impl_sdl3.h | 4 ++++ backends/imgui_impl_sdlgpu3.h | 4 ++++ backends/imgui_impl_sdlrenderer2.cpp | 4 ++++ backends/imgui_impl_sdlrenderer2.h | 4 ++++ backends/imgui_impl_sdlrenderer3.cpp | 4 ++++ backends/imgui_impl_sdlrenderer3.h | 4 ++++ backends/imgui_impl_vulkan.cpp | 2 ++ backends/imgui_impl_vulkan.h | 5 +++++ backends/imgui_impl_wgpu.cpp | 6 ++++++ backends/imgui_impl_wgpu.h | 6 ++++++ backends/imgui_impl_win32.cpp | 4 ++++ backends/imgui_impl_win32.h | 5 +++++ 38 files changed, 138 insertions(+), 4 deletions(-) diff --git a/backends/imgui_impl_allegro5.cpp b/backends/imgui_impl_allegro5.cpp index bd877f322..bd282e149 100644 --- a/backends/imgui_impl_allegro5.cpp +++ b/backends/imgui_impl_allegro5.cpp @@ -66,6 +66,7 @@ #include "imgui.h" #ifndef IMGUI_DISABLE #include "imgui_impl_allegro5.h" +#ifndef IMGUI_CXX_MODULE #include // uint64_t #include // memcpy @@ -75,6 +76,7 @@ #ifdef _WIN32 #include #endif +#endif #define ALLEGRO_HAS_CLIPBOARD ((ALLEGRO_VERSION_INT & ~ALLEGRO_UNSTABLE_BIT) >= ((5 << 24) | (1 << 16) | (12 << 8))) // Clipboard only supported from Allegro 5.1.12 #define ALLEGRO_HAS_DRAW_INDEXED_PRIM ((ALLEGRO_VERSION_INT & ~ALLEGRO_UNSTABLE_BIT) >= ((5 << 24) | (2 << 16) | ( 5 << 8))) // DX9 implementation of al_draw_indexed_prim() got fixed in Allegro 5.2.5 diff --git a/backends/imgui_impl_allegro5.h b/backends/imgui_impl_allegro5.h index 84ebf4338..c7b6cc190 100644 --- a/backends/imgui_impl_allegro5.h +++ b/backends/imgui_impl_allegro5.h @@ -24,9 +24,12 @@ #include "imgui.h" // IMGUI_IMPL_API #ifndef IMGUI_DISABLE +#ifndef IMGUI_CXX_MODULE struct ALLEGRO_DISPLAY; union ALLEGRO_EVENT; +#endif +IMGUI_EXPORT_BEGIN // Follow "Getting Started" link and check examples/ folder to learn about using backends! IMGUI_IMPL_API bool ImGui_ImplAllegro5_Init(ALLEGRO_DISPLAY* display); IMGUI_IMPL_API void ImGui_ImplAllegro5_Shutdown(); @@ -41,5 +44,6 @@ IMGUI_IMPL_API void ImGui_ImplAllegro5_InvalidateDeviceObjects(); // (Advanced) Use e.g. if you need to precisely control the timing of texture updates (e.g. for staged rendering), by setting ImDrawData::Textures = nullptr to handle this manually. IMGUI_IMPL_API void ImGui_ImplAllegro5_UpdateTexture(ImTextureData* tex); +IMGUI_EXPORT_END #endif // #ifndef IMGUI_DISABLE diff --git a/backends/imgui_impl_android.cpp b/backends/imgui_impl_android.cpp index 21a7ae526..68dd0ab4a 100644 --- a/backends/imgui_impl_android.cpp +++ b/backends/imgui_impl_android.cpp @@ -34,11 +34,13 @@ #include "imgui.h" #ifndef IMGUI_DISABLE #include "imgui_impl_android.h" +#ifndef IMGUI_CXX_MODULE #include #include #include #include #include +#endif // Android data static double g_Time = 0.0; diff --git a/backends/imgui_impl_android.h b/backends/imgui_impl_android.h index 8f22e9b76..a1e92675c 100644 --- a/backends/imgui_impl_android.h +++ b/backends/imgui_impl_android.h @@ -25,13 +25,17 @@ #include "imgui.h" // IMGUI_IMPL_API #ifndef IMGUI_DISABLE +#ifndef IMGUI_CXX_MODULE struct ANativeWindow; struct AInputEvent; +#endif +IMGUI_EXPORT_BEGIN // Follow "Getting Started" link and check examples/ folder to learn about using backends! IMGUI_IMPL_API bool ImGui_ImplAndroid_Init(ANativeWindow* window); IMGUI_IMPL_API int32_t ImGui_ImplAndroid_HandleInputEvent(const AInputEvent* input_event); IMGUI_IMPL_API void ImGui_ImplAndroid_Shutdown(); IMGUI_IMPL_API void ImGui_ImplAndroid_NewFrame(); +IMGUI_EXPORT_END #endif // #ifndef IMGUI_DISABLE diff --git a/backends/imgui_impl_dx10.cpp b/backends/imgui_impl_dx10.cpp index a81d81305..25a5b039a 100644 --- a/backends/imgui_impl_dx10.cpp +++ b/backends/imgui_impl_dx10.cpp @@ -47,10 +47,12 @@ #include "imgui_impl_dx10.h" // DirectX +#ifndef IMGUI_CXX_MODULE #include #include #include #include +#endif #ifdef _MSC_VER #pragma comment(lib, "d3dcompiler") // Automatically link with d3dcompiler.lib as we are using D3DCompile() below. #endif diff --git a/backends/imgui_impl_dx10.h b/backends/imgui_impl_dx10.h index 3ab1669a9..753f81228 100644 --- a/backends/imgui_impl_dx10.h +++ b/backends/imgui_impl_dx10.h @@ -19,10 +19,13 @@ #include "imgui.h" // IMGUI_IMPL_API #ifndef IMGUI_DISABLE +#ifndef IMGUI_CXX_MODULE struct ID3D10Device; struct ID3D10SamplerState; struct ID3D10Buffer; +#endif +IMGUI_EXPORT_BEGIN // Follow "Getting Started" link and check examples/ folder to learn about using backends! IMGUI_IMPL_API bool ImGui_ImplDX10_Init(ID3D10Device* device); IMGUI_IMPL_API void ImGui_ImplDX10_Shutdown(); @@ -47,5 +50,6 @@ struct ImGui_ImplDX10_RenderState //ID3D10SamplerState* SamplerNearest; // Use ImDrawList::AddCallback(ImGui::GetPlatform().DrawCallback_SetSamplerNearest) }; IMGUI_IMPL_API ImGui_ImplDX10_RenderState* ImGui_ImplDX10_GetRenderState(); +IMGUI_EXPORT_END #endif // #ifndef IMGUI_DISABLE diff --git a/backends/imgui_impl_dx11.cpp b/backends/imgui_impl_dx11.cpp index a7d2cdf73..ca7bf7dfb 100644 --- a/backends/imgui_impl_dx11.cpp +++ b/backends/imgui_impl_dx11.cpp @@ -48,9 +48,11 @@ #include "imgui_impl_dx11.h" // DirectX +#ifndef IMGUI_CXX_MODULE #include #include #include +#endif #ifdef _MSC_VER #pragma comment(lib, "d3dcompiler") // Automatically link with d3dcompiler.lib as we are using D3DCompile() below. #endif diff --git a/backends/imgui_impl_dx11.h b/backends/imgui_impl_dx11.h index 5fd8ddca9..d079867ca 100644 --- a/backends/imgui_impl_dx11.h +++ b/backends/imgui_impl_dx11.h @@ -19,11 +19,14 @@ #include "imgui.h" // IMGUI_IMPL_API #ifndef IMGUI_DISABLE +#ifndef IMGUI_CXX_MODULE struct ID3D11Device; struct ID3D11DeviceContext; struct ID3D11SamplerState; struct ID3D11Buffer; +#endif +IMGUI_EXPORT_BEGIN // Follow "Getting Started" link and check examples/ folder to learn about using backends! IMGUI_IMPL_API bool ImGui_ImplDX11_Init(ID3D11Device* device, ID3D11DeviceContext* device_context); IMGUI_IMPL_API void ImGui_ImplDX11_Shutdown(); @@ -49,5 +52,6 @@ struct ImGui_ImplDX11_RenderState //ID3D11SamplerState* SamplerNearest; // Use ImDrawList::AddCallback(ImGui::GetPlatform().DrawCallback_SetSamplerNearest) }; IMGUI_IMPL_API ImGui_ImplDX11_RenderState* ImGui_ImplDX11_GetRenderState(); +IMGUI_EXPORT_END #endif // #ifndef IMGUI_DISABLE diff --git a/backends/imgui_impl_dx12.cpp b/backends/imgui_impl_dx12.cpp index 22a9bdc97..902c23a9a 100644 --- a/backends/imgui_impl_dx12.cpp +++ b/backends/imgui_impl_dx12.cpp @@ -63,9 +63,11 @@ #include "imgui_impl_dx12.h" // DirectX +#ifndef IMGUI_CXX_MODULE #include #include #include +#endif #ifdef _MSC_VER #pragma comment(lib, "d3dcompiler") // Automatically link with d3dcompiler.lib as we are using D3DCompile() below. #endif diff --git a/backends/imgui_impl_dx12.h b/backends/imgui_impl_dx12.h index 106b4b4d2..a9df2ccea 100644 --- a/backends/imgui_impl_dx12.h +++ b/backends/imgui_impl_dx12.h @@ -21,8 +21,10 @@ #pragma once #include "imgui.h" // IMGUI_IMPL_API #ifndef IMGUI_DISABLE +#ifndef IMGUI_CXX_MODULE #include // DXGI_FORMAT #include // D3D12_CPU_DESCRIPTOR_HANDLE +#endif // Clang/GCC warnings with -Weverything #if defined(__clang__) @@ -30,6 +32,7 @@ #pragma clang diagnostic ignored "-Wold-style-cast" // warning: use of old-style cast #endif +IMGUI_EXPORT_BEGIN // Initialization data, for ImGui_ImplDX12_Init() struct ImGui_ImplDX12_InitInfo { @@ -84,6 +87,8 @@ IMGUI_IMPL_API ImGui_ImplDX12_RenderState* ImGui_ImplDX12_GetRenderState(); //IMGUI_IMPL_API bool ImGui_ImplDX12_Init(ID3D12Device* device, int num_frames_in_flight, DXGI_FORMAT rtv_format, ID3D12DescriptorHeap* srv_descriptor_heap, D3D12_CPU_DESCRIPTOR_HANDLE font_srv_cpu_desc_handle, D3D12_GPU_DESCRIPTOR_HANDLE font_srv_gpu_desc_handle); #endif +IMGUI_EXPORT_END + #if defined(__clang__) #pragma clang diagnostic pop #endif diff --git a/backends/imgui_impl_dx9.cpp b/backends/imgui_impl_dx9.cpp index 360398f04..94d2c9794 100644 --- a/backends/imgui_impl_dx9.cpp +++ b/backends/imgui_impl_dx9.cpp @@ -47,7 +47,9 @@ #include "imgui_impl_dx9.h" // DirectX +#ifndef IMGUI_CXX_MODULE #include +#endif // Clang/GCC warnings with -Weverything #if defined(__clang__) diff --git a/backends/imgui_impl_dx9.h b/backends/imgui_impl_dx9.h index 021439b9a..bffee9228 100644 --- a/backends/imgui_impl_dx9.h +++ b/backends/imgui_impl_dx9.h @@ -19,8 +19,11 @@ #include "imgui.h" // IMGUI_IMPL_API #ifndef IMGUI_DISABLE +#ifndef IMGUI_CXX_MODULE struct IDirect3DDevice9; +#endif +IMGUI_EXPORT_BEGIN // Follow "Getting Started" link and check examples/ folder to learn about using backends! IMGUI_IMPL_API bool ImGui_ImplDX9_Init(IDirect3DDevice9* device); IMGUI_IMPL_API void ImGui_ImplDX9_Shutdown(); @@ -33,5 +36,6 @@ IMGUI_IMPL_API void ImGui_ImplDX9_InvalidateDeviceObjects(); // (Advanced) Use e.g. if you need to precisely control the timing of texture updates (e.g. for staged rendering), by setting ImDrawData::Textures = nullptr to handle this manually. IMGUI_IMPL_API void ImGui_ImplDX9_UpdateTexture(ImTextureData* tex); +IMGUI_EXPORT_END #endif // #ifndef IMGUI_DISABLE diff --git a/backends/imgui_impl_glfw.cpp b/backends/imgui_impl_glfw.cpp index 678129a07..466a46883 100644 --- a/backends/imgui_impl_glfw.cpp +++ b/backends/imgui_impl_glfw.cpp @@ -132,6 +132,7 @@ #else #define GLFW_HAS_WAYLAND 0 #endif +#ifndef IMGUI_CXX_MODULE #include #ifdef _WIN32 #undef APIENTRY @@ -165,6 +166,7 @@ #define EMSCRIPTEN_USE_EMBEDDED_GLFW3 #endif #endif +#endif // #ifndef IMGUI_CXX_MODULE // We gather version tests as define in order to easily see which features are version-dependent. #define GLFW_VERSION_COMBINED (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 + GLFW_VERSION_REVISION) @@ -241,7 +243,9 @@ struct ImGui_ImplGlfw_Data // (passing install_callbacks=false in ImGui_ImplGlfw_InitXXX functions), set the current dear imgui context and then call our callbacks. // - Otherwise we may need to store a GLFWWindow* -> ImGuiContext* map and handle this in the backend, adding a little bit of extra complexity to it. // FIXME: some shared resources (mouse cursor shape, gamepad) are mishandled when using multi-context. +#ifndef IMGUI_CXX_MODULE namespace ImGui { extern ImGuiIO& GetIO(ImGuiContext*); } +#endif static ImGui_ImplGlfw_Data* ImGui_ImplGlfw_GetBackendData() { // Get data for current context diff --git a/backends/imgui_impl_glfw.h b/backends/imgui_impl_glfw.h index 7dc8cb5e1..5799d453f 100644 --- a/backends/imgui_impl_glfw.h +++ b/backends/imgui_impl_glfw.h @@ -26,9 +26,12 @@ #include "imgui.h" // IMGUI_IMPL_API #ifndef IMGUI_DISABLE +#ifndef IMGUI_CXX_MODULE struct GLFWwindow; struct GLFWmonitor; +#endif +IMGUI_EXPORT_BEGIN // Follow "Getting Started" link and check examples/ folder to learn about using backends! IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForOpenGL(GLFWwindow* window, bool install_callbacks); IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForVulkan(GLFWwindow* window, bool install_callbacks); @@ -66,6 +69,6 @@ IMGUI_IMPL_API void ImGui_ImplGlfw_MonitorCallback(GLFWmonitor* monitor, int IMGUI_IMPL_API void ImGui_ImplGlfw_Sleep(int milliseconds); IMGUI_IMPL_API float ImGui_ImplGlfw_GetContentScaleForWindow(GLFWwindow* window); IMGUI_IMPL_API float ImGui_ImplGlfw_GetContentScaleForMonitor(GLFWmonitor* monitor); - +IMGUI_EXPORT_END #endif // #ifndef IMGUI_DISABLE diff --git a/backends/imgui_impl_glut.cpp b/backends/imgui_impl_glut.cpp index a68f9dbc8..dd899c5d9 100644 --- a/backends/imgui_impl_glut.cpp +++ b/backends/imgui_impl_glut.cpp @@ -37,12 +37,14 @@ #include "imgui.h" #ifndef IMGUI_DISABLE #include "imgui_impl_glut.h" +#ifndef IMGUI_CXX_MODULE #define GL_SILENCE_DEPRECATION #ifdef __APPLE__ #include #else #include #endif +#endif #ifdef _MSC_VER #pragma warning (disable: 4505) // unreferenced local function has been removed (stb stuff) diff --git a/backends/imgui_impl_glut.h b/backends/imgui_impl_glut.h index 20e77dbce..d30eed08e 100644 --- a/backends/imgui_impl_glut.h +++ b/backends/imgui_impl_glut.h @@ -26,6 +26,7 @@ #ifndef IMGUI_DISABLE #include "imgui.h" // IMGUI_IMPL_API +IMGUI_EXPORT_BEGIN // Follow "Getting Started" link and check examples/ folder to learn about using backends! IMGUI_IMPL_API bool ImGui_ImplGLUT_Init(); IMGUI_IMPL_API void ImGui_ImplGLUT_InstallFuncs(); @@ -43,5 +44,6 @@ IMGUI_IMPL_API void ImGui_ImplGLUT_KeyboardFunc(unsigned char c, int x, int IMGUI_IMPL_API void ImGui_ImplGLUT_KeyboardUpFunc(unsigned char c, int x, int y); // ~ CharReleasedFunc IMGUI_IMPL_API void ImGui_ImplGLUT_SpecialFunc(int key, int x, int y); // ~ KeyPressedFunc IMGUI_IMPL_API void ImGui_ImplGLUT_SpecialUpFunc(int key, int x, int y); // ~ KeyReleasedFunc +IMGUI_EXPORT_END #endif // #ifndef IMGUI_DISABLE diff --git a/backends/imgui_impl_null.h b/backends/imgui_impl_null.h index b5cfb5a2c..0c27801c8 100644 --- a/backends/imgui_impl_null.h +++ b/backends/imgui_impl_null.h @@ -13,6 +13,7 @@ #include "imgui.h" // IMGUI_IMPL_API #ifndef IMGUI_DISABLE +IMGUI_EXPORT_BEGIN // Follow "Getting Started" link and check examples/ folder to learn about using backends! // Null = NullPlatform + NullRender @@ -30,5 +31,6 @@ IMGUI_IMPL_API bool ImGui_ImplNullRender_Init(); IMGUI_IMPL_API void ImGui_ImplNullRender_Shutdown(); IMGUI_IMPL_API void ImGui_ImplNullRender_NewFrame(); IMGUI_IMPL_API void ImGui_ImplNullRender_RenderDrawData(ImDrawData* draw_data); +IMGUI_EXPORT_END #endif // #ifndef IMGUI_DISABLE diff --git a/backends/imgui_impl_opengl2.cpp b/backends/imgui_impl_opengl2.cpp index 88eed8c5f..15f7ca085 100644 --- a/backends/imgui_impl_opengl2.cpp +++ b/backends/imgui_impl_opengl2.cpp @@ -56,7 +56,9 @@ #include "imgui.h" #ifndef IMGUI_DISABLE #include "imgui_impl_opengl2.h" +#ifndef IMGUI_CXX_MODULE #include // intptr_t +#endif // Clang/GCC warnings with -Weverything #if defined(__clang__) @@ -66,6 +68,7 @@ #endif // Include OpenGL header (without an OpenGL loader) requires a bit of fiddling +#ifndef IMGUI_CXX_MODULE #if defined(_WIN32) && !defined(APIENTRY) #define APIENTRY __stdcall // It is customary to use APIENTRY for OpenGL function pointer declarations on all platforms. Additionally, the Windows OpenGL header needs APIENTRY. #endif @@ -78,11 +81,14 @@ #else #include #endif +#endif // [Debugging] //#define IMGUI_IMPL_OPENGL_DEBUG #ifdef IMGUI_IMPL_OPENGL_DEBUG +#ifndef IMGUI_CXX_MODULE #include +#endif #define GL_CALL(_CALL) do { _CALL; GLenum gl_err = glGetError(); if (gl_err != 0) fprintf(stderr, "GL error 0x%x returned from '%s'.\n", gl_err, #_CALL); } while (0) // Call with error check #else #define GL_CALL(_CALL) _CALL // Call without error check diff --git a/backends/imgui_impl_opengl2.h b/backends/imgui_impl_opengl2.h index b9f7453f5..8870f843c 100644 --- a/backends/imgui_impl_opengl2.h +++ b/backends/imgui_impl_opengl2.h @@ -28,6 +28,7 @@ #include "imgui.h" // IMGUI_IMPL_API #ifndef IMGUI_DISABLE +IMGUI_EXPORT_BEGIN // Follow "Getting Started" link and check examples/ folder to learn about using backends! IMGUI_IMPL_API bool ImGui_ImplOpenGL2_Init(); IMGUI_IMPL_API void ImGui_ImplOpenGL2_Shutdown(); @@ -40,5 +41,6 @@ IMGUI_IMPL_API void ImGui_ImplOpenGL2_DestroyDeviceObjects(); // (Advanced) Use e.g. if you need to precisely control the timing of texture updates (e.g. for staged rendering), by setting ImDrawData::Textures = nullptr to handle this manually. IMGUI_IMPL_API void ImGui_ImplOpenGL2_UpdateTexture(ImTextureData* tex); +IMGUI_EXPORT_END #endif // #ifndef IMGUI_DISABLE diff --git a/backends/imgui_impl_opengl3.cpp b/backends/imgui_impl_opengl3.cpp index 73dc349d8..20595810f 100644 --- a/backends/imgui_impl_opengl3.cpp +++ b/backends/imgui_impl_opengl3.cpp @@ -133,11 +133,13 @@ #include "imgui.h" #ifndef IMGUI_DISABLE #include "imgui_impl_opengl3.h" +#ifndef IMGUI_CXX_MODULE #include #include // intptr_t #if defined(__APPLE__) #include #endif +#endif // Clang/GCC warnings with -Weverything #if defined(__clang__) @@ -158,6 +160,7 @@ #endif // GL includes +#ifndef IMGUI_CXX_MODULE #if defined(IMGUI_IMPL_OPENGL_ES2) #if (defined(__APPLE__) && (TARGET_OS_IOS || TARGET_OS_TV)) #include // Use GL ES 2 @@ -189,6 +192,7 @@ #define IMGUI_IMPL_OPENGL_LOADER_IMGL3W #include "imgui_impl_opengl3_loader.h" #endif +#endif // #ifndef IMGUI_CXX_MODULE // Vertex arrays are not supported on ES2/WebGL1 unless Emscripten which uses an extension #ifndef IMGUI_IMPL_OPENGL_ES2 @@ -231,7 +235,9 @@ // [Debugging] //#define IMGUI_IMPL_OPENGL_DEBUG #ifdef IMGUI_IMPL_OPENGL_DEBUG +#ifndef IMGUI_CXX_MODULE #include +#endif #define GL_CALL(_CALL) do { _CALL; GLenum gl_err = glGetError(); if (gl_err != 0) fprintf(stderr, "GL error 0x%x returned from '%s'.\n", gl_err, #_CALL); } while (0) // Call with error check #else #define GL_CALL(_CALL) _CALL // Call without error check diff --git a/backends/imgui_impl_opengl3.h b/backends/imgui_impl_opengl3.h index e1d999bd3..bc1981bfc 100644 --- a/backends/imgui_impl_opengl3.h +++ b/backends/imgui_impl_opengl3.h @@ -31,6 +31,7 @@ #include "imgui.h" // IMGUI_IMPL_API #ifndef IMGUI_DISABLE +IMGUI_EXPORT_BEGIN // Follow "Getting Started" link and check examples/ folder to learn about using backends! IMGUI_IMPL_API bool ImGui_ImplOpenGL3_Init(const char* glsl_version = nullptr); IMGUI_IMPL_API void ImGui_ImplOpenGL3_Shutdown(); @@ -53,7 +54,7 @@ IMGUI_IMPL_API void ImGui_ImplOpenGL3_UpdateTexture(ImTextureData* tex); && !defined(IMGUI_IMPL_OPENGL_ES3) // Try to detect GLES on matching platforms -#if defined(__APPLE__) +#if defined(__APPLE__) && !defined(IMGUI_CXX_MODULE) #include #endif #if (defined(__APPLE__) && (TARGET_OS_IOS || TARGET_OS_TV)) || (defined(__ANDROID__)) @@ -77,5 +78,6 @@ struct ImGui_ImplOpenGL3_RenderState unsigned int CurrentTexParameterFilter; // (GLuint) Used if UseTexParameterFilter == true }; IMGUI_IMPL_API ImGui_ImplOpenGL3_RenderState* ImGui_ImplOpenGL3_GetRenderState(); +IMGUI_EXPORT_END #endif // #ifndef IMGUI_DISABLE diff --git a/backends/imgui_impl_qnx.cpp b/backends/imgui_impl_qnx.cpp index 3730f54d2..09969f422 100644 --- a/backends/imgui_impl_qnx.cpp +++ b/backends/imgui_impl_qnx.cpp @@ -20,11 +20,13 @@ #ifndef IMGUI_DISABLE #include "imgui_impl_qnx.h" +#ifndef IMGUI_CXX_MODULE #include #include #include #include #include +#endif static unsigned int ImGui_ImplQNX_KeySymToUnicode(unsigned int keysym); diff --git a/backends/imgui_impl_qnx.h b/backends/imgui_impl_qnx.h index 7bd86f439..e006fcf5a 100644 --- a/backends/imgui_impl_qnx.h +++ b/backends/imgui_impl_qnx.h @@ -23,13 +23,17 @@ #include "imgui.h" // IMGUI_IMPL_API #ifndef IMGUI_DISABLE +#ifndef IMGUI_CXX_MODULE #include +#endif +IMGUI_EXPORT_BEGIN // The application owns the Screen context, window and event object. // Poll events with screen_get_event() and pass each non-NONE event to ProcessEvent(). IMGUI_IMPL_API bool ImGui_ImplQNX_Init(screen_context_t context, screen_window_t window); IMGUI_IMPL_API void ImGui_ImplQNX_Shutdown(); IMGUI_IMPL_API void ImGui_ImplQNX_NewFrame(); IMGUI_IMPL_API bool ImGui_ImplQNX_ProcessEvent(screen_event_t event); +IMGUI_EXPORT_END #endif // #ifndef IMGUI_DISABLE diff --git a/backends/imgui_impl_sdl2.cpp b/backends/imgui_impl_sdl2.cpp index a93bcc29e..f9e081ae7 100644 --- a/backends/imgui_impl_sdl2.cpp +++ b/backends/imgui_impl_sdl2.cpp @@ -118,6 +118,7 @@ #endif // SDL +#ifndef IMGUI_CXX_MODULE #include #include #include // for snprintf() @@ -127,6 +128,7 @@ #ifdef __EMSCRIPTEN__ #include #endif +#endif #undef Status // X11 headers are leaking this. #if SDL_VERSION_ATLEAST(2,0,4) && !defined(__EMSCRIPTEN__) && !defined(__ANDROID__) && !(defined(__APPLE__) && TARGET_OS_IOS) && !defined(__amigaos4__) @@ -142,12 +144,14 @@ #define SDL_HAS_METAL 0 #endif #define SDL_HAS_OPEN_URL SDL_VERSION_ATLEAST(2,0,14) +#ifndef IMGUI_CXX_MODULE #if SDL_HAS_VULKAN #include #endif #if SDL_HAS_METAL #include #endif +#endif // SDL Data struct ImGui_ImplSDL2_Data @@ -803,7 +807,7 @@ static void ImGui_ImplSDL2_CloseGamepads() bd->Gamepads.resize(0); } -void ImGui_ImplSDL2_SetGamepadMode(ImGui_ImplSDL2_GamepadMode mode, struct _SDL_GameController** manual_gamepads_array, int manual_gamepads_count) +void ImGui_ImplSDL2_SetGamepadMode(ImGui_ImplSDL2_GamepadMode mode, _SDL_GameController** manual_gamepads_array, int manual_gamepads_count) { ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData(); ImGui_ImplSDL2_CloseGamepads(); diff --git a/backends/imgui_impl_sdl2.h b/backends/imgui_impl_sdl2.h index 63ef7071a..b6ee4a140 100644 --- a/backends/imgui_impl_sdl2.h +++ b/backends/imgui_impl_sdl2.h @@ -22,11 +22,14 @@ #include "imgui.h" // IMGUI_IMPL_API #ifndef IMGUI_DISABLE +#ifndef IMGUI_CXX_MODULE struct SDL_Window; struct SDL_Renderer; struct _SDL_GameController; typedef union SDL_Event SDL_Event; +#endif +IMGUI_EXPORT_BEGIN // Follow "Getting Started" link and check examples/ folder to learn about using backends! IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForOpenGL(SDL_Window* window, void* sdl_gl_context); IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForVulkan(SDL_Window* window); @@ -45,7 +48,7 @@ IMGUI_IMPL_API float ImGui_ImplSDL2_GetContentScaleForDisplay(int display_ind // Gamepad selection automatically starts in AutoFirst mode, picking first available SDL_Gamepad. You may override this. // When using manual mode, caller is responsible for opening/closing gamepad. enum ImGui_ImplSDL2_GamepadMode { ImGui_ImplSDL2_GamepadMode_AutoFirst, ImGui_ImplSDL2_GamepadMode_AutoAll, ImGui_ImplSDL2_GamepadMode_Manual }; -IMGUI_IMPL_API void ImGui_ImplSDL2_SetGamepadMode(ImGui_ImplSDL2_GamepadMode mode, struct _SDL_GameController** manual_gamepads_array = nullptr, int manual_gamepads_count = -1); +IMGUI_IMPL_API void ImGui_ImplSDL2_SetGamepadMode(ImGui_ImplSDL2_GamepadMode mode, _SDL_GameController** manual_gamepads_array = nullptr, int manual_gamepads_count = -1); // (Advanced, for X11 users) Override Mouse Capture mode. Mouse capture allows receiving updated mouse position after clicking inside our window and dragging outside it. // Having this 'Enabled' is in theory always better. But, on X11 if you crash/break to debugger while capture is active you may temporarily lose access to your mouse. @@ -53,5 +56,6 @@ IMGUI_IMPL_API void ImGui_ImplSDL2_SetGamepadMode(ImGui_ImplSDL2_GamepadMode // But you may independently decide on X11, when a debugger is attached, to set this value to ImGui_ImplSDL2_MouseCaptureMode_Disabled. enum ImGui_ImplSDL2_MouseCaptureMode { ImGui_ImplSDL2_MouseCaptureMode_Enabled, ImGui_ImplSDL2_MouseCaptureMode_EnabledAfterDrag, ImGui_ImplSDL2_MouseCaptureMode_Disabled }; IMGUI_IMPL_API void ImGui_ImplSDL2_SetMouseCaptureMode(ImGui_ImplSDL2_MouseCaptureMode mode); +IMGUI_EXPORT_END #endif // #ifndef IMGUI_DISABLE diff --git a/backends/imgui_impl_sdl3.cpp b/backends/imgui_impl_sdl3.cpp index 05f6498f1..7ded18b80 100644 --- a/backends/imgui_impl_sdl3.cpp +++ b/backends/imgui_impl_sdl3.cpp @@ -77,6 +77,7 @@ #endif // SDL +#ifndef IMGUI_CXX_MODULE #include #include // for snprintf() #if defined(__APPLE__) @@ -88,6 +89,7 @@ #endif #include #endif +#endif #if !defined(__EMSCRIPTEN__) && !defined(__ANDROID__) && !(defined(__APPLE__) && TARGET_OS_IOS) && !defined(__amigaos4__) #define SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE 1 diff --git a/backends/imgui_impl_sdl3.h b/backends/imgui_impl_sdl3.h index 0720283c0..6af8185b8 100644 --- a/backends/imgui_impl_sdl3.h +++ b/backends/imgui_impl_sdl3.h @@ -22,11 +22,14 @@ #include "imgui.h" // IMGUI_IMPL_API #ifndef IMGUI_DISABLE +#ifndef IMGUI_CXX_MODULE struct SDL_Window; struct SDL_Renderer; struct SDL_Gamepad; typedef union SDL_Event SDL_Event; +#endif +IMGUI_EXPORT_BEGIN // Follow "Getting Started" link and check examples/ folder to learn about using backends! IMGUI_IMPL_API bool ImGui_ImplSDL3_InitForOpenGL(SDL_Window* window, void* sdl_gl_context); IMGUI_IMPL_API bool ImGui_ImplSDL3_InitForVulkan(SDL_Window* window); @@ -50,5 +53,6 @@ IMGUI_IMPL_API void ImGui_ImplSDL3_SetGamepadMode(ImGui_ImplSDL3_GamepadMode // But you may independently decide on X11, when a debugger is attached, to set this value to ImGui_ImplSDL3_MouseCaptureMode_Disabled. enum ImGui_ImplSDL3_MouseCaptureMode { ImGui_ImplSDL3_MouseCaptureMode_Enabled, ImGui_ImplSDL3_MouseCaptureMode_EnabledAfterDrag, ImGui_ImplSDL3_MouseCaptureMode_Disabled }; IMGUI_IMPL_API void ImGui_ImplSDL3_SetMouseCaptureMode(ImGui_ImplSDL3_MouseCaptureMode mode); +IMGUI_EXPORT_END #endif // #ifndef IMGUI_DISABLE diff --git a/backends/imgui_impl_sdlgpu3.h b/backends/imgui_impl_sdlgpu3.h index a517c43b1..63f80e0b3 100644 --- a/backends/imgui_impl_sdlgpu3.h +++ b/backends/imgui_impl_sdlgpu3.h @@ -25,8 +25,11 @@ #pragma once #include "imgui.h" // IMGUI_IMPL_API #ifndef IMGUI_DISABLE +#ifndef IMGUI_CXX_MODULE #include +#endif +IMGUI_EXPORT_BEGIN // Initialization data, for ImGui_ImplSDLGPU_Init() // - Remember to set ColorTargetFormat to the correct format. If you're rendering to the swapchain, call SDL_GetGPUSwapchainTextureFormat() to query the right value struct ImGui_ImplSDLGPU3_InitInfo @@ -60,5 +63,6 @@ struct ImGui_ImplSDLGPU3_RenderState SDL_GPUDevice* Device; }; IMGUI_IMPL_API ImGui_ImplSDLGPU3_RenderState* ImGui_ImplSDLGPU3_GetRenderState(); +IMGUI_EXPORT_END #endif // #ifndef IMGUI_DISABLE diff --git a/backends/imgui_impl_sdlrenderer2.cpp b/backends/imgui_impl_sdlrenderer2.cpp index d8dcfb154..53874c1b6 100644 --- a/backends/imgui_impl_sdlrenderer2.cpp +++ b/backends/imgui_impl_sdlrenderer2.cpp @@ -44,7 +44,9 @@ #include "imgui.h" #ifndef IMGUI_DISABLE #include "imgui_impl_sdlrenderer2.h" +#ifndef IMGUI_CXX_MODULE #include // intptr_t +#endif // Clang warnings with -Weverything #if defined(__clang__) @@ -55,8 +57,10 @@ #endif // SDL +#ifndef IMGUI_CXX_MODULE #include #include +#endif #if !SDL_VERSION_ATLEAST(2,0,17) #error This backend requires SDL 2.0.17+ because of SDL_RenderGeometry() function #endif diff --git a/backends/imgui_impl_sdlrenderer2.h b/backends/imgui_impl_sdlrenderer2.h index e16b8cae9..c5fe269c3 100644 --- a/backends/imgui_impl_sdlrenderer2.h +++ b/backends/imgui_impl_sdlrenderer2.h @@ -29,8 +29,11 @@ #ifndef IMGUI_DISABLE #include "imgui.h" // IMGUI_IMPL_API +#ifndef IMGUI_CXX_MODULE struct SDL_Renderer; +#endif +IMGUI_EXPORT_BEGIN // Follow "Getting Started" link and check examples/ folder to learn about using backends! IMGUI_IMPL_API bool ImGui_ImplSDLRenderer2_Init(SDL_Renderer* renderer); IMGUI_IMPL_API void ImGui_ImplSDLRenderer2_Shutdown(); @@ -52,5 +55,6 @@ struct ImGui_ImplSDLRenderer2_RenderState SDL_Renderer* Renderer; }; IMGUI_IMPL_API ImGui_ImplSDLRenderer2_RenderState* ImGui_ImplSDLRenderer2_GetRenderState(); +IMGUI_EXPORT_END #endif // #ifndef IMGUI_DISABLE diff --git a/backends/imgui_impl_sdlrenderer3.cpp b/backends/imgui_impl_sdlrenderer3.cpp index 6dd4c14fe..813a7d07b 100644 --- a/backends/imgui_impl_sdlrenderer3.cpp +++ b/backends/imgui_impl_sdlrenderer3.cpp @@ -41,7 +41,9 @@ #include "imgui.h" #ifndef IMGUI_DISABLE #include "imgui_impl_sdlrenderer3.h" +#ifndef IMGUI_CXX_MODULE #include // intptr_t +#endif // Clang warnings with -Weverything #if defined(__clang__) @@ -52,8 +54,10 @@ #endif // SDL +#ifndef IMGUI_CXX_MODULE #include #include +#endif #if !SDL_VERSION_ATLEAST(3,0,0) #error This backend requires SDL 3.0.0+ #endif diff --git a/backends/imgui_impl_sdlrenderer3.h b/backends/imgui_impl_sdlrenderer3.h index ee701be38..c45c80793 100644 --- a/backends/imgui_impl_sdlrenderer3.h +++ b/backends/imgui_impl_sdlrenderer3.h @@ -28,8 +28,11 @@ #ifndef IMGUI_DISABLE // For SDL_ScaleMode which cannot be forward declared. +#ifndef IMGUI_CXX_MODULE #include +#endif +IMGUI_EXPORT_BEGIN // Follow "Getting Started" link and check examples/ folder to learn about using backends! IMGUI_IMPL_API bool ImGui_ImplSDLRenderer3_Init(SDL_Renderer* renderer); IMGUI_IMPL_API void ImGui_ImplSDLRenderer3_Shutdown(); @@ -52,5 +55,6 @@ struct ImGui_ImplSDLRenderer3_RenderState SDL_ScaleMode CurrentScaleMode; // Current scale mode during render. Set to SDL_SCALEMODE_INVALID to use "SetSamplerFromTex" mode. }; IMGUI_IMPL_API ImGui_ImplSDLRenderer3_RenderState* ImGui_ImplSDLRenderer3_GetRenderState(); +IMGUI_EXPORT_END #endif // #ifndef IMGUI_DISABLE diff --git a/backends/imgui_impl_vulkan.cpp b/backends/imgui_impl_vulkan.cpp index 80b9d58ab..c3f01a0ff 100644 --- a/backends/imgui_impl_vulkan.cpp +++ b/backends/imgui_impl_vulkan.cpp @@ -118,7 +118,9 @@ #include "imgui.h" #ifndef IMGUI_DISABLE #include "imgui_impl_vulkan.h" +#ifndef IMGUI_CXX_MODULE #include +#endif #ifndef IM_MAX #define IM_MAX(A, B) (((A) >= (B)) ? (A) : (B)) #endif diff --git a/backends/imgui_impl_vulkan.h b/backends/imgui_impl_vulkan.h index 0f2da5e2d..1e9bd8c96 100644 --- a/backends/imgui_impl_vulkan.h +++ b/backends/imgui_impl_vulkan.h @@ -64,6 +64,7 @@ #endif // Vulkan includes +#ifndef IMGUI_CXX_MODULE #ifdef IMGUI_IMPL_VULKAN_USE_VOLK #ifdef IMGUI_IMPL_VULKAN_VOLK_FILENAME #include IMGUI_IMPL_VULKAN_VOLK_FILENAME @@ -73,6 +74,7 @@ #else #include #endif +#endif #if defined(VK_VERSION_1_3) || defined(VK_KHR_dynamic_rendering) #define IMGUI_IMPL_VULKAN_HAS_DYNAMIC_RENDERING #endif @@ -81,6 +83,7 @@ #define IMGUI_IMPL_VULKAN_MINIMUM_SAMPLED_IMAGE_POOL_SIZE (8) // Minimum per atlas #define IMGUI_IMPL_VULKAN_MINIMUM_SAMPLER_POOL_SIZE (2) // Minimum for linear + nearest +IMGUI_EXPORT_BEGIN // Specify settings to create pipeline and swapchain struct ImGui_ImplVulkan_PipelineInfo { @@ -273,6 +276,8 @@ struct ImGui_ImplVulkanH_Window } }; +IMGUI_EXPORT_END + #if defined(__clang__) #pragma clang diagnostic pop #endif diff --git a/backends/imgui_impl_wgpu.cpp b/backends/imgui_impl_wgpu.cpp index 002967b92..6ed052372 100644 --- a/backends/imgui_impl_wgpu.cpp +++ b/backends/imgui_impl_wgpu.cpp @@ -57,8 +57,10 @@ #ifndef IMGUI_DISABLE #include "imgui_impl_wgpu.h" +#ifndef IMGUI_CXX_MODULE #include #include +#endif // One of IMGUI_IMPL_WEBGPU_BACKEND_DAWN or IMGUI_IMPL_WEBGPU_BACKEND_WGPU must be provided. See imgui_impl_wgpu.h for more details. #if !defined(IMGUI_IMPL_WEBGPU_BACKEND_DAWN) && !defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU) && !defined(IMGUI_IMPL_WEBGPU_BACKEND_WGVK) @@ -69,7 +71,9 @@ #endif // Dear ImGui prototypes from imgui_internal.h +#ifndef IMGUI_CXX_MODULE extern ImGuiID ImHashData(const void* data_p, size_t data_size, ImU32 seed); +#endif #define MEMALIGN(_SIZE,_ALIGN) (((_SIZE) + ((_ALIGN) - 1)) & ~((_ALIGN) - 1)) // Memory align (copied from IM_ALIGN() macro). // WebGPU data @@ -1083,12 +1087,14 @@ void ImGui_ImplWGPU_DebugPrintAdapterInfo(const WGPUAdapter& adapter) #if defined(__APPLE__) // MacOS specific: is necessary to compile with "-x objective-c++" flags // (e.g. using cmake: set_source_files_properties(${IMGUI_DIR}/backends/imgui_impl_wgpu.cpp PROPERTIES COMPILE_FLAGS "-x objective-c++") ) +#ifndef IMGUI_CXX_MODULE #include #if TARGET_OS_OSX #include #include #endif #endif +#endif WGPUSurface ImGui_ImplWGPU_CreateWGPUSurfaceHelper(ImGui_ImplWGPU_CreateSurfaceInfo* info) { diff --git a/backends/imgui_impl_wgpu.h b/backends/imgui_impl_wgpu.h index 9f206db32..0706abec9 100644 --- a/backends/imgui_impl_wgpu.h +++ b/backends/imgui_impl_wgpu.h @@ -34,15 +34,20 @@ // Setup Emscripten default if not specified. #if defined(__EMSCRIPTEN__) && !defined(IMGUI_IMPL_WEBGPU_BACKEND_DAWN) && !defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU) +#ifndef IMGUI_CXX_MODULE #include +#endif #define IMGUI_IMPL_WEBGPU_BACKEND_DAWN #endif +#ifndef IMGUI_CXX_MODULE #include #if defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU) && !defined(__EMSCRIPTEN__) #include // WGPULogLevel #endif +#endif +IMGUI_EXPORT_BEGIN // Initialization data, for ImGui_ImplWGPU_Init() struct ImGui_ImplWGPU_InitInfo { @@ -115,5 +120,6 @@ struct ImGui_ImplWGPU_CreateSurfaceInfo }; WGPUSurface ImGui_ImplWGPU_CreateWGPUSurfaceHelper(ImGui_ImplWGPU_CreateSurfaceInfo* info); #endif // #ifndef __EMSCRIPTEN__ +IMGUI_EXPORT_END #endif // #ifndef IMGUI_DISABLE diff --git a/backends/imgui_impl_win32.cpp b/backends/imgui_impl_win32.cpp index 787329bf6..0c2098688 100644 --- a/backends/imgui_impl_win32.cpp +++ b/backends/imgui_impl_win32.cpp @@ -86,6 +86,7 @@ #include "imgui.h" #ifndef IMGUI_DISABLE #include "imgui_impl_win32.h" +#ifndef IMGUI_CXX_MODULE #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN #endif @@ -93,10 +94,13 @@ #include // GET_X_LPARAM(), GET_Y_LPARAM() #include #include +#endif // Using XInput for gamepad (will load DLL dynamically) #ifndef IMGUI_IMPL_WIN32_DISABLE_GAMEPAD +#ifndef IMGUI_CXX_MODULE #include +#endif typedef DWORD(WINAPI* PFN_XInputGetCapabilities)(DWORD, DWORD, XINPUT_CAPABILITIES*); typedef DWORD(WINAPI* PFN_XInputGetState)(DWORD, XINPUT_STATE*); #endif diff --git a/backends/imgui_impl_win32.h b/backends/imgui_impl_win32.h index d2a960059..72ca52871 100644 --- a/backends/imgui_impl_win32.h +++ b/backends/imgui_impl_win32.h @@ -20,6 +20,7 @@ #include "imgui.h" // IMGUI_IMPL_API #ifndef IMGUI_DISABLE +IMGUI_EXPORT_BEGIN // Follow "Getting Started" link and check examples/ folder to learn about using backends! IMGUI_IMPL_API bool ImGui_ImplWin32_Init(void* hwnd); IMGUI_IMPL_API bool ImGui_ImplWin32_InitForOpenGL(void* hwnd); @@ -34,6 +35,9 @@ IMGUI_IMPL_API void ImGui_ImplWin32_NewFrame(); #if 0 extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); #endif +#ifdef IMGUI_CXX_MODULE // (C++20 module: exported instead, as a forward declaration in your code wouldn't be attached to the module) +IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); +#endif // DPI-related helpers (optional) // - Use to enable DPI awareness without having to create an application manifest. @@ -49,5 +53,6 @@ IMGUI_IMPL_API float ImGui_ImplWin32_GetDpiScaleForMonitor(void* monitor); // // - Use to enable alpha compositing transparency with the desktop. // - Use together with e.g. clearing your framebuffer with zero-alpha. IMGUI_IMPL_API void ImGui_ImplWin32_EnableAlphaCompositing(void* hwnd); // HWND hwnd +IMGUI_EXPORT_END #endif // #ifndef IMGUI_DISABLE