|
117 | 117 | #define GLFW_EXPOSE_NATIVE_COCOA |
118 | 118 | #endif |
119 | 119 | #include <GLFW/glfw3native.h> |
| 120 | +#ifdef IMGUI_IMPL_WEBGPU_BACKEND_WGPU |
| 121 | +#include <Foundation/Foundation.h> |
| 122 | +#include <QuartzCore/CAMetalLayer.h> |
| 123 | +#endif |
120 | 124 | #elif !defined(__EMSCRIPTEN__) |
121 | 125 | #ifndef GLFW_EXPOSE_NATIVE_X11 // for glfwGetX11Window() on Freedesktop (Linux, BSD, etc.) |
122 | 126 | #define GLFW_EXPOSE_NATIVE_X11 |
@@ -1049,97 +1053,77 @@ void ImGui_ImplGlfw_InstallEmscriptenCallbacks(GLFWwindow* window, const char* c |
1049 | 1053 | } |
1050 | 1054 | #endif // #ifdef EMSCRIPTEN_USE_PORT_CONTRIB_GLFW3 |
1051 | 1055 |
|
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 |
1053 | 1057 | // At current date (jun/2025) there is no "official" support in GLFW to create a surface for WebGPU backend |
1054 | 1058 | // 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 |
1061 | 1061 | // (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) |
1068 | 1064 | { |
1069 | 1065 | WGPUSurfaceDescriptor surfaceDescriptor = {}; |
1070 | | - WGPUChainedStruct chainedStruct = {}; |
1071 | | - |
| 1066 | + WGPUChainedStruct chainedStruct = {}; |
1072 | 1067 | WGPUSurface surface = {}; |
1073 | 1068 |
|
1074 | 1069 | #if defined(GLFW_EXPOSE_NATIVE_COCOA) |
1075 | 1070 | { |
1076 | 1071 | id metal_layer = NULL; |
1077 | | - NSWindow *ns_window = glfwGetCocoaWindow(window); |
| 1072 | + NSWindow* ns_window = glfwGetCocoaWindow(window); |
1078 | 1073 | [ns_window.contentView setWantsLayer:YES]; |
1079 | 1074 | metal_layer = [CAMetalLayer layer]; |
1080 | 1075 | [ns_window.contentView setLayer:metal_layer]; |
1081 | | - |
1082 | 1076 | chainedStruct.sType = WGPUSType_SurfaceSourceMetalLayer; |
1083 | | - |
1084 | 1077 | WGPUSurfaceSourceMetalLayer surfaceMetal = {}; |
1085 | 1078 | surfaceMetal.chain = chainedStruct; |
1086 | 1079 | surfaceMetal.layer = metal_layer; |
1087 | | - |
1088 | 1080 | surfaceDescriptor.nextInChain = &surfaceMetal.chain; |
1089 | 1081 | surface = wgpuInstanceCreateSurface(instance, &surfaceDescriptor); |
1090 | 1082 | } |
1091 | 1083 | #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(); |
1094 | 1087 | Window x11_window = glfwGetX11Window(window); |
1095 | | - |
1096 | 1088 | chainedStruct.sType = WGPUSType_SurfaceSourceXlibWindow; |
1097 | | - |
1098 | 1089 | WGPUSurfaceSourceXlibWindow surfaceXlib = {}; |
1099 | | - surfaceXlib.chain = chainedStruct; |
| 1090 | + surfaceXlib.chain = chainedStruct; |
1100 | 1091 | surfaceXlib.display = x11_display; |
1101 | | - surfaceXlib.window = x11_window; |
1102 | | - |
| 1092 | + surfaceXlib.window = x11_window; |
1103 | 1093 | surfaceDescriptor.nextInChain = &surfaceXlib.chain; |
1104 | 1094 | surface = wgpuInstanceCreateSurface(instance, &surfaceDescriptor); |
1105 | 1095 | } |
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); |
1110 | 1100 | chainedStruct.sType = WGPUSType_SurfaceSourceWaylandSurface; |
1111 | | - |
1112 | 1101 | WGPUSurfaceSourceWaylandSurface surfaceWayland = {}; |
1113 | | - surfaceWayland.chain = chainedStruct; |
| 1102 | + surfaceWayland.chain = chainedStruct; |
1114 | 1103 | surfaceWayland.display = wayland_display; |
1115 | 1104 | surfaceWayland.surface = wayland_surface; |
1116 | | - |
1117 | 1105 | surfaceDescriptor.nextInChain = &surfaceWayland.chain; |
1118 | 1106 | surface = wgpuInstanceCreateSurface(instance, &surfaceDescriptor); |
1119 | 1107 | } |
1120 | 1108 | #elif defined(GLFW_EXPOSE_NATIVE_WIN32) |
1121 | 1109 | { |
1122 | 1110 | HWND hwnd = glfwGetWin32Window(window); |
1123 | | - HINSTANCE hinstance = GetModuleHandle(NULL); |
1124 | | - |
| 1111 | + HINSTANCE hinstance = ::GetModuleHandle(NULL); |
1125 | 1112 | chainedStruct.sType = WGPUSType_SurfaceSourceWindowsHWND; |
1126 | | - |
1127 | 1113 | WGPUSurfaceSourceWindowsHWND surfaceHWND = {}; |
1128 | | - surfaceHWND.chain = chainedStruct; |
| 1114 | + surfaceHWND.chain = chainedStruct; |
1129 | 1115 | surfaceHWND.hinstance = hinstance; |
1130 | | - surfaceHWND.hwnd = hwnd; |
1131 | | - |
| 1116 | + surfaceHWND.hwnd = hwnd; |
1132 | 1117 | surfaceDescriptor.nextInChain = &surfaceHWND.chain; |
1133 | 1118 | surface = wgpuInstanceCreateSurface(instance, &surfaceDescriptor); |
1134 | 1119 | } |
1135 | 1120 | #elif |
1136 | | -#error "Unsupported GLFW/WebGPU native platform" |
| 1121 | +#error "Unsupported GLFW+WebGPU native platform" |
1137 | 1122 | #endif |
1138 | 1123 | return surface; |
1139 | 1124 | } |
1140 | 1125 | #endif // defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU) && !defined(__EMSCRIPTEN__) |
1141 | 1126 |
|
1142 | | - |
1143 | 1127 | //----------------------------------------------------------------------------- |
1144 | 1128 |
|
1145 | 1129 | #if defined(__clang__) |
|
0 commit comments