ImGui demo window

This commit is contained in:
David Allemang
2024-07-01 17:24:04 -04:00
parent bc4421b754
commit 154427d5bc
8 changed files with 196 additions and 4 deletions

View File

@@ -5,8 +5,7 @@ const shaders = @import("shaders");
const Allocator = std.mem.Allocator;
const au = @import("au.zig");
const app_name = "vulkan-zig triangle example";
const im = @import("cimgui");
const Vertex = extern struct {
const binding_description = vk.VertexInputBindingDescription{
@@ -50,7 +49,6 @@ const vertices = [_]Vertex{
const indices = [_]Index{ 4, 5, 6, 6, 5, 7 };
const Frame = struct {
pub fn init() !Frame {
return .{};
@@ -132,6 +130,8 @@ const Frame = struct {
// vkd.cmdBindIndexBuffer(cmdbuf, index_buffer, 0, .uint16);
// vkd.cmdDrawIndexed(cmdbuf, indices.len, 1, 0, 0, 0);
im.c.ImGui_ImplVulkan_RenderDrawData(im.c.igGetDrawData(), @ptrFromInt(@intFromEnum(cmd.handle)), null);
cmd.endRendering();
cmd.pipelineBarrier(
@@ -163,6 +163,10 @@ const Frame = struct {
}
};
pub fn loader_wrapper(procname: [*c]const u8, _: ?*anyopaque) callconv(.C) vk.PfnVoidFunction {
return c.glfwGetInstanceProcAddress(au.I.handle, procname);
}
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.detectLeaks();
@@ -177,7 +181,65 @@ pub fn main() !void {
var flights = try au.Flights(Frame).init(alloc, 3); // FRAMES IN FLIGHT
defer flights.deinit();
const ctx = im.c.igCreateContext(null) orelse return error.igCreateContextFailed;
defer im.c.igDestroyContext(ctx);
// _ = im.c.ImGui_ImplGlfw_InitForOther(@ptrCast(au.W.handle), true);
// defer im.c.ImGui_ImplGlfw_Shutdown();
const descriptorPool = try au.D.createDescriptorPool(&vk.DescriptorPoolCreateInfo{
.flags = .{ .free_descriptor_set_bit = true },
.pool_size_count = 1,
.p_pool_sizes = &.{
vk.DescriptorPoolSize{ .descriptor_count = 32, .type = .combined_image_sampler },
},
.max_sets = 32,
}, null);
defer au.D.destroyDescriptorPool(descriptorPool, null);
_ = im.c.ImGui_ImplVulkan_LoadFunctions(loader_wrapper, null);
_ = im.c.ImGui_ImplGlfw_InitForVulkan(@ptrCast(au.W.handle), true);
defer im.c.ImGui_ImplGlfw_Shutdown();
_ = try sc.rebuild();
const prci: vk.PipelineRenderingCreateInfo = .{
.view_mask = 0,
.depth_attachment_format = .undefined,
.stencil_attachment_format = .undefined,
.color_attachment_count = 1,
.p_color_attachment_formats = &.{au.device_config.format.format},
};
var info: im.c.ImGui_ImplVulkan_InitInfo = .{
.Instance = @ptrFromInt(@intFromEnum(au.I.handle)),
.PhysicalDevice = @ptrFromInt(@intFromEnum(au.device_config.pdev)),
.Device = @ptrFromInt(@intFromEnum(au.D.handle)),
.QueueFamily = au.device_config.family,
.Queue = @ptrFromInt(@intFromEnum(au.Q.handle)),
.DescriptorPool = @ptrFromInt(@intFromEnum(descriptorPool)),
.RenderPass = null,
.MinImageCount = sc.cinfo.min_image_count,
.ImageCount = @intCast(sc.images.items.len),
.PipelineRenderingCreateInfo = @bitCast(prci),
.MSAASamples = 0,
.PipelineCache = null,
.Subpass = 0,
.UseDynamicRendering = true,
.Allocator = null,
};
_ = im.c.ImGui_ImplVulkan_Init(&info);
_ = im.c.ImGui_ImplVulkan_CreateFontsTexture();
defer im.c.ImGui_ImplVulkan_Shutdown();
while (!au.W.should_close()) {
im.c.ImGui_ImplGlfw_NewFrame();
im.c.ImGui_ImplVulkan_NewFrame();
im.c.igNewFrame();
im.c.igShowDemoWindow(null);
im.c.igEndFrame();
im.c.igRender();
const flight = flights.next();
const events = if (au.W.focused())