mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 07:38:48 +00:00
Merge pull request #3941 from laytan/wgpu-wayland-improvements
improve WGPU / GLFW / Wayland story by weak linking and adjusting docs
This commit is contained in:
Vendored
+5
@@ -197,7 +197,12 @@ foreign glfw {
|
|||||||
|
|
||||||
SetErrorCallback :: proc(cbfun: ErrorProc) -> ErrorProc ---
|
SetErrorCallback :: proc(cbfun: ErrorProc) -> ErrorProc ---
|
||||||
|
|
||||||
|
// Functions added in 3.4, Linux links against system glfw so we define these as weak to be able
|
||||||
|
// to check at runtime if they are available.
|
||||||
|
|
||||||
|
@(linkage="weak")
|
||||||
GetPlatform :: proc() -> c.int ---
|
GetPlatform :: proc() -> c.int ---
|
||||||
|
@(linkage="weak")
|
||||||
PlatformSupported :: proc(platform: c.int) -> b32 ---
|
PlatformSupported :: proc(platform: c.int) -> b32 ---
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Vendored
+6
@@ -13,7 +13,13 @@ foreign {
|
|||||||
SetX11SelectionString :: proc(string: cstring) ---
|
SetX11SelectionString :: proc(string: cstring) ---
|
||||||
GetX11SelectionString :: proc() -> cstring ---
|
GetX11SelectionString :: proc() -> cstring ---
|
||||||
|
|
||||||
|
// Functions added in 3.4, Linux links against system glfw so we define these as weak to be able
|
||||||
|
// to check at runtime if they are available.
|
||||||
|
|
||||||
|
@(linkage="weak")
|
||||||
GetWaylandDisplay :: proc() -> rawptr /* struct wl_display* */ ---
|
GetWaylandDisplay :: proc() -> rawptr /* struct wl_display* */ ---
|
||||||
|
@(linkage="weak")
|
||||||
GetWaylandWindow :: proc(window: WindowHandle) -> rawptr /* struct wl_surface* */ ---
|
GetWaylandWindow :: proc(window: WindowHandle) -> rawptr /* struct wl_surface* */ ---
|
||||||
|
@(linkage="weak")
|
||||||
GetWaylandMonitor :: proc(monitor: MonitorHandle) -> rawptr /* struct wl_output* */ ---
|
GetWaylandMonitor :: proc(monitor: MonitorHandle) -> rawptr /* struct wl_output* */ ---
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+9
-3
@@ -41,8 +41,14 @@ It exports one procedure `GetSurface(wgpu.Instance, glfw.WindowHandle) -> glfw.S
|
|||||||
The procedure will call the needed target specific procedures and return a surface configured
|
The procedure will call the needed target specific procedures and return a surface configured
|
||||||
for the given window.
|
for the given window.
|
||||||
|
|
||||||
To support Wayland on Linux, you need to have GLFW compiled to support it, and use
|
|
||||||
`-define:WGPU_GFLW_GLUE_SUPPORT_WAYLAND=true` to enable the package to check for Wayland.
|
|
||||||
|
|
||||||
Do note that wgpu does not require GLFW, you can use native windows or another windowing library too.
|
Do note that wgpu does not require GLFW, you can use native windows or another windowing library too.
|
||||||
For that you can take inspiration from `glfwglue` on glueing them together.
|
For that you can take inspiration from `glfwglue` on glueing them together.
|
||||||
|
|
||||||
|
### Wayland
|
||||||
|
|
||||||
|
GLFW supports Wayland from version 3.4 onwards and only if it is compiled with `-DGLFW_EXPOSE_NATIVE_WAYLAND`.
|
||||||
|
|
||||||
|
Odin links against your system's glfw library (probably installed through a package manager).
|
||||||
|
If that version is lower than 3.4 or hasn't been compiled with the previously mentioned define,
|
||||||
|
you will have to compile glfw from source yourself and adjust the `foreign import` declarations in `vendor:glfw/bindings` to
|
||||||
|
point to it.
|
||||||
|
|||||||
Vendored
+5
-4
@@ -3,11 +3,8 @@ package wgpu_glfw_glue
|
|||||||
import "vendor:glfw"
|
import "vendor:glfw"
|
||||||
import "vendor:wgpu"
|
import "vendor:wgpu"
|
||||||
|
|
||||||
// GLFW needs to be compiled with wayland support for this to work.
|
|
||||||
SUPPORT_WAYLAND :: #config(WGPU_GFLW_GLUE_SUPPORT_WAYLAND, false)
|
|
||||||
|
|
||||||
GetSurface :: proc(instance: wgpu.Instance, window: glfw.WindowHandle) -> wgpu.Surface {
|
GetSurface :: proc(instance: wgpu.Instance, window: glfw.WindowHandle) -> wgpu.Surface {
|
||||||
when SUPPORT_WAYLAND {
|
if glfw.GetPlatform != nil {
|
||||||
if glfw.GetPlatform() == glfw.PLATFORM_WAYLAND {
|
if glfw.GetPlatform() == glfw.PLATFORM_WAYLAND {
|
||||||
display := glfw.GetWaylandDisplay()
|
display := glfw.GetWaylandDisplay()
|
||||||
surface := glfw.GetWaylandWindow(window)
|
surface := glfw.GetWaylandWindow(window)
|
||||||
@@ -24,6 +21,10 @@ GetSurface :: proc(instance: wgpu.Instance, window: glfw.WindowHandle) -> wgpu.S
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if glfw.GetPlatform() != glfw.PLATFORM_X11 {
|
||||||
|
panic("wgpu glfw glue: unsupported platform, expected Wayland or X11")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
display := glfw.GetX11Display()
|
display := glfw.GetX11Display()
|
||||||
|
|||||||
Reference in New Issue
Block a user