easy comptime hooks

This commit is contained in:
2024-07-09 23:35:40 -04:00
parent cb8684cbf3
commit cc1a9fdabc
5 changed files with 69 additions and 68 deletions

View File

@@ -12,6 +12,8 @@ const Window = @import("Window.zig");
const im = @import("cimgui");
pub usingnamespace im;
pub const Options = struct {};
pub fn loader_wrapper(procname: [*c]const u8, _: ?*anyopaque) callconv(.C) vk.PfnVoidFunction {
return au.glfwGetInstanceProcAddress(au.I.handle, procname);
}
@@ -75,34 +77,30 @@ pub fn init() !void {
if (!im.impl.ImGui_ImplVulkan_CreateFontsTexture()) {
return error.igVulkanFontTextureFailed;
}
try Render.add_present_callback(present);
errdefer Render.remove_present_callback(present);
}
pub fn frame() void {
pub fn nu_frame() !void {
im.impl.ImGui_ImplGlfw_NewFrame();
im.impl.ImGui_ImplVulkan_NewFrame();
im.igNewFrame();
im.igShowDemoWindow(null);
try nu.invoke_hook("nu_imgui_frame", .{});
im.igEndFrame();
im.igRender();
}
pub fn deinit() void {
Render.remove_present_callback(present);
im.impl.ImGui_ImplVulkan_Shutdown();
au.D.destroyDescriptorPool(descriptor_pool, null);
im.impl.ImGui_ImplGlfw_Shutdown();
im.igDestroyContext(ctx);
}
pub fn present(cmd: au.CommandBufferProxy) void {
pub fn nu_render_present(cmd: au.CommandBufferProxy) void {
im.impl.ImGui_ImplVulkan_RenderDrawData(
@ptrCast(im.igGetDrawData()),
@ptrFromInt(@intFromEnum(cmd.handle)),
null,
);
}
pub fn deinit() void {
im.impl.ImGui_ImplVulkan_Shutdown();
au.D.destroyDescriptorPool(descriptor_pool, null);
im.impl.ImGui_ImplGlfw_Shutdown();
im.igDestroyContext(ctx);
}