well-behaved swapchain

This commit is contained in:
David Allemang
2024-11-25 12:06:27 -05:00
parent ae37fc2ad3
commit 3e4b70573c
6 changed files with 83 additions and 61 deletions

View File

@@ -54,6 +54,8 @@ pub fn setup(_: std.mem.Allocator) !void {
null,
) orelse std.debug.panic("GLFW Create Window Failed", .{});
_ = c.glfwSetFramebufferSizeCallback(handle, &resize_callback);
// bus.connect(handle);
// errdefer bus.disconnect(handle);
}
@@ -75,3 +77,19 @@ pub fn next() bool {
return true;
}
var _resize_callbacks: std.BoundedArray(*const fn (u32, u32) void, 16) = .{};
fn resize_callback(_: ?*c.GLFWwindow, w: c_int, h: c_int) callconv(.C) void {
for (_resize_callbacks.slice()) |cb| {
cb(@intCast(w), @intCast(h));
}
}
pub fn add_resize_callback(cb: *const fn (u32, u32) void) void {
_resize_callbacks.appendAssumeCapacity(cb);
}
pub fn set_title(title: [:0]const u8) void {
c.glfwSetWindowTitle(handle, title);
}