diff --git a/include/GLFW/glfw3.h b/include/GLFW/glfw3.h index 1d31ced65..fe181bcde 100644 --- a/include/GLFW/glfw3.h +++ b/include/GLFW/glfw3.h @@ -6536,6 +6536,19 @@ GLFWAPI VkResult glfwCreateWindowSurface(VkInstance instance, GLFWwindow* window #if defined(WEBGPU_H_) +/*! @brief Provide the address of the `wgpuInstanceCreateSurface` function to GLFW. + * + * This function passes the address provided for the `wgpuInstanceCreateSurface` function + * to GLFW. + * + * @param[in] addr The address of the `wgpuInstanceCreateSurface` function. + * + * @since Added in version 3.5 + * + * @ingroup webgpu + */ +GLFWAPI void glfwSetWGPUInstanceCreateSurfaceAddr(WGPUSurface (*addr)(WGPUInstance, const WGPUSurfaceDescriptor*)); + /*! @brief Creates a WebGPU surface for the specified window. * * This function creates a WebGPU surface for the specified window. diff --git a/src/internal.h b/src/internal.h index eaedb1c68..fbd3acb0a 100644 --- a/src/internal.h +++ b/src/internal.h @@ -367,9 +367,8 @@ typedef struct WGPUSurfaceDescriptor WGPUStringView label; } WGPUSurfaceDescriptor; -#if !defined(_MSC_VER) -WGPUSurface __attribute__((weak)) wgpuInstanceCreateSurface(WGPUInstance instance, const WGPUSurfaceDescriptor* descriptor); -#endif +typedef WGPUSurface (*PFN_wgpuInstanceCreateSurface)(WGPUInstance, const WGPUSurfaceDescriptor*); +#define wgpuInstanceCreateSurface _glfw.wgpu.instanceCreateSurface #include "platform.h" @@ -916,6 +915,10 @@ struct _GLFWlibrary GLFWbool EXT_headless_surface; } vk; + struct { + PFN_wgpuInstanceCreateSurface instanceCreateSurface; + } wgpu; + struct { GLFWmonitorfun monitor; GLFWjoystickfun joystick; diff --git a/src/webgpu.c b/src/webgpu.c index 5af24b411..e330bd8f9 100644 --- a/src/webgpu.c +++ b/src/webgpu.c @@ -29,12 +29,11 @@ #include #include -#if !defined(_MSC_VER) -WGPUSurface __attribute__((weak)) wgpuInstanceCreateSurface(WGPUInstance instance, const WGPUSurfaceDescriptor* descriptor) +GLFWAPI void glfwSetWGPUInstanceCreateSurfaceAddr(WGPUSurface (*addr)(WGPUInstance, const WGPUSurfaceDescriptor*)) { - return NULL; + _GLFW_REQUIRE_INIT() + _glfw.wgpu.instanceCreateSurface = addr; } -#endif GLFWAPI WGPUSurface glfwCreateWindowWGPUSurface(WGPUInstance instance, GLFWwindow* handle) { @@ -44,7 +43,7 @@ GLFWAPI WGPUSurface glfwCreateWindowWGPUSurface(WGPUInstance instance, GLFWwindo assert(window != NULL); assert(instance != NULL); - assert(&wgpuInstanceCreateSurface != NULL); + assert(_glfw.wgpu.instanceCreateSurface != NULL); if (window->context.client != GLFW_NO_API) {