Skip to content

Commit

Permalink
Merge pull request #4837 from SlashScreen/sdl3_glue
Browse files Browse the repository at this point in the history
wgpu: add sdl3 glue
  • Loading branch information
gingerBill authored Feb 13, 2025
2 parents 435f77b + b7f37bb commit 816566d
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 0 deletions.
6 changes: 6 additions & 0 deletions vendor/wgpu/sdl3glue/glue.odin
Original file line number Diff line number Diff line change
@@ -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")
18 changes: 18 additions & 0 deletions vendor/wgpu/sdl3glue/glue_darwin.odin
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package wgpu_sdl3_glue

import "vendor:sdl3"
import "vendor:wgpu"

GetSurface :: proc(instance: wgpu.Instance, window: ^sdl3.Window) -> wgpu.Surface {
view := sdl3.Metal_CreateView(window)
metal_layer := sdl3.Metal_GetLayer(view)
return wgpu.InstanceCreateSurface(
instance,
&wgpu.SurfaceDescriptor {
nextInChain = &wgpu.SurfaceDescriptorFromMetalLayer {
chain = wgpu.ChainedStruct{sType = .SurfaceDescriptorFromMetalLayer},
layer = metal_layer,
},
},
)
}
54 changes: 54 additions & 0 deletions vendor/wgpu/sdl3glue/glue_linux.odin
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package wgpu_sdl3_glue

import "vendor:sdl3"
import "vendor:wgpu"


GetSurface :: proc(instance: wgpu.Instance, window: ^sdl3.Window) -> wgpu.Surface {
switch sdl3.GetCurrentVideoDriver() {
case "x11":
display := sdl3.GetPointerProperty(
sdl3.GetWindowProperties(window),
sdl3.PROP_WINDOW_X11_DISPLAY_POINTER,
nil,
)
x_window := sdl3.GetNumberProperty(
sdl3.GetWindowProperties(window),
sdl3.PROP_WINDOW_X11_WINDOW_NUMBER,
0,
)
return wgpu.InstanceCreateSurface(
instance,
&wgpu.SurfaceDescriptor {
nextInChain = &wgpu.SurfaceDescriptorFromXlibWindow {
chain = {sType = .SurfaceDescriptorFromXlibWindow},
display = display,
window = u64(x_window),
},
},
)
case "wayland":
display := sdl3.GetPointerProperty(
sdl3.GetWindowProperties(window),
sdl3.PROP_WINDOW_WAYLAND_DISPLAY_POINTER,
nil,
)
w_surface := sdl3.GetPointerProperty(
sdl3.GetWindowProperties(window),
sdl3.PROP_WINDOW_WAYLAND_SURFACE_POINTER,
nil,
)
return wgpu.InstanceCreateSurface(
instance,
&wgpu.SurfaceDescriptor {
nextInChain = &wgpu.SurfaceDescriptorFromWaylandSurface {
chain = {sType = .SurfaceDescriptorFromWaylandSurface},
display = display,
surface = w_surface,
},
},
)
case:
panic("wgpu sdl3 glue: unsupported platform, expected Wayland or X11")
}
}
29 changes: 29 additions & 0 deletions vendor/wgpu/sdl3glue/glue_windows.odin
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
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 := sdl3.GetPointerProperty(
sdl3.GetWindowProperties(window),
sdl3.PROP_WINDOW_WIN32_INSTANCE_POINTER,
nil,
)
return wgpu.InstanceCreateSurface(
instance,
&wgpu.SurfaceDescriptor {
nextInChain = &wgpu.SurfaceDescriptorFromWindowsHWND {
chain = wgpu.ChainedStruct{sType = .SurfaceDescriptorFromWindowsHWND},
hinstance = hinstance,
hwnd = hwnd,
},
},
)
}

0 comments on commit 816566d

Please # to comment.