Compare commits

...

9 Commits

Author SHA1 Message Date
Sebastian Dawid
a297c9b81c
Merge 44f8a80ade into 63a7e8b7f8 2025-08-20 21:11:23 +02:00
Camilla Löwy
63a7e8b7f8 Add and update Wayland-specific notes in docs
Fixes #2746
2025-08-20 20:13:07 +02:00
Sebastian Emanuel Dawid
44f8a80ade Add WebGPU support for MacOS 2025-08-16 00:46:54 +02:00
Sebastian Dawid
4cbb4db70c Add WebGPU support for Windows 2025-08-16 00:30:16 +02:00
Sebastian Emanuel Dawid
205bf6c768 Add WebGPU support to X11 2025-08-15 23:57:40 +02:00
Sebastian Emanuel Dawid
37812b7e36 Revert "Try loading surface creation function via dlsym instead"
This reverts commit cb0c28908f.
2025-08-15 23:39:30 +02:00
Sebastian Emanuel Dawid
cb0c28908f Try loading surface creation function via dlsym instead 2025-08-15 23:38:04 +02:00
Sebastian Emanuel Dawid
8dc6a1f00b Add surface creation function to wl platform initialization 2025-08-15 23:12:47 +02:00
Sebastian Emanuel Dawid
2f44430536 Added native support for creating WebGPU surfaces
Note that this commit only adds support when running on Wayland.
2025-08-15 23:08:51 +02:00
19 changed files with 305 additions and 28 deletions

View File

@ -55,6 +55,7 @@ video tutorials.
- Jason Daly
- danhambleton
- Jarrod Davis
- decce
- Olivier Delannoy
- Paul R. Deppe
- Michael Dickens

View File

@ -255,3 +255,7 @@ hardware gamma correction, which today is typically an approximation of sRGB
gamma. This means that setting a perfectly linear ramp, or gamma 1.0, will
produce the default (usually sRGB-like) behavior.
@note @wayland An application cannot read or modify the monitor gamma ramp. The
@ref glfwGetGammaRamp, @ref glfwSetGammaRamp and @ref glfwSetGamma functions
emit @ref GLFW_FEATURE_UNAVAILABLE.

View File

@ -893,6 +893,12 @@ int xpos, ypos;
glfwGetWindowPos(window, &xpos, &ypos);
```
@note @wayland An applications cannot know the positions of its windows or
whether one has been moved. The @ref GLFW_POSITION_X and @ref GLFW_POSITION_Y
window hints are ignored. The @ref glfwGetWindowPos and @ref glfwSetWindowPos
functions emit @ref GLFW_FEATURE_UNAVAILABLE. The window position callback will
not be called.
### Window title {#window_title}
@ -1038,6 +1044,12 @@ You can also get the current iconification state with @ref glfwGetWindowAttrib.
int iconified = glfwGetWindowAttrib(window, GLFW_ICONIFIED);
```
@note @wayland An application cannot know if any of its windows have been
iconified or restore one from iconification. The @ref glfwRestoreWindow
function can only restore windows from maximization and the iconify callback
will not be called. The [GLFW_ICONIFIED](@ref GLFW_ICONIFIED_attrib) attribute
will be false. The @ref glfwIconifyWindow function works normally.
### Window maximization {#window_maximize}

View File

@ -115,6 +115,10 @@ extern "C" {
* VK_USE_PLATFORM_WIN32_KHR) so we offer our replacement symbols after it.
*/
#if defined(GLFW_INCLUDE_WEBGPU)
#include <webgpu/webgpu.h>
#endif /* WebGPU header */
/* It is customary to use APIENTRY for OpenGL function pointer declarations on
* all platforms. Additionally, the Windows OpenGL header needs APIENTRY.
*/
@ -2915,8 +2919,8 @@ GLFWAPI const GLFWvidmode* glfwGetVideoMode(GLFWmonitor* monitor);
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref GLFW_INVALID_VALUE,
* @ref GLFW_PLATFORM_ERROR and @ref GLFW_FEATURE_UNAVAILABLE (see remarks).
*
* @remark @wayland Gamma handling is a privileged protocol, this function
* will thus never be implemented and emits @ref GLFW_FEATURE_UNAVAILABLE.
* @remark @wayland Monitor gamma is a privileged protocol, so this function
* cannot be implemented and emits @ref GLFW_FEATURE_UNAVAILABLE.
*
* @thread_safety This function must only be called from the main thread.
*
@ -2939,8 +2943,8 @@ GLFWAPI void glfwSetGamma(GLFWmonitor* monitor, float gamma);
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref GLFW_PLATFORM_ERROR
* and @ref GLFW_FEATURE_UNAVAILABLE (see remarks).
*
* @remark @wayland Gamma handling is a privileged protocol, this function
* will thus never be implemented and emits @ref GLFW_FEATURE_UNAVAILABLE while
* @remark @wayland Monitor gamma is a privileged protocol, so this function
* cannot be implemented and emits @ref GLFW_FEATURE_UNAVAILABLE while
* returning `NULL`.
*
* @pointer_lifetime The returned structure and its arrays are allocated and
@ -2983,8 +2987,8 @@ GLFWAPI const GLFWgammaramp* glfwGetGammaRamp(GLFWmonitor* monitor);
*
* @remark @win32 The gamma ramp size must be 256.
*
* @remark @wayland Gamma handling is a privileged protocol, this function
* will thus never be implemented and emits @ref GLFW_FEATURE_UNAVAILABLE.
* @remark @wayland Monitor gamma is a privileged protocol, so this function
* cannot be implemented and emits @ref GLFW_FEATURE_UNAVAILABLE.
*
* @pointer_lifetime The specified gamma ramp is copied before this function
* returns.
@ -3430,8 +3434,8 @@ GLFWAPI void glfwSetWindowIcon(GLFWwindow* window, int count, const GLFWimage* i
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref
* GLFW_PLATFORM_ERROR and @ref GLFW_FEATURE_UNAVAILABLE (see remarks).
*
* @remark @wayland There is no way for an application to retrieve the global
* position of its windows. This function will emit @ref
* @remark @wayland Window positions are not currently part of any common
* Wayland protocol, so this function cannot be implemented and will emit @ref
* GLFW_FEATURE_UNAVAILABLE.
*
* @thread_safety This function must only be called from the main thread.
@ -3464,8 +3468,8 @@ GLFWAPI void glfwGetWindowPos(GLFWwindow* window, int* xpos, int* ypos);
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref
* GLFW_PLATFORM_ERROR and @ref GLFW_FEATURE_UNAVAILABLE (see remarks).
*
* @remark @wayland There is no way for an application to set the global
* position of its windows. This function will emit @ref
* @remark @wayland Window positions are not currently part of any common
* Wayland protocol, so this function cannot be implemented and will emit @ref
* GLFW_FEATURE_UNAVAILABLE.
*
* @thread_safety This function must only be called from the main thread.
@ -3807,10 +3811,6 @@ GLFWAPI void glfwSetWindowOpacity(GLFWwindow* window, float opacity);
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref
* GLFW_PLATFORM_ERROR.
*
* @remark @wayland Once a window is iconified, @ref glfwRestoreWindow wont
* be able to restore it. This is a design decision of the xdg-shell
* protocol.
*
* @thread_safety This function must only be called from the main thread.
*
* @sa @ref window_iconify
@ -3838,6 +3838,10 @@ GLFWAPI void glfwIconifyWindow(GLFWwindow* window);
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref
* GLFW_PLATFORM_ERROR.
*
* @remark @wayland Restoring a window from maximization is not currently part
* of any common Wayland protocol, so this function can only restore windows
* from maximization.
*
* @thread_safety This function must only be called from the main thread.
*
* @sa @ref window_iconify
@ -4058,8 +4062,8 @@ GLFWAPI GLFWmonitor* glfwGetWindowMonitor(GLFWwindow* window);
* affected by any resizing or mode switching, although you may need to update
* your viewport if the framebuffer size has changed.
*
* @remark @wayland The desired window position is ignored, as there is no way
* for an application to set this property.
* @remark @wayland Window positions are not currently part of any common
* Wayland protocol. The window position arguments are ignored.
*
* @thread_safety This function must only be called from the main thread.
*
@ -4096,8 +4100,9 @@ GLFWAPI void glfwSetWindowMonitor(GLFWwindow* window, GLFWmonitor* monitor, int
* errors. However, this function should not fail as long as it is passed
* valid arguments and the library has been [initialized](@ref intro_init).
*
* @remark @wayland The Wayland protocol provides no way to check whether a
* window is iconfied, so @ref GLFW_ICONIFIED always returns `GLFW_FALSE`.
* @remark @wayland Checking whether a window is iconified is not currently
* part of any common Wayland protocol, so the @ref GLFW_ICONIFIED attribute
* cannot be implemented and is always `GLFW_FALSE`.
*
* @thread_safety This function must only be called from the main thread.
*
@ -4219,8 +4224,8 @@ GLFWAPI void* glfwGetWindowUserPointer(GLFWwindow* window);
*
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED.
*
* @remark @wayland This callback will never be called, as there is no way for
* an application to know its global position.
* @remark @wayland This callback will not be called. The Wayland protocol
* provides no way to be notified of when a window is moved.
*
* @thread_safety This function must only be called from the main thread.
*
@ -4395,6 +4400,10 @@ GLFWAPI GLFWwindowfocusfun glfwSetWindowFocusCallback(GLFWwindow* window, GLFWwi
*
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED.
*
* @remark @wayland This callback will not be called. The Wayland protocol
* provides no way to be notified of when a window is iconified, and no way to
* check whether a window is currently iconified.
*
* @thread_safety This function must only be called from the main thread.
*
* @sa @ref window_iconify
@ -6525,6 +6534,41 @@ GLFWAPI VkResult glfwCreateWindowSurface(VkInstance instance, GLFWwindow* window
#endif /*VK_VERSION_1_0*/
#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.
*
* If the surface could not be created this function returns `NULL`.
*
* It is the callers responsibility to destroy the surface. The surface
* must be destroyed using `wgpuSurfaceRelease`.
*
* @param[in] instance The WebGPU instance to create the surface in.
* @param[in] window The window to create the surface for.
* @return The handle of the surface. This is `NULL` if an error occurred.
*
* @since Added in version 3.5
*
* @ingroup webgpu
*/
GLFWAPI WGPUSurface glfwCreateWindowWGPUSurface(WGPUInstance instance, GLFWwindow* window);
#endif /*WEBGPU_H_*/
/*************************************************************************
* Global definition cleanup

View File

@ -3,9 +3,10 @@ add_library(glfw ${GLFW_LIBRARY_TYPE}
"${GLFW_SOURCE_DIR}/include/GLFW/glfw3.h"
"${GLFW_SOURCE_DIR}/include/GLFW/glfw3native.h"
internal.h platform.h mappings.h
context.c init.c input.c monitor.c platform.c vulkan.c window.c
egl_context.c osmesa_context.c null_platform.h null_joystick.h
null_init.c null_monitor.c null_window.c null_joystick.c)
context.c init.c input.c monitor.c platform.c vulkan.c webgpu.c
window.c egl_context.c osmesa_context.c null_platform.h
null_joystick.h null_init.c null_monitor.c null_window.c
null_joystick.c)
# The time, thread and module code is shared between all backends on a given OS,
# including the null backend, which still needs those bits to be functional
@ -128,7 +129,8 @@ set_target_properties(glfw PROPERTIES
C_STANDARD 99
C_EXTENSIONS OFF
DEFINE_SYMBOL _GLFW_BUILD_DLL
FOLDER "GLFW3")
FOLDER "GLFW3"
EXPORT_COMPILE_COMMANDS ON)
target_include_directories(glfw PUBLIC
"$<BUILD_INTERFACE:${GLFW_SOURCE_DIR}/include>"

View File

@ -564,7 +564,8 @@ GLFWbool _glfwConnectCocoa(int platformID, _GLFWplatform* platform)
.getEGLNativeWindow = _glfwGetEGLNativeWindowCocoa,
.getRequiredInstanceExtensions = _glfwGetRequiredInstanceExtensionsCocoa,
.getPhysicalDevicePresentationSupport = _glfwGetPhysicalDevicePresentationSupportCocoa,
.createWindowSurface = _glfwCreateWindowSurfaceCocoa
.createWindowSurface = _glfwCreateWindowSurfaceCocoa,
.createWindowWGPUSurface = _glfwCreateWindowWGPUSurfaceCocoa
};
*platform = cocoa;

View File

@ -276,6 +276,8 @@ void _glfwGetRequiredInstanceExtensionsCocoa(char** extensions);
GLFWbool _glfwGetPhysicalDevicePresentationSupportCocoa(VkInstance instance, VkPhysicalDevice device, uint32_t queuefamily);
VkResult _glfwCreateWindowSurfaceCocoa(VkInstance instance, _GLFWwindow* window, const VkAllocationCallbacks* allocator, VkSurfaceKHR* surface);
WGPUSurface _glfwCreateWindowWGPUSurfaceCocoa(WGPUInstance instance, _GLFWwindow* window);
void _glfwFreeMonitorCocoa(_GLFWmonitor* monitor);
void _glfwGetMonitorPosCocoa(_GLFWmonitor* monitor, int* xpos, int* ypos);
void _glfwGetMonitorContentScaleCocoa(_GLFWmonitor* monitor, float* xscale, float* yscale);

View File

@ -2020,6 +2020,26 @@ VkResult _glfwCreateWindowSurfaceCocoa(VkInstance instance,
} // autoreleasepool
}
typedef struct WGPUSurfaceSourceMetalLayer {
WGPUChainedStruct chain;
void * layer;
} WGPUSurfaceSourceMetalLayer;
WGPUSurface _glfwCreateWindowWGPUSurfaceCocoa(WGPUInstance instance, _GLFWwindow* window) {
[window->ns.view setLayer:window->ns.layer];
[window->ns.view setWantsLayer:YES];
WGPUSurfaceSourceMetalLayer metalSurface;
metalSurface.chain.next = NULL;
metalSurface.chain.sType = WGPUSType_SurfaceSourceMetalLayer;
metalSurface.layer = window->ns.layer;
WGPUSurfaceDescriptor surfaceDescriptor;
surfaceDescriptor.nextInChain = &metalSurface.chain;
surfaceDescriptor.label = (WGPUStringView){ NULL, SIZE_MAX };
return wgpuInstanceCreateSurface(instance, &surfaceDescriptor);
}
//////////////////////////////////////////////////////////////////////////
////// GLFW native API //////

View File

@ -331,6 +331,42 @@ typedef PFN_vkVoidFunction (APIENTRY * PFN_vkGetInstanceProcAddr)(VkInstance,con
typedef VkResult (APIENTRY * PFN_vkEnumerateInstanceExtensionProperties)(const char*,uint32_t*,VkExtensionProperties*);
#define vkGetInstanceProcAddr _glfw.vk.GetInstanceProcAddr
// forward declare WebGPU types
typedef struct WGPUInstanceImpl* WGPUInstance;
typedef struct WGPUSurfaceImpl* WGPUSurface;
typedef struct WGPUStringView {
char const * data;
size_t length;
} WGPUStringView;
typedef enum WGPUSType {
WGPUSType_ShaderSourceSPIRV = 0x00000001,
WGPUSType_ShaderSourceWGSL = 0x00000002,
WGPUSType_RenderPassMaxDrawCount = 0x00000003,
WGPUSType_SurfaceSourceMetalLayer = 0x00000004,
WGPUSType_SurfaceSourceWindowsHWND = 0x00000005,
WGPUSType_SurfaceSourceXlibWindow = 0x00000006,
WGPUSType_SurfaceSourceWaylandSurface = 0x00000007,
WGPUSType_SurfaceSourceAndroidNativeWindow = 0x00000008,
WGPUSType_SurfaceSourceXCBWindow = 0x00000009,
WGPUSType_Force32 = 0x7FFFFFFF
} WGPUSType;
typedef struct WGPUChainedStruct {
struct WGPUChainedStruct const * next;
WGPUSType sType;
} WGPUChainedStruct;
typedef struct WGPUSurfaceDescriptor {
WGPUChainedStruct const * nextInChain;
WGPUStringView label;
} WGPUSurfaceDescriptor;
typedef WGPUSurface (*PFN_wgpuInstanceCreateSurface)(WGPUInstance, const WGPUSurfaceDescriptor*);
#define wgpuInstanceCreateSurface _glfw.wgpu.instanceCreateSurface
#include "platform.h"
#define GLFW_NATIVE_INCLUDE_NONE
@ -759,6 +795,8 @@ struct _GLFWplatform
void (*getRequiredInstanceExtensions)(char**);
GLFWbool (*getPhysicalDevicePresentationSupport)(VkInstance,VkPhysicalDevice,uint32_t);
VkResult (*createWindowSurface)(VkInstance,_GLFWwindow*,const VkAllocationCallbacks*,VkSurfaceKHR*);
// webgpu
WGPUSurface (*createWindowWGPUSurface)(WGPUInstance, _GLFWwindow*);
};
// Library global data
@ -875,6 +913,10 @@ struct _GLFWlibrary
GLFWbool EXT_headless_surface;
} vk;
struct {
PFN_wgpuInstanceCreateSurface instanceCreateSurface;
} wgpu;
struct {
GLFWmonitorfun monitor;
GLFWjoystickfun joystick;

54
src/webgpu.c Normal file
View File

@ -0,0 +1,54 @@
//========================================================================
// GLFW 3.5 - www.glfw.org
//------------------------------------------------------------------------
// Copyright (c) Sebastian Dawid <sdawid@techfak.uni-bielefeld.de>
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would
// be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not
// be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source
// distribution.
//
//========================================================================
#include "internal.h"
#include <assert.h>
#include <stdlib.h>
GLFWAPI void glfwSetWGPUInstanceCreateSurfaceAddr(WGPUSurface (*addr)(WGPUInstance, const WGPUSurfaceDescriptor*)) {
_GLFW_REQUIRE_INIT()
_glfw.wgpu.instanceCreateSurface = addr;
}
GLFWAPI WGPUSurface glfwCreateWindowWGPUSurface(WGPUInstance instance, GLFWwindow* handle) {
_GLFW_REQUIRE_INIT_OR_RETURN(NULL)
_GLFWwindow* window = (_GLFWwindow*)handle;
assert(window != NULL);
assert(instance != NULL);
assert(_glfw.wgpu.instanceCreateSurface != NULL);
if (window->context.client != GLFW_NO_API)
{
_glfwInputError(GLFW_INVALID_VALUE,
"WebGPU: Window surface creation requires the window to have the client API set to GLFW_NO_API");
return NULL;
};
return _glfw.platform.createWindowWGPUSurface(instance, window);
}

View File

@ -669,7 +669,8 @@ GLFWbool _glfwConnectWin32(int platformID, _GLFWplatform* platform)
.getEGLNativeWindow = _glfwGetEGLNativeWindowWin32,
.getRequiredInstanceExtensions = _glfwGetRequiredInstanceExtensionsWin32,
.getPhysicalDevicePresentationSupport = _glfwGetPhysicalDevicePresentationSupportWin32,
.createWindowSurface = _glfwCreateWindowSurfaceWin32
.createWindowSurface = _glfwCreateWindowSurfaceWin32,
.createWindowWGPUSurface = _glfwCreateWindowWGPUSurfaceWin32
};
*platform = win32;

View File

@ -544,6 +544,8 @@ void _glfwGetRequiredInstanceExtensionsWin32(char** extensions);
GLFWbool _glfwGetPhysicalDevicePresentationSupportWin32(VkInstance instance, VkPhysicalDevice device, uint32_t queuefamily);
VkResult _glfwCreateWindowSurfaceWin32(VkInstance instance, _GLFWwindow* window, const VkAllocationCallbacks* allocator, VkSurfaceKHR* surface);
WGPUSurface _glfwCreateWindowWGPUSurfaceWin32(WGPUInstance instance, _GLFWwindow* window);
void _glfwFreeMonitorWin32(_GLFWmonitor* monitor);
void _glfwGetMonitorPosWin32(_GLFWmonitor* monitor, int* xpos, int* ypos);
void _glfwGetMonitorContentScaleWin32(_GLFWmonitor* monitor, float* xscale, float* yscale);

View File

@ -2562,6 +2562,26 @@ VkResult _glfwCreateWindowSurfaceWin32(VkInstance instance,
return err;
}
typedef struct WGPUSurfaceSourceWindowsHWND {
WGPUChainedStruct chain;
void * hinstance;
void * hwnd;
} WGPUSurfaceSourceWindowsHWND;
WGPUSurface _glfwCreateWindowWGPUSurfaceWin32(WGPUInstance instance, _GLFWwindow *window) {
WGPUSurfaceSourceWindowsHWND windowsSurface;
windowsSurface.chain.sType = WGPUSType_SurfaceSourceWindowsHWND;
windowsSurface.chain.next = NULL;
windowsSurface.hinstance = _glfw.win32.instance;
windowsSurface.hwnd = window->win32.handle;
WGPUSurfaceDescriptor surfaceDescriptor;
surfaceDescriptor.nextInChain = &windowsSurface.chain;
surfaceDescriptor.label = (WGPUStringView){ NULL, SIZE_MAX };
return wgpuInstanceCreateSurface(instance, &surfaceDescriptor);
}
GLFWAPI HWND glfwGetWin32Window(GLFWwindow* handle)
{
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);

View File

@ -515,7 +515,8 @@ GLFWbool _glfwConnectWayland(int platformID, _GLFWplatform* platform)
.getEGLNativeWindow = _glfwGetEGLNativeWindowWayland,
.getRequiredInstanceExtensions = _glfwGetRequiredInstanceExtensionsWayland,
.getPhysicalDevicePresentationSupport = _glfwGetPhysicalDevicePresentationSupportWayland,
.createWindowSurface = _glfwCreateWindowSurfaceWayland
.createWindowSurface = _glfwCreateWindowSurfaceWayland,
.createWindowWGPUSurface = _glfwCreateWindowWGPUSurfaceWayland
};
void* module = _glfwPlatformLoadModule("libwayland-client.so.0");

View File

@ -678,6 +678,8 @@ void _glfwGetRequiredInstanceExtensionsWayland(char** extensions);
GLFWbool _glfwGetPhysicalDevicePresentationSupportWayland(VkInstance instance, VkPhysicalDevice device, uint32_t queuefamily);
VkResult _glfwCreateWindowSurfaceWayland(VkInstance instance, _GLFWwindow* window, const VkAllocationCallbacks* allocator, VkSurfaceKHR* surface);
WGPUSurface _glfwCreateWindowWGPUSurfaceWayland(WGPUInstance instance, _GLFWwindow* window);
void _glfwFreeMonitorWayland(_GLFWmonitor* monitor);
void _glfwGetMonitorPosWayland(_GLFWmonitor* monitor, int* xpos, int* ypos);
void _glfwGetMonitorContentScaleWayland(_GLFWmonitor* monitor, float* xscale, float* yscale);

View File

@ -3324,6 +3324,25 @@ VkResult _glfwCreateWindowSurfaceWayland(VkInstance instance,
return err;
}
typedef struct WGPUSurfaceSourceWaylandSurface {
WGPUChainedStruct chain;
void * display;
void * surface;
} WGPUSurfaceSourceWaylandSurface;
WGPUSurface _glfwCreateWindowWGPUSurfaceWayland(WGPUInstance instance, _GLFWwindow* window) {
WGPUSurfaceSourceWaylandSurface waylandSurface;
waylandSurface.chain.sType = WGPUSType_SurfaceSourceWaylandSurface;
waylandSurface.chain.next = NULL;
waylandSurface.surface = window->wl.surface;
waylandSurface.display = _glfw.wl.display;
WGPUSurfaceDescriptor surfaceDescriptor;
surfaceDescriptor.nextInChain = &waylandSurface.chain;
surfaceDescriptor.label = (WGPUStringView){ NULL, SIZE_MAX };
return wgpuInstanceCreateSurface(instance, &surfaceDescriptor);
}
//////////////////////////////////////////////////////////////////////////
////// GLFW native API //////

View File

@ -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

View File

@ -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);

View File

@ -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 //////