extract imgui setup
This commit is contained in:
61
src/main.zig
61
src/main.zig
@@ -5,10 +5,10 @@ const shaders = @import("shaders");
|
||||
const Allocator = std.mem.Allocator;
|
||||
|
||||
const au = @import("au.zig");
|
||||
const im = @import("cimgui");
|
||||
|
||||
const Uber = @import("Uber.zig");
|
||||
|
||||
const ui = @import("au/ui.zig");
|
||||
|
||||
const vertices = [_]Uber.Vertex{
|
||||
// Vulkan depth range is 0, 1 instead of OpenGL -1, 1
|
||||
.{ .pos = .{ -0.5, -0.5, -0.5, 1.0 }, .color = .{ 1, 0, 0 } },
|
||||
@@ -69,14 +69,22 @@ pub fn main() !void {
|
||||
try au.init(alloc);
|
||||
defer au.deinit();
|
||||
|
||||
{
|
||||
const props = au.I.getPhysicalDeviceProperties(au.device_config.pdev);
|
||||
std.debug.print(
|
||||
"Selected Device:\n {s}\n mode: {}\n",
|
||||
.{ props.device_name, au.device_config.mode },
|
||||
);
|
||||
}
|
||||
|
||||
var sc = try au.SwapChain.init(alloc);
|
||||
defer sc.deinit();
|
||||
|
||||
var flights = try au.Flights.init(alloc, 3); // FRAMES IN FLIGHT
|
||||
defer flights.deinit();
|
||||
|
||||
const ctx = im.c.igCreateContext(null) orelse return error.igCreateContextFailed;
|
||||
defer im.c.igDestroyContext(ctx);
|
||||
const ctx = try ui.init(flights.flights.len);
|
||||
defer ui.deinit(ctx);
|
||||
|
||||
const descriptorPool = try au.D.createDescriptorPool(&vk.DescriptorPoolCreateInfo{
|
||||
.flags = .{ .free_descriptor_set_bit = true },
|
||||
@@ -88,41 +96,8 @@ pub fn main() !void {
|
||||
}, 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 = 2,
|
||||
.ImageCount = @intCast(flights.flights.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();
|
||||
|
||||
const cache = try au.D.createPipelineCache(&vk.PipelineCacheCreateInfo{}, null);
|
||||
defer au.D.destroyPipelineCache(cache, null);
|
||||
|
||||
@@ -130,6 +105,7 @@ pub fn main() !void {
|
||||
defer uber.deinit();
|
||||
|
||||
const vkalloc = au.VkAllocator.init();
|
||||
std.debug.print("heaps: {any}\ntypes: {any}\n", .{ vkalloc.heaps(), vkalloc.types() });
|
||||
|
||||
const vertex_buffer = try au.D.createBuffer(&vk.BufferCreateInfo{
|
||||
.size = @sizeOf(@TypeOf(vertices)),
|
||||
@@ -220,12 +196,9 @@ pub fn main() !void {
|
||||
const rand = prng.random();
|
||||
|
||||
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();
|
||||
ui.NewFrame();
|
||||
ui.igShowMetricsWindow(null);
|
||||
ui.EndFrame();
|
||||
|
||||
const flight = flights.next();
|
||||
|
||||
@@ -267,7 +240,7 @@ pub fn main() !void {
|
||||
index_buffer,
|
||||
descriptorSet,
|
||||
);
|
||||
im.c.ImGui_ImplVulkan_RenderDrawData(im.c.igGetDrawData(), @ptrFromInt(@intFromEnum(cmd.handle)), null);
|
||||
ui.Draw(cmd);
|
||||
tgt.end_rendering(cmd);
|
||||
|
||||
for (vertex_data) |*v| {
|
||||
|
Reference in New Issue
Block a user