-
Notifications
You must be signed in to change notification settings - Fork 0
/
glfw_webgpu.c3
62 lines (44 loc) · 1.82 KB
/
glfw_webgpu.c3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import glfw;
import webgpu;
def GlfwWindow = glfw::window::Window;
extern fn X11Display glfwGetX11Display();
extern fn X11Window glfwGetX11Window(GlfwWindow window);
extern fn WaylandDisplay glfwGetWaylandDisplay();
extern fn WaylandSurface glfwGetWaylandWindow(GlfwWindow window);
fault SurfaceError {
PLATFORM_UNSUPPORTED
}
fn Surface! createSurface(Instance instance, GlfwWindow window) {
Platform platform = glfw::getPlatform();
switch(platform) {
case platform::X11: return createX11Surface(instance, window);
case platform::WAYLAND: return createWaylandSurface(instance, window);
default: return SurfaceError.PLATFORM_UNSUPPORTED?;
}
}
fn Surface createX11Surface(Instance instance, GlfwWindow window) {
X11Display x11Display = glfwGetX11Display();
X11Window x11Window = glfwGetX11Window(window);
SurfaceDescriptorFromXlibWindow fromXlibWindow;
fromXlibWindow.chain.next = null;
fromXlibWindow.chain.sType = SType.SURFACE_DESCRIPTOR_FROM_XLIB_WINDOW;
fromXlibWindow.display = x11Display;
fromXlibWindow.window = x11Window;
SurfaceDescriptor surfaceDescriptor;
surfaceDescriptor.next = &fromXlibWindow.chain;
surfaceDescriptor.label = null;
return instance.createSurface(&surfaceDescriptor);
}
fn Surface createWaylandSurface(Instance instance, GlfwWindow window) {
WaylandDisplay waylandDisplay = glfwGetWaylandDisplay();
WaylandSurface waylandSurface = glfwGetWaylandWindow(window);
SurfaceSourceWaylandSurface fromWaylandWindow;
fromWaylandWindow.chain.next = null;
fromWaylandWindow.chain.sType = SType.SURFACE_DESCRIPTOR_FROM_WAYLAND_SURFACE;
fromWaylandWindow.display = waylandDisplay;
fromWaylandWindow.surface = waylandSurface;
SurfaceDescriptor surfaceDescriptor;
surfaceDescriptor.next = &fromWaylandWindow.chain;
surfaceDescriptor.label = null;
return instance.createSurface(&surfaceDescriptor);
}