From 963fae202108acd0498349e872e4811fa6c6aba0 Mon Sep 17 00:00:00 2001 From: Nic Gaffney Date: Wed, 12 Jun 2024 21:15:52 -0500 Subject: Added imgui for configuration --- vendor/zgui/src/backend_glfw_wgpu.zig | 67 +++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 vendor/zgui/src/backend_glfw_wgpu.zig (limited to 'vendor/zgui/src/backend_glfw_wgpu.zig') diff --git a/vendor/zgui/src/backend_glfw_wgpu.zig b/vendor/zgui/src/backend_glfw_wgpu.zig new file mode 100644 index 0000000..e6fa517 --- /dev/null +++ b/vendor/zgui/src/backend_glfw_wgpu.zig @@ -0,0 +1,67 @@ +const gui = @import("gui.zig"); +const backend_glfw = @import("backend_glfw.zig"); + +// This call will install GLFW callbacks to handle GUI interactions. +// Those callbacks will chain-call user's previously installed callbacks, if any. +// This means that custom user's callbacks need to be installed *before* calling zgpu.gui.init(). +pub fn init( + window: *const anyopaque, // zglfw.Window + wgpu_device: *const anyopaque, // wgpu.Device + wgpu_swap_chain_format: u32, // wgpu.TextureFormat + wgpu_depth_format: u32, // wgpu.TextureFormat +) void { + backend_glfw.init(window); + + var info = ImGui_ImplWGPU_InitInfo{ + .device = wgpu_device, + .num_frames_in_flight = 1, + .rt_format = wgpu_swap_chain_format, + .depth_format = wgpu_depth_format, + .pipeline_multisample_state = .{}, + }; + + if (!ImGui_ImplWGPU_Init(&info)) { + unreachable; + } +} + +pub fn deinit() void { + ImGui_ImplWGPU_Shutdown(); + backend_glfw.deinit(); +} + +pub fn newFrame(fb_width: u32, fb_height: u32) void { + ImGui_ImplWGPU_NewFrame(); + backend_glfw.newFrame(); + + gui.io.setDisplaySize(@floatFromInt(fb_width), @floatFromInt(fb_height)); + gui.io.setDisplayFramebufferScale(1.0, 1.0); + + gui.newFrame(); +} + +pub fn draw(wgpu_render_pass: *const anyopaque) void { + gui.render(); + ImGui_ImplWGPU_RenderDrawData(gui.getDrawData(), wgpu_render_pass); +} + +pub const ImGui_ImplWGPU_InitInfo = extern struct { + device: *const anyopaque, + num_frames_in_flight: u32 = 1, + rt_format: u32, + depth_format: u32, + + pipeline_multisample_state: extern struct { + next_in_chain: ?*const anyopaque = null, + count: u32 = 1, + mask: u32 = @bitCast(@as(i32, -1)), + alpha_to_coverage_enabled: bool = false, + }, +}; + +// Those functions are defined in 'imgui_impl_wgpu.cpp` +// (they include few custom changes). +extern fn ImGui_ImplWGPU_Init(init_info: *ImGui_ImplWGPU_InitInfo) bool; +extern fn ImGui_ImplWGPU_NewFrame() void; +extern fn ImGui_ImplWGPU_RenderDrawData(draw_data: *const anyopaque, pass_encoder: *const anyopaque) void; +extern fn ImGui_ImplWGPU_Shutdown() void; -- cgit v1.2.3