Skip to content

Commit

Permalink
glfw: can now create a wayland surface
Browse files Browse the repository at this point in the history
  • Loading branch information
D-Berg committed Dec 8, 2024
1 parent 897aaf4 commit e0c59fa
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
29 changes: 26 additions & 3 deletions src/glfw.zig
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,9 @@ pub fn GetWGPUSurface(window: Window, instance: Instance) wgpu.WGPUError!Surface
return try GetWGPUMetalSurface(window, instance);
},
.linux => {

switch (display_server) {
.X11 => return try GetWGPUX11Surface(window, instance),
.Wayland => @compileError("not yet implemented")
.Wayland => return try GetWGPUWaylandSurface(window, instance)
}
},
.windows => {
Expand Down Expand Up @@ -203,9 +202,33 @@ fn GetWGPUX11Surface(window: Window, instance: Instance) wgpu.WGPUError!Surface

return try instance.CreateSurface(&surface_desc);
}


extern "c" fn glfwGetWaylandDisplay() ?*anyopaque;
extern "c" fn glfwGetWaylandWindow(handle: *GLFWwindow) ?*anyopaque;
fn GetWGPUWaylandSurface(window: Window, instance: Instance) wgpu.WGPUError!Surface {

const wl_display = glfwGetWaylandDisplay() orelse
return wgpu.WGPUError.FailedToCreateSurface;

const wl_surface = glfwGetWaylandWindow(window._impl) orelse
return wgpu.WGPUError.FailedToCreateSurface;

const fromWaland = Surface.DescriptorFromWaylandSurface{
.chain = .{ .sType = .SurfaceDescriptorFromWaylandSurface },
.display = wl_display,
.surface = wl_surface
};

const surface_desc = Surface.Descriptor{
.nextInChain = &fromWaland.chain
};

return try instance.CreateSurface(&surface_desc);
}

// TODO: Shouldnt be pub
pub extern "c" fn glfwGetCocoaWindow(window: *GLFWwindow) *anyopaque;

/// setup_metal_leayer.m
pub extern "c" fn setupMetalLayer(window: *anyopaque) *anyopaque;
/// Works only for metal as of now
Expand Down
6 changes: 6 additions & 0 deletions src/wgpu/Surface.zig
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ pub const DescriptorFromXlibWindow = extern struct {
window: u64,
};

pub const DescriptorFromWaylandSurface = extern struct {
chain: ChainedStruct,
display: *anyopaque,
surface: *anyopaque
};

extern "c" fn wgpuSurfaceRelease(surface: SurfaceImpl) void;
pub fn Release(surface: Surface) void {

Expand Down

0 comments on commit e0c59fa

Please sign in to comment.