mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-18 11:52:22 -07:00
wgpu: add sdl3 glue
This commit is contained in:
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
#+build !linux
|
||||
#+build !windows
|
||||
#+build !darwin
|
||||
package wgpu_sdl3_glue
|
||||
|
||||
#panic("package wgpu/sdl3glue is not supported on the current target")
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package wgpu_sdl3_glue
|
||||
|
||||
import "vendor:sdl3"
|
||||
import "vendor:wgpu"
|
||||
import CA "vendor:darwin/QuartzCore"
|
||||
import NS "core:sys/darwin/Foundation"
|
||||
|
||||
GetSurface :: proc(instance: wgpu.Instance, window: ^sdl3.Window) -> wgpu.Surface {
|
||||
ns_window := cast(^NS.Window)sdl3.GetPointerProperty(sdl3.GetWindowProperties(window), sdl3.PROP_WINDOW_COCOA_WINDOW_POINTER, nil)
|
||||
metal_layer := CA.MetalLayer_layer()
|
||||
ns_window->contentView()->setLayer(metal_layer)
|
||||
return wgpu.InstanceCreateSurface(
|
||||
instance,
|
||||
&wgpu.SurfaceDescriptor{
|
||||
nextInChain = &wgpu.SurfaceDescriptorFromMetalLayer{
|
||||
chain = wgpu.ChainedStruct{
|
||||
sType = .SurfaceDescriptorFromMetalLayer,
|
||||
},
|
||||
layer = rawptr(metal_layer),
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
Vendored
+45
@@ -0,0 +1,45 @@
|
||||
package wgpu_sdl3_glue
|
||||
|
||||
import "vendor:sdl3"
|
||||
import "vendor:wgpu"
|
||||
|
||||
@(private="file")
|
||||
DRIVER_X11: cstring = "x11"
|
||||
@(private="file")
|
||||
DRIVER_WAYLAND: cstring = "wayland"
|
||||
|
||||
GetSurface :: proc(instance: wgpu.Instance, window: ^sdl3.Window) -> wgpu.Surface {
|
||||
if sdl3.strcmp(sdl3.GetCurrentVideoDriver(), DRIVER_WAYLAND) == 0 {
|
||||
display := sdl3.GetPointerProperty(sdl3.GetWindowProperties(window), sdl3.PROP_WINDOW_X11_DISPLAY_POINTER, nil)
|
||||
surface := sdl3.GetNumberProperty(sdl3.GetWindowProperties(window), sdl3.PROP_WINDOW_X11_WINDOW_NUMBER, 0)
|
||||
return wgpu.InstanceCreateSurface(
|
||||
instance,
|
||||
&wgpu.SurfaceDescriptor{
|
||||
nextInChain = &wgpu.SurfaceDescriptorFromWaylandSurface{
|
||||
chain = {
|
||||
sType = .SurfaceDescriptorFromWaylandSurface,
|
||||
},
|
||||
display = display,
|
||||
surface = surface,
|
||||
},
|
||||
},
|
||||
)
|
||||
} else if sdl3.strcmp(sdl3.GetCurrentVideoDriver(), DRIVER_X11) == 0 {
|
||||
display := sdl3.GetPointerProperty(sdl3.GetWindowProperties(window), sdl3.PROP_WINDOW_WAYLAND_DISPLAY_POINTER, nil)
|
||||
surface := sdl3.GetPointerProperty(sdl3.GetWindowProperties(window), sdl3.PROP_WINDOW_WAYLAND_SURFACE_POINTER, 0)
|
||||
return wgpu.InstanceCreateSurface(
|
||||
instance,
|
||||
&wgpu.SurfaceDescriptor{
|
||||
nextInChain = &wgpu.SurfaceDescriptorFromXlibWindow{
|
||||
chain = {
|
||||
sType = .SurfaceDescriptorFromXlibWindow,
|
||||
},
|
||||
display = display,
|
||||
window = u64(window),
|
||||
},
|
||||
},
|
||||
)
|
||||
} else {
|
||||
panic("wgpu sdl3 glue: unsupported platform, expected Wayland or X11")
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package wgpu_sdl3_glue
|
||||
|
||||
import win "core:sys/windows"
|
||||
|
||||
import "vendor:sdl3"
|
||||
import "vendor:wgpu"
|
||||
|
||||
GetSurface :: proc(instance: wgpu.Instance, window: ^sdl3.Window) -> wgpu.Surface {
|
||||
hwnd := sdl3.GetPointerProperty(sdl3.GetWindowProperties(window), sdl3.PROP_WINDOW_WIN32_HWND_POINTER, nil)
|
||||
hinstance := win.GetModuleHandleW(nil)
|
||||
return wgpu.InstanceCreateSurface(
|
||||
instance,
|
||||
&wgpu.SurfaceDescriptor{
|
||||
nextInChain = &wgpu.SurfaceDescriptorFromWindowsHWND{
|
||||
chain = wgpu.ChainedStruct{
|
||||
sType = .SurfaceDescriptorFromWindowsHWND,
|
||||
},
|
||||
hinstance = rawptr(hinstance),
|
||||
hwnd = rawptr(hwnd),
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user