From 8b69cc2ae2fdb728a2be3826f8027c3326e4d87d Mon Sep 17 00:00:00 2001 From: Aaron C Gaudette Date: Thu, 12 Sep 2024 17:09:26 -0700 Subject: [PATCH] Guard API changes with backend define --- glfw3webgpu.c | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/glfw3webgpu.c b/glfw3webgpu.c index 9ff18f7..a0dfd0f 100644 --- a/glfw3webgpu.c +++ b/glfw3webgpu.c @@ -70,9 +70,14 @@ WGPUSurface glfwGetWGPUSurface(WGPUInstance instance, GLFWwindow* window) { Display* x11_display = glfwGetX11Display(); Window x11_window = glfwGetX11Window(window); +#ifdef WEBGPU_BACKEND_DAWN WGPUSurfaceSourceXlibWindow fromXlibWindow; - fromXlibWindow.chain.next = NULL; fromXlibWindow.chain.sType = WGPUSType_SurfaceSourceXlibWindow; +#else + WGPUSurfaceDescriptorFromXlibWindow fromXlibWindow; + fromXlibWindow.chain.sType = WGPUSType_SurfaceDescriptorFromXlibWindow; +#endif + fromXlibWindow.chain.next = NULL; fromXlibWindow.display = x11_display; fromXlibWindow.window = x11_window; @@ -89,9 +94,14 @@ WGPUSurface glfwGetWGPUSurface(WGPUInstance instance, GLFWwindow* window) { struct wl_display* wayland_display = glfwGetWaylandDisplay(); struct wl_surface* wayland_surface = glfwGetWaylandWindow(window); +#ifdef WEBGPU_BACKEND_DAWN WGPUSurfaceSourceWaylandSurface fromWaylandSurface; - fromWaylandSurface.chain.next = NULL; fromWaylandSurface.chain.sType = WGPUSType_SurfaceSourceWaylandSurface; +#else + WGPUSurfaceDescriptorFromWaylandSurface fromWaylandSurface; + fromWaylandSurface.chain.sType = WGPUSType_SurfaceDescriptorFromWaylandSurface; +#endif + fromWaylandSurface.chain.next = NULL; fromWaylandSurface.display = wayland_display; fromWaylandSurface.surface = wayland_surface; @@ -110,9 +120,14 @@ WGPUSurface glfwGetWGPUSurface(WGPUInstance instance, GLFWwindow* window) { [ns_window.contentView setWantsLayer : YES] ; [ns_window.contentView setLayer : metal_layer] ; +#ifdef WEBGPU_BACKEND_DAWN WGPUSurfaceSourceMetalLayer fromMetalLayer; - fromMetalLayer.chain.next = NULL; fromMetalLayer.chain.sType = WGPUSType_SurfaceSourceMetalLayer; +#else + WGPUSurfaceDescriptorFromMetalLayer fromMetalLayer; + fromMetalLayer.chain.sType = WGPUSType_SurfaceDescriptorFromMetalLayer; +#endif + fromMetalLayer.chain.next = NULL; fromMetalLayer.layer = metal_layer; WGPUSurfaceDescriptor surfaceDescriptor; @@ -128,9 +143,14 @@ WGPUSurface glfwGetWGPUSurface(WGPUInstance instance, GLFWwindow* window) { HWND hwnd = glfwGetWin32Window(window); HINSTANCE hinstance = GetModuleHandle(NULL); +#ifdef WEBGPU_BACKEND_DAWN WGPUSurfaceSourceWindowsHWND fromWindowsHWND; - fromWindowsHWND.chain.next = NULL; fromWindowsHWND.chain.sType = WGPUSType_SurfaceSourceWindowsHWND; +#else + WGPUSurfaceDescriptorFromWindowsHWND fromWindowsHWND; + fromWindowsHWND.chain.sType = WGPUSType_SurfaceDescriptorFromWindowsHWND; +#endif + fromWindowsHWND.chain.next = NULL; fromWindowsHWND.hinstance = hinstance; fromWindowsHWND.hwnd = hwnd; @@ -144,9 +164,14 @@ WGPUSurface glfwGetWGPUSurface(WGPUInstance instance, GLFWwindow* window) { #ifdef GLFW_EXPOSE_NATIVE_EMSCRIPTEN case GLFW_PLATFORM_EMSCRIPTEN: { +#ifdef WEBGPU_BACKEND_DAWN WGPUSurfaceSourceCanvasHTMLSelector_Emscripten fromCanvasHTMLSelector; - fromCanvasHTMLSelector.chain.next = NULL; fromCanvasHTMLSelector.chain.sType = WGPUSType_SurfaceSourceCanvasHTMLSelector_Emscripten; +#else + WGPUSurfaceDescriptorFromCanvasHTMLSelector fromCanvasHTMLSelector; + fromCanvasHTMLSelector.chain.sType = WGPUSType_SurfaceDescriptorFromCanvasHTMLSelector; +#endif + fromCanvasHTMLSelector.chain.next = NULL; fromCanvasHTMLSelector.selector = "canvas"; WGPUSurfaceDescriptor surfaceDescriptor;