mirror of
https://github.com/odin-lang/Odin.git
synced 2026-06-08 19:44:20 +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:
5
vendor/glfw/bindings/bindings.odin
vendored
5
vendor/glfw/bindings/bindings.odin
vendored
@@ -197,7 +197,12 @@ foreign glfw {
|
||||
|
||||
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 ---
|
||||
@(linkage="weak")
|
||||
PlatformSupported :: proc(platform: c.int) -> b32 ---
|
||||
}
|
||||
|
||||
|
||||
6
vendor/glfw/native_linux.odin
vendored
6
vendor/glfw/native_linux.odin
vendored
@@ -13,7 +13,13 @@ foreign {
|
||||
SetX11SelectionString :: proc(string: 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* */ ---
|
||||
@(linkage="weak")
|
||||
GetWaylandWindow :: proc(window: WindowHandle) -> rawptr /* struct wl_surface* */ ---
|
||||
@(linkage="weak")
|
||||
GetWaylandMonitor :: proc(monitor: MonitorHandle) -> rawptr /* struct wl_output* */ ---
|
||||
}
|
||||
|
||||
12
vendor/wgpu/README.md
vendored
12
vendor/wgpu/README.md
vendored
@@ -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
|
||||
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.
|
||||
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.
|
||||
|
||||
9
vendor/wgpu/glfwglue/glue_linux.odin
vendored
9
vendor/wgpu/glfwglue/glue_linux.odin
vendored
@@ -3,11 +3,8 @@ package wgpu_glfw_glue
|
||||
import "vendor:glfw"
|
||||
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 {
|
||||
when SUPPORT_WAYLAND {
|
||||
if glfw.GetPlatform != nil {
|
||||
if glfw.GetPlatform() == glfw.PLATFORM_WAYLAND {
|
||||
display := glfw.GetWaylandDisplay()
|
||||
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()
|
||||
|
||||
Reference in New Issue
Block a user