2022-07-27 10:05:27 +00:00
|
|
|
const std = @import("std");
|
|
|
|
const glfw = @import("glfw");
|
|
|
|
const assert = std.debug.assert;
|
|
|
|
const ig = @import("imgui");
|
|
|
|
const ig_impl_glfw = @import("imgui_impl_glfw.zig");
|
|
|
|
|
|
|
|
const ProfileMark = @import("../common/profiler.zig").ProfileMark;
|
|
|
|
|
|
|
|
// TODO memory
|
|
|
|
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
|
|
|
const allocator = gpa.allocator();
|
|
|
|
|
2022-07-27 10:08:22 +00:00
|
|
|
pub fn init(window: *glfw.Window) !void {
|
2022-07-27 10:05:27 +00:00
|
|
|
ig.CHECKVERSION();
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
//ig.SetAllocatorFunctions(igAlloc, igFree);
|
|
|
|
|
|
|
|
_ = ig.CreateContext();
|
|
|
|
errdefer ig.DestroyContext();
|
|
|
|
|
2022-07-27 10:08:22 +00:00
|
|
|
if (!ig_impl_glfw.InitForVulkan(window, false)) {
|
2022-07-27 10:05:27 +00:00
|
|
|
return error.ImGuiFailedToInitialize;
|
|
|
|
}
|
|
|
|
|
|
|
|
ig.StyleColorsDark();
|
|
|
|
_ = window;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn deinit() void {
|
|
|
|
ig_impl_glfw.Shutdown();
|
|
|
|
ig.DestroyContext();
|
|
|
|
}
|
|
|
|
|
|
|
|
const pm_beginframe = ProfileMark.init("ui.beginFrame");
|
|
|
|
pub fn beginFrame() void {
|
|
|
|
pm_beginframe.begin();
|
|
|
|
defer pm_beginframe.end();
|
|
|
|
|
|
|
|
ig_impl_glfw.NewFrame();
|
|
|
|
ig.NewFrame();
|
|
|
|
}
|
|
|
|
|
|
|
|
const pm_endframe = ProfileMark.init("ui.endFrame");
|
|
|
|
pub fn endFrame() void {
|
|
|
|
pm_endframe.begin();
|
|
|
|
defer pm_endframe.end();
|
|
|
|
|
|
|
|
ig.EndFrame();
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
//fn igAlloc(sz: usize, user_data: ?*anyopaque) callconv(.C) ?*anyopaque {
|
|
|
|
// _ = user_data;
|
|
|
|
// const mem = allocator.alloc(u8, sz) catch return null;
|
|
|
|
// return @ptrCast(*anyopaque, mem);
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//fn igFree(ptr: ?*anyopaque, user_data: ?*anyopaque) callconv(.C) void {
|
|
|
|
// _ = user_data;
|
|
|
|
// if (ptr) |p| allocator.free(@ptrCast([*]u8, p));
|
|
|
|
//}
|