diff --git a/src/x11_init.c b/src/x11_init.c index 6b34c263..c90babe1 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -1246,7 +1246,8 @@ GLFWbool _glfwConnectX11(int platformID, _GLFWplatform* platform) .getEGLNativeWindow = _glfwGetEGLNativeWindowX11, .getRequiredInstanceExtensions = _glfwGetRequiredInstanceExtensionsX11, .getPhysicalDevicePresentationSupport = _glfwGetPhysicalDevicePresentationSupportX11, - .createWindowSurface = _glfwCreateWindowSurfaceX11 + .createWindowSurface = _glfwCreateWindowSurfaceX11, + .createWindowWGPUSurface = _glfwCreateWindowWGPUSurfaceX11 }; // HACK: If the application has left the locale as "C" then both wide diff --git a/src/x11_platform.h b/src/x11_platform.h index 30326c5b..af1ad314 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -963,6 +963,8 @@ void _glfwGetRequiredInstanceExtensionsX11(char** extensions); GLFWbool _glfwGetPhysicalDevicePresentationSupportX11(VkInstance instance, VkPhysicalDevice device, uint32_t queuefamily); VkResult _glfwCreateWindowSurfaceX11(VkInstance instance, _GLFWwindow* window, const VkAllocationCallbacks* allocator, VkSurfaceKHR* surface); +WGPUSurface _glfwCreateWindowWGPUSurfaceX11(WGPUInstance instance, _GLFWwindow* window); + void _glfwFreeMonitorX11(_GLFWmonitor* monitor); void _glfwGetMonitorPosX11(_GLFWmonitor* monitor, int* xpos, int* ypos); void _glfwGetMonitorContentScaleX11(_GLFWmonitor* monitor, float* xscale, float* yscale); diff --git a/src/x11_window.c b/src/x11_window.c index 322349f0..5a60f7a0 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -3282,6 +3282,53 @@ VkResult _glfwCreateWindowSurfaceX11(VkInstance instance, } } +typedef struct WGPUSurfaceSourceXCBWindow { + WGPUChainedStruct chain; + void * connection; + uint32_t window; +} WGPUSurfaceSourceXCBWindow; + +typedef struct WGPUSurfaceSourceXlibWindow { + WGPUChainedStruct chain; + void * display; + uint64_t window; +} WGPUSurfaceSourceXlibWindow; + +WGPUSurface _glfwCreateWindowWGPUSurfaceX11(WGPUInstance instance, _GLFWwindow* window) +{ + WGPUSurfaceDescriptor surfaceDescriptor; + + if (_glfw.x11.x11xcb.handle) + { + WGPUSurfaceSourceXCBWindow xcbSurface; + xcbSurface.chain.sType = WGPUSType_SurfaceSourceXCBWindow; + xcbSurface.chain.next = NULL; + xcb_connection_t* connection = XGetXCBConnection(_glfw.x11.display); + if (!connection) + { + _glfwInputError(GLFW_PLATFORM_ERROR, + "X11: Failed to retrieve XCB connection"); + return NULL; + } + xcbSurface.connection = connection; + xcbSurface.window = window->x11.handle; + surfaceDescriptor.nextInChain = &xcbSurface.chain; + } + else + { + WGPUSurfaceSourceXlibWindow xlibSurface; + xlibSurface.chain.sType = WGPUSType_SurfaceSourceXlibWindow; + xlibSurface.chain.next = NULL; + xlibSurface.display = _glfw.x11.display; + xlibSurface.window = window->x11.handle; + surfaceDescriptor.nextInChain = &xlibSurface.chain; + } + + surfaceDescriptor.label = (WGPUStringView){ NULL, SIZE_MAX }; + + return wgpuInstanceCreateSurface(instance, &surfaceDescriptor); +} + ////////////////////////////////////////////////////////////////////////// ////// GLFW native API //////