From 37812b7e36c392a68f617e820f3a113026af8e66 Mon Sep 17 00:00:00 2001 From: Sebastian Emanuel Dawid Date: Fri, 15 Aug 2025 23:39:30 +0200 Subject: [PATCH] Revert "Try loading surface creation function via `dlsym` instead" This reverts commit cb0c28908f78ddef154e55a9fc3fda43f2829108. --- include/GLFW/glfw3.h | 13 +++++++++++++ src/init.c | 2 -- src/internal.h | 2 -- src/webgpu.c | 11 ++++------- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/include/GLFW/glfw3.h b/include/GLFW/glfw3.h index f920bd7b..516852a9 100644 --- a/include/GLFW/glfw3.h +++ b/include/GLFW/glfw3.h @@ -6531,6 +6531,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/init.c b/src/init.c index d31d111e..dbd5a900 100644 --- a/src/init.c +++ b/src/init.c @@ -402,8 +402,6 @@ GLFWAPI int glfwInit(void) if (!_glfwSelectPlatform(_glfw.hints.init.platformID, &_glfw.platform)) return GLFW_FALSE; - _glfwLoadWGPUInstanceCreateSurfaceAddr(); - if (!_glfw.platform.init()) { terminate(); diff --git a/src/internal.h b/src/internal.h index 4b860140..1ee044c9 100644 --- a/src/internal.h +++ b/src/internal.h @@ -1051,8 +1051,6 @@ GLFWbool _glfwInitVulkan(int mode); void _glfwTerminateVulkan(void); const char* _glfwGetVulkanResultString(VkResult result); -void _glfwLoadWGPUInstanceCreateSurfaceAddr(void); - size_t _glfwEncodeUTF8(char* s, uint32_t codepoint); char** _glfwParseUriList(char* text, int* count); diff --git a/src/webgpu.c b/src/webgpu.c index 5b841bc2..7a32cfe3 100644 --- a/src/webgpu.c +++ b/src/webgpu.c @@ -28,14 +28,11 @@ #include #include -#if defined(_GLFW_WIN32) -// TODO: Implement Window version -#else -#include -void _glfwLoadWGPUInstanceCreateSurfaceAddr() { - _glfw.wgpu.instanceCreateSurface = dlsym(RTLD_DEFAULT, "wgpuInstanceCreateSurface"); + +GLFWAPI void glfwSetWGPUInstanceCreateSurfaceAddr(WGPUSurface (*addr)(WGPUInstance, const WGPUSurfaceDescriptor*)) { + _GLFW_REQUIRE_INIT() + _glfw.wgpu.instanceCreateSurface = addr; } -#endif GLFWAPI WGPUSurface glfwCreateWindowWGPUSurface(WGPUInstance instance, GLFWwindow* handle) { _GLFW_REQUIRE_INIT_OR_RETURN(NULL)