Skip to content

Commit 4deba36

Browse files
committed
Misc amends (8381)
1 parent 46ca8bc commit 4deba36

File tree

11 files changed

+364
-378
lines changed

11 files changed

+364
-378
lines changed

backends/imgui_impl_glfw.cpp

Lines changed: 25 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@
117117
#define GLFW_EXPOSE_NATIVE_COCOA
118118
#endif
119119
#include <GLFW/glfw3native.h>
120+
#ifdef IMGUI_IMPL_WEBGPU_BACKEND_WGPU
121+
#include <Foundation/Foundation.h>
122+
#include <QuartzCore/CAMetalLayer.h>
123+
#endif
120124
#elif !defined(__EMSCRIPTEN__)
121125
#ifndef GLFW_EXPOSE_NATIVE_X11 // for glfwGetX11Window() on Freedesktop (Linux, BSD, etc.)
122126
#define GLFW_EXPOSE_NATIVE_X11
@@ -1049,97 +1053,77 @@ void ImGui_ImplGlfw_InstallEmscriptenCallbacks(GLFWwindow* window, const char* c
10491053
}
10501054
#endif // #ifdef EMSCRIPTEN_USE_PORT_CONTRIB_GLFW3
10511055

1052-
// GLFW helper to create a WebGPU surface, used only in WGPU-Native, DAWN-Native already has a built-in function
1056+
// GLFW helper to create a WebGPU surface, used only in WGPU-Native. DAWN-Native already has a built-in function
10531057
// At current date (jun/2025) there is no "official" support in GLFW to create a surface for WebGPU backend
10541058
// This stub uses "low level" GLFW calls to acquire information from a specific Window Manager.
1055-
// Currently supported platforms: Windows / Linux (X11 and Wayland) / MacOS
1056-
// Not necessary/available with EMSCRIPTEN
1057-
#if defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU) && !defined(__EMSCRIPTEN__)
1058-
// GLFW native necessary to get information about current platform / Window Manager
1059-
#include <GLFW/glfw3native.h>
1060-
// MacOS specific: is necessary to compile with "-x objective-c++" flags
1059+
// Currently supported platforms: Windows / Linux (X11 and Wayland) / MacOS. Not necessary/available with EMSCRIPTEN
1060+
// MacOS specific: need to compile with "-x objective-c++" flags
10611061
// (e.g. using cmake: set_source_files_properties(${IMGUI_DIR}/backends/imgui_impl_glfw.cpp PROPERTIES COMPILE_FLAGS "-x objective-c++") )
1062-
#if defined(GLFW_EXPOSE_NATIVE_COCOA)
1063-
#include <Foundation/Foundation.h>
1064-
#include <QuartzCore/CAMetalLayer.h>
1065-
#endif
1066-
1067-
WGPUSurface ImGui_ImplGLFW_CreateWGPUSurface_Helper(WGPUInstance instance, GLFWwindow* window)
1062+
#if defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU) && !defined(__EMSCRIPTEN__)
1063+
WGPUSurface ImGui_ImplGLFW_CreateWGPUSurface(WGPUInstance instance, GLFWwindow* window)
10681064
{
10691065
WGPUSurfaceDescriptor surfaceDescriptor = {};
1070-
WGPUChainedStruct chainedStruct = {};
1071-
1066+
WGPUChainedStruct chainedStruct = {};
10721067
WGPUSurface surface = {};
10731068

10741069
#if defined(GLFW_EXPOSE_NATIVE_COCOA)
10751070
{
10761071
id metal_layer = NULL;
1077-
NSWindow *ns_window = glfwGetCocoaWindow(window);
1072+
NSWindow* ns_window = glfwGetCocoaWindow(window);
10781073
[ns_window.contentView setWantsLayer:YES];
10791074
metal_layer = [CAMetalLayer layer];
10801075
[ns_window.contentView setLayer:metal_layer];
1081-
10821076
chainedStruct.sType = WGPUSType_SurfaceSourceMetalLayer;
1083-
10841077
WGPUSurfaceSourceMetalLayer surfaceMetal = {};
10851078
surfaceMetal.chain = chainedStruct;
10861079
surfaceMetal.layer = metal_layer;
1087-
10881080
surfaceDescriptor.nextInChain = &surfaceMetal.chain;
10891081
surface = wgpuInstanceCreateSurface(instance, &surfaceDescriptor);
10901082
}
10911083
#elif defined(GLFW_EXPOSE_NATIVE_WAYLAND) && defined(GLFW_EXPOSE_NATIVE_X11)
1092-
if (glfwGetPlatform() == GLFW_PLATFORM_X11) {
1093-
Display *x11_display = glfwGetX11Display();
1084+
if (glfwGetPlatform() == GLFW_PLATFORM_X11)
1085+
{
1086+
Display* x11_display = glfwGetX11Display();
10941087
Window x11_window = glfwGetX11Window(window);
1095-
10961088
chainedStruct.sType = WGPUSType_SurfaceSourceXlibWindow;
1097-
10981089
WGPUSurfaceSourceXlibWindow surfaceXlib = {};
1099-
surfaceXlib.chain = chainedStruct;
1090+
surfaceXlib.chain = chainedStruct;
11001091
surfaceXlib.display = x11_display;
1101-
surfaceXlib.window = x11_window;
1102-
1092+
surfaceXlib.window = x11_window;
11031093
surfaceDescriptor.nextInChain = &surfaceXlib.chain;
11041094
surface = wgpuInstanceCreateSurface(instance, &surfaceDescriptor);
11051095
}
1106-
if (glfwGetPlatform() == GLFW_PLATFORM_WAYLAND) {
1107-
struct wl_display *wayland_display = glfwGetWaylandDisplay();
1108-
struct wl_surface *wayland_surface = glfwGetWaylandWindow(window);
1109-
1096+
if (glfwGetPlatform() == GLFW_PLATFORM_WAYLAND)
1097+
{
1098+
struct wl_display* wayland_display = glfwGetWaylandDisplay();
1099+
struct wl_surface* wayland_surface = glfwGetWaylandWindow(window);
11101100
chainedStruct.sType = WGPUSType_SurfaceSourceWaylandSurface;
1111-
11121101
WGPUSurfaceSourceWaylandSurface surfaceWayland = {};
1113-
surfaceWayland.chain = chainedStruct;
1102+
surfaceWayland.chain = chainedStruct;
11141103
surfaceWayland.display = wayland_display;
11151104
surfaceWayland.surface = wayland_surface;
1116-
11171105
surfaceDescriptor.nextInChain = &surfaceWayland.chain;
11181106
surface = wgpuInstanceCreateSurface(instance, &surfaceDescriptor);
11191107
}
11201108
#elif defined(GLFW_EXPOSE_NATIVE_WIN32)
11211109
{
11221110
HWND hwnd = glfwGetWin32Window(window);
1123-
HINSTANCE hinstance = GetModuleHandle(NULL);
1124-
1111+
HINSTANCE hinstance = ::GetModuleHandle(NULL);
11251112
chainedStruct.sType = WGPUSType_SurfaceSourceWindowsHWND;
1126-
11271113
WGPUSurfaceSourceWindowsHWND surfaceHWND = {};
1128-
surfaceHWND.chain = chainedStruct;
1114+
surfaceHWND.chain = chainedStruct;
11291115
surfaceHWND.hinstance = hinstance;
1130-
surfaceHWND.hwnd = hwnd;
1131-
1116+
surfaceHWND.hwnd = hwnd;
11321117
surfaceDescriptor.nextInChain = &surfaceHWND.chain;
11331118
surface = wgpuInstanceCreateSurface(instance, &surfaceDescriptor);
11341119
}
11351120
#elif
1136-
#error "Unsupported GLFW/WebGPU native platform"
1121+
#error "Unsupported GLFW+WebGPU native platform"
11371122
#endif
11381123
return surface;
11391124
}
11401125
#endif // defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU) && !defined(__EMSCRIPTEN__)
11411126

1142-
11431127
//-----------------------------------------------------------------------------
11441128

11451129
#if defined(__clang__)

backends/imgui_impl_glfw.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ IMGUI_IMPL_API void ImGui_ImplGlfw_Sleep(int milliseconds);
6666
IMGUI_IMPL_API float ImGui_ImplGlfw_GetContentScaleForWindow(GLFWwindow* window);
6767
IMGUI_IMPL_API float ImGui_ImplGlfw_GetContentScaleForMonitor(GLFWmonitor* monitor);
6868

69-
// GLFW helper to create a WebGPU surface for Native/Desktop applications: used only in WGPU-Native, DAWN-Native already has a built-in function
69+
// GLFW helpers for native/desktop WebGPU applications (used only in WGPU-Native, DAWN-Native already has a built-in function)
7070
#if defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU) && !defined(__EMSCRIPTEN__)
7171
#include <webgpu/webgpu.h>
72-
WGPUSurface ImGui_ImplGLFW_CreateWGPUSurface_Helper(WGPUInstance instance, GLFWwindow* window);
72+
WGPUSurface ImGui_ImplGLFW_CreateWGPUSurface(WGPUInstance instance, GLFWwindow* window);
7373
#endif
7474

7575

backends/imgui_impl_sdl2.cpp

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -912,74 +912,66 @@ void ImGui_ImplSDL2_NewFrame()
912912
#include <QuartzCore/CAMetalLayer.h>
913913
#endif
914914

915-
WGPUSurface ImGui_ImplSDL2_CreateWGPUSurface_Helper(WGPUInstance instance, SDL_Window* window)
915+
WGPUSurface ImGui_ImplSDL2_CreateWGPUSurface(WGPUInstance instance, SDL_Window* window)
916916
{
917917
WGPUSurfaceDescriptor surfaceDescriptor = {};
918-
WGPUChainedStruct chainedStruct = {};
918+
WGPUChainedStruct chainedStruct = {};
919+
WGPUSurface surface = {};
920+
919921
SDL_SysWMinfo sysWMInfo;
920922
SDL_VERSION(&sysWMInfo.version);
921923
SDL_GetWindowWMInfo(window, &sysWMInfo);
922924

923-
WGPUSurface surface = {};
924-
925925
#if defined(SDL_VIDEO_DRIVER_WAYLAND) || defined(SDL_VIDEO_DRIVER_X11)
926-
const char *vidDrv = SDL_GetHint(SDL_HINT_VIDEODRIVER);
927-
if(!vidDrv) return NULL;
928-
929-
if(tolower(vidDrv[0])=='w' && tolower(vidDrv[1])=='a' && tolower(vidDrv[2])=='y' &&
930-
tolower(vidDrv[3])=='l' && tolower(vidDrv[4])=='a' && tolower(vidDrv[5])=='n' && tolower(vidDrv[6])=='d') { // wayland
926+
const char* video_driver = SDL_GetHint(SDL_HINT_VIDEODRIVER);
927+
if (!video_driver)
928+
return nullptr;
931929

930+
if (strncmp(video_driver, "wayland", 7) == 0)
931+
{
932932
chainedStruct.sType = WGPUSType_SurfaceSourceWaylandSurface;
933-
934933
WGPUSurfaceSourceWaylandSurface surfaceWayland = {};
935-
surfaceWayland.chain = chainedStruct;
934+
surfaceWayland.chain = chainedStruct;
936935
surfaceWayland.display = sysWMInfo.info.wl.display;
937936
surfaceWayland.surface = sysWMInfo.info.wl.surface;
938-
939937
surfaceDescriptor.nextInChain = &surfaceWayland.chain;
940938
surface = wgpuInstanceCreateSurface(instance, &surfaceDescriptor);
941-
942-
} else { // x11
939+
}
940+
else
941+
{
943942
chainedStruct.sType = WGPUSType_SurfaceSourceXlibWindow;
944-
945943
WGPUSurfaceSourceXlibWindow surfaceXlib = {};
946-
surfaceXlib.chain = chainedStruct;
944+
surfaceXlib.chain = chainedStruct;
947945
surfaceXlib.display = sysWMInfo.info.x11.display;
948-
surfaceXlib.window = sysWMInfo.info.x11.window;
949-
946+
surfaceXlib.window = sysWMInfo.info.x11.window;
950947
surfaceDescriptor.nextInChain = &surfaceXlib.chain;
951948
surface = wgpuInstanceCreateSurface(instance, &surfaceDescriptor);
952949
}
953950
#elif defined(SDL_VIDEO_DRIVER_WINDOWS)
954951
{
955952
chainedStruct.sType = WGPUSType_SurfaceSourceWindowsHWND;
956-
957953
WGPUSurfaceSourceWindowsHWND surfaceHWND = {};
958-
surfaceHWND.chain = chainedStruct;
954+
surfaceHWND.chain = chainedStruct;
959955
surfaceHWND.hinstance = sysWMInfo.info.win.hinstance;
960-
surfaceHWND.hwnd = sysWMInfo.info.win.window;
961-
956+
surfaceHWND.hwnd = sysWMInfo.info.win.window;
962957
surfaceDescriptor.nextInChain = &surfaceHWND.chain;
963958
surface = wgpuInstanceCreateSurface(instance, &surfaceDescriptor);
964959
}
965960
#elif defined(SDL_VIDEO_DRIVER_COCOA)
966961
{
967962
id metal_layer = [CAMetalLayer layer];
968-
NSWindow *ns_window = sysWMInfo.info.cocoa.window;
963+
NSWindow* ns_window = sysWMInfo.info.cocoa.window;
969964
[ns_window.contentView setWantsLayer:YES];
970965
[ns_window.contentView setLayer:metal_layer];
971-
972966
chainedStruct.sType = WGPUSType_SurfaceSourceMetalLayer;
973-
974967
WGPUSurfaceSourceMetalLayer surfaceMetal = {};
975968
surfaceMetal.chain = chainedStruct;
976969
surfaceMetal.layer = metal_layer;
977-
978970
surfaceDescriptor.nextInChain = &surfaceMetal.chain;
979971
surface = wgpuInstanceCreateSurface(instance, &surfaceDescriptor);
980972
}
981973
#else
982-
#error "Unsupported SDL2/WebGPU Backend"
974+
#error "Unsupported SDL2+WebGPU Backend"
983975
#endif
984976
return surface;
985977
}

backends/imgui_impl_sdl2.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ IMGUI_IMPL_API float ImGui_ImplSDL2_GetContentScaleForDisplay(int display_ind
4747
enum ImGui_ImplSDL2_GamepadMode { ImGui_ImplSDL2_GamepadMode_AutoFirst, ImGui_ImplSDL2_GamepadMode_AutoAll, ImGui_ImplSDL2_GamepadMode_Manual };
4848
IMGUI_IMPL_API void ImGui_ImplSDL2_SetGamepadMode(ImGui_ImplSDL2_GamepadMode mode, struct _SDL_GameController** manual_gamepads_array = nullptr, int manual_gamepads_count = -1);
4949

50-
// SDL2 helper to create a WebGPU surface (exclusively!) for Native/Desktop applications: available only together with WebGPU/WGPU backend
50+
// SDL2 helpers for native/desktop WebGPU applications.
5151
#if defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU) || defined(IMGUI_IMPL_WEBGPU_BACKEND_DAWN) && !defined(__EMSCRIPTEN__)
5252
#include <webgpu/webgpu.h>
53-
WGPUSurface ImGui_ImplSDL2_CreateWGPUSurface_Helper(WGPUInstance instance, SDL_Window* window);
53+
WGPUSurface ImGui_ImplSDL2_CreateWGPUSurface(WGPUInstance instance, SDL_Window* window);
5454
#endif
5555

5656
#endif // #ifndef IMGUI_DISABLE

backends/imgui_impl_sdl3.cpp

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -854,71 +854,69 @@ void ImGui_ImplSDL3_NewFrame()
854854
# include <windows.h>
855855
#endif
856856

857-
WGPUSurface ImGui_ImplSDL3_CreateWGPUSurface_Helper(WGPUInstance instance, SDL_Window* window) {
857+
WGPUSurface ImGui_ImplSDL3_CreateWGPUSurface(WGPUInstance instance, SDL_Window* window)
858+
{
858859
SDL_PropertiesID propertiesID = SDL_GetWindowProperties(window);
859860
WGPUSurfaceDescriptor surfaceDescriptor = {};
860-
861861
WGPUSurface surface = {};
862862

863863
#if defined(SDL_PLATFORM_MACOS)
864864
{
865865
id metal_layer = NULL;
866-
NSWindow *ns_window = (__bridge NSWindow *)SDL_GetPointerProperty(propertiesID, SDL_PROP_WINDOW_COCOA_WINDOW_POINTER, NULL);
866+
NSWindow* ns_window = (__bridge NSWindow*)SDL_GetPointerProperty(propertiesID, SDL_PROP_WINDOW_COCOA_WINDOW_POINTER, NULL);
867867
if (!ns_window) return NULL;
868868
[ns_window.contentView setWantsLayer : YES];
869869
metal_layer = [CAMetalLayer layer];
870870
[ns_window.contentView setLayer : metal_layer];
871-
872871
WGPUSurfaceSourceMetalLayer surfaceMetal = {};
873872
surfaceMetal.chain.sType = WGPUSType_SurfaceSourceMetalLayer;
874873
surfaceMetal.layer = metal_layer;
875-
876874
surfaceDescriptor.nextInChain = &surfaceMetal.chain;
877875
surface = wgpuInstanceCreateSurface(instance, &surfaceDescriptor);
878876
}
879877
#elif defined(SDL_PLATFORM_LINUX)
880-
if (!SDL_strcmp(SDL_GetCurrentVideoDriver(), "wayland")) {
881-
void *w_display = SDL_GetPointerProperty(propertiesID, SDL_PROP_WINDOW_WAYLAND_DISPLAY_POINTER, NULL);
882-
void *w_surface = SDL_GetPointerProperty(propertiesID, SDL_PROP_WINDOW_WAYLAND_SURFACE_POINTER, NULL);
883-
if (!w_display || !w_surface) return NULL;
884-
878+
if (!SDL_strcmp(SDL_GetCurrentVideoDriver(), "wayland"))
879+
{
880+
void* w_display = SDL_GetPointerProperty(propertiesID, SDL_PROP_WINDOW_WAYLAND_DISPLAY_POINTER, NULL);
881+
void* w_surface = SDL_GetPointerProperty(propertiesID, SDL_PROP_WINDOW_WAYLAND_SURFACE_POINTER, NULL);
882+
if (!w_display || !w_surface)
883+
return NULL;
885884
WGPUSurfaceSourceWaylandSurface surfaceWayland = {};
886885
surfaceWayland.chain.sType = WGPUSType_SurfaceSourceWaylandSurface;
887886
surfaceWayland.display = w_display;
888887
surfaceWayland.surface = w_surface;
889-
890888
surfaceDescriptor.nextInChain = &surfaceWayland.chain;
891889
surface = wgpuInstanceCreateSurface(instance, &surfaceDescriptor);
892-
} else if (!SDL_strcmp(SDL_GetCurrentVideoDriver(), "x11")) {
893-
void *x_display = SDL_GetPointerProperty(propertiesID, SDL_PROP_WINDOW_X11_DISPLAY_POINTER, NULL);
890+
}
891+
else if (!SDL_strcmp(SDL_GetCurrentVideoDriver(), "x11"))
892+
{
893+
void* x_display = SDL_GetPointerProperty(propertiesID, SDL_PROP_WINDOW_X11_DISPLAY_POINTER, NULL);
894894
uint64_t x_window = SDL_GetNumberProperty(propertiesID, SDL_PROP_WINDOW_X11_WINDOW_NUMBER, 0);
895-
if (!x_display || !x_window) return NULL;
896-
895+
if (!x_display || !x_window)
896+
return NULL;
897897
WGPUSurfaceSourceXlibWindow surfaceXlib = {};
898898
surfaceXlib.chain.sType = WGPUSType_SurfaceSourceXlibWindow;
899899
surfaceXlib.display = x_display;
900-
surfaceXlib.window = x_window;
901-
900+
surfaceXlib.window = x_window;
902901
surfaceDescriptor.nextInChain = &surfaceXlib.chain;
903902
surface = wgpuInstanceCreateSurface(instance, &surfaceDescriptor);
904903
}
905904

906905
#elif defined(SDL_PLATFORM_WIN32)
907906
{
908907
HWND hwnd = (HWND)SDL_GetPointerProperty(propertiesID, SDL_PROP_WINDOW_WIN32_HWND_POINTER, NULL);
909-
if (!hwnd) return NULL;
910-
HINSTANCE hinstance = GetModuleHandle(NULL);
911-
908+
if (!hwnd)
909+
return NULL;
910+
HINSTANCE hinstance = ::GetModuleHandle(NULL);
912911
WGPUSurfaceSourceWindowsHWND surfaceHWND = {};
913912
surfaceHWND.chain.sType = WGPUSType_SurfaceSourceWindowsHWND;
914913
surfaceHWND.hinstance = hinstance;
915914
surfaceHWND.hwnd = hwnd;
916-
917915
surfaceDescriptor.nextInChain = &surfaceHWND.chain;
918916
surface = wgpuInstanceCreateSurface(instance, &surfaceDescriptor);
919917
}
920918
#else
921-
#error "Unsupported SDL3/WebGPU Backend"
919+
#error "Unsupported SDL3+WebGPU Backend"
922920
#endif
923921
return surface;
924922
}

backends/imgui_impl_sdl3.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ IMGUI_IMPL_API bool ImGui_ImplSDL3_ProcessEvent(const SDL_Event* event);
4444
enum ImGui_ImplSDL3_GamepadMode { ImGui_ImplSDL3_GamepadMode_AutoFirst, ImGui_ImplSDL3_GamepadMode_AutoAll, ImGui_ImplSDL3_GamepadMode_Manual };
4545
IMGUI_IMPL_API void ImGui_ImplSDL3_SetGamepadMode(ImGui_ImplSDL3_GamepadMode mode, SDL_Gamepad** manual_gamepads_array = nullptr, int manual_gamepads_count = -1);
4646

47-
// SDL3 helper to create a WebGPU surface for Native/Desktop applications: available only with WebGPU/WGPU backend
47+
// SDL2 helpers for native/desktop WebGPU applications.
4848
#if defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU) || defined(IMGUI_IMPL_WEBGPU_BACKEND_DAWN) && !defined(__EMSCRIPTEN__)
4949
#include <webgpu/webgpu.h>
50-
WGPUSurface ImGui_ImplSDL3_CreateWGPUSurface_Helper(WGPUInstance instance, SDL_Window* window);
50+
WGPUSurface ImGui_ImplSDL3_CreateWGPUSurface(WGPUInstance instance, SDL_Window* window);
5151
#endif
5252

5353
#endif // #ifndef IMGUI_DISABLE

0 commit comments

Comments
 (0)