Compare commits

..

11 Commits

Author SHA1 Message Date
Rekai Nyangadzayi Musuka 25fa193b1f fix: ensure that main.zig is removed 2023-07-11 00:47:32 -05:00
Rekai Nyangadzayi Musuka 334c021350 fix: restore import for glfw w/ opengl3 backend
rebase unalived that specific line. Whoops
2023-07-11 00:47:32 -05:00
Rekai Nyangadzayi Musuka 2894f69c2f feat: prefer SDL.h instead of SDL/SDL.h on all supported platforms 2023-07-11 00:47:32 -05:00
Rekai Nyangadzayi Musuka be835bb15b chore: explicitly link SDL2
TODO: What happens on Windows? macOS?
2023-07-11 00:47:32 -05:00
Rekai Nyangadzayi Musuka a2e5652678 fix: vcpkg stores SDL.h under SDL2 folder
macOS and Linux seem to not, so in order to get CI working again I
should make use of the preprocessor.

FIXME: I think this makes vcpkg a **hard** requirement which perhaps
isn't ideal if I want ZBA to be as easy to build as possible. I should
try ensuring that building w/out vcpkg works as well
2023-07-11 00:47:32 -05:00
Rekai Nyangadzayi Musuka 925ff4b50a feat: add sdl2-opengl3 backend impl 2023-07-11 00:47:32 -05:00
Rekai Nyangadzayi Musuka 1ff2abf816 chore: handle all cases of enum 2023-07-11 00:47:32 -05:00
Rekai Nyangadzayi Musuka 367dd7a99e chore: combine render() and draw() in backend 2023-07-11 00:47:32 -05:00
Rekai Nyangadzayi Musuka c7d1c329a1 feat: add backend impl for glfw+opengl3 2023-07-11 00:47:32 -05:00
Rekai Nyangadzayi Musuka 6c56505fa6 feat: add glfw+opengl3 backend option to build.zig 2023-07-11 00:47:32 -05:00
Rekai Nyangadzayi Musuka 9964c55136 chore: add necessary imgui files for opengl3 2023-07-11 00:47:32 -05:00
4 changed files with 24 additions and 130 deletions

View File

@ -11,10 +11,6 @@ pub const Backend = enum {
pub const Options = struct { pub const Options = struct {
backend: Backend, backend: Backend,
shared: bool = false, shared: bool = false,
/// use bundled imgui source
with_imgui: bool = true,
/// use bundled implot source
with_implot: bool = true,
}; };
pub const Package = struct { pub const Package = struct {
@ -71,55 +67,40 @@ pub fn package(
.optimize = optimize, .optimize = optimize,
}); });
zgui_c_cpp.addIncludePath(.{ .path = thisDir() ++ "/libs" }); zgui_c_cpp.addIncludePath(thisDir() ++ "/libs");
zgui_c_cpp.addIncludePath(.{ .path = thisDir() ++ "/libs/imgui" }); zgui_c_cpp.addIncludePath(thisDir() ++ "/libs/imgui");
zgui_c_cpp.linkLibC(); zgui_c_cpp.linkLibC();
zgui_c_cpp.linkLibCpp(); zgui_c_cpp.linkLibCpp();
const cflags = &.{"-fno-sanitize=undefined"}; const cflags = &.{"-fno-sanitize=undefined"};
zgui_c_cpp.addCSourceFile(.{ zgui_c_cpp.addCSourceFile(thisDir() ++ "/src/zgui.cpp", cflags);
.file = .{ .path = thisDir() ++ "/src/zgui.cpp" },
.flags = cflags,
});
if (args.options.with_imgui) { zgui_c_cpp.addCSourceFile(thisDir() ++ "/libs/imgui/imgui.cpp", cflags);
zgui_c_cpp.addCSourceFiles(&.{ zgui_c_cpp.addCSourceFile(thisDir() ++ "/libs/imgui/imgui_widgets.cpp", cflags);
thisDir() ++ "/libs/imgui/imgui.cpp", zgui_c_cpp.addCSourceFile(thisDir() ++ "/libs/imgui/imgui_tables.cpp", cflags);
thisDir() ++ "/libs/imgui/imgui_widgets.cpp", zgui_c_cpp.addCSourceFile(thisDir() ++ "/libs/imgui/imgui_draw.cpp", cflags);
thisDir() ++ "/libs/imgui/imgui_tables.cpp", zgui_c_cpp.addCSourceFile(thisDir() ++ "/libs/imgui/imgui_demo.cpp", cflags);
thisDir() ++ "/libs/imgui/imgui_draw.cpp",
thisDir() ++ "/libs/imgui/imgui_demo.cpp",
}, cflags);
}
if (args.options.with_implot) { zgui_c_cpp.addCSourceFile(thisDir() ++ "/libs/imgui/implot_demo.cpp", cflags);
zgui_c_cpp.addCSourceFiles(&.{ zgui_c_cpp.addCSourceFile(thisDir() ++ "/libs/imgui/implot.cpp", cflags);
thisDir() ++ "/libs/imgui/implot_demo.cpp", zgui_c_cpp.addCSourceFile(thisDir() ++ "/libs/imgui/implot_items.cpp", cflags);
thisDir() ++ "/libs/imgui/implot.cpp",
thisDir() ++ "/libs/imgui/implot_items.cpp",
}, cflags);
}
switch (args.options.backend) { switch (args.options.backend) {
.glfw_wgpu => { .glfw_wgpu => {
zgui_c_cpp.addIncludePath(.{ .path = thisDir() ++ "/../zglfw/libs/glfw/include" }); zgui_c_cpp.addIncludePath(thisDir() ++ "/../zglfw/libs/glfw/include");
zgui_c_cpp.addIncludePath(.{ .path = thisDir() ++ "/../zgpu/libs/dawn/include" }); zgui_c_cpp.addIncludePath(thisDir() ++ "/../zgpu/libs/dawn/include");
zgui_c_cpp.addCSourceFiles(&.{ zgui_c_cpp.addCSourceFile(thisDir() ++ "/libs/imgui/backends/imgui_impl_glfw.cpp", cflags);
thisDir() ++ "/libs/imgui/backends/imgui_impl_glfw.cpp", zgui_c_cpp.addCSourceFile(thisDir() ++ "/libs/imgui/backends/imgui_impl_wgpu.cpp", cflags);
thisDir() ++ "/libs/imgui/backends/imgui_impl_wgpu.cpp",
}, cflags);
}, },
.glfw_opengl3 => { .glfw_opengl3 => {
zgui_c_cpp.addCSourceFile(thisDir() ++ "/libs/imgui/backends/imgui_impl_glfw.cpp", cflags); zgui_c_cpp.addCSourceFile(thisDir() ++ "/libs/imgui/backends/imgui_impl_glfw.cpp", cflags);
zgui_c_cpp.addCSourceFile(thisDir() ++ "/libs/imgui/backends/imgui_impl_opengl3.cpp", cflags); zgui_c_cpp.addCSourceFile(thisDir() ++ "/libs/imgui/backends/imgui_impl_opengl3.cpp", cflags);
}, },
.win32_dx12 => { .win32_dx12 => {
zgui_c_cpp.addCSourceFiles(&.{ zgui_c_cpp.addCSourceFile(thisDir() ++ "/libs/imgui/backends/imgui_impl_win32.cpp", cflags);
thisDir() ++ "/libs/imgui/backends/imgui_impl_win32.cpp", zgui_c_cpp.addCSourceFile(thisDir() ++ "/libs/imgui/backends/imgui_impl_dx12.cpp", cflags);
thisDir() ++ "/libs/imgui/backends/imgui_impl_dx12.cpp",
}, cflags);
zgui_c_cpp.linkSystemLibraryName("d3dcompiler_47"); zgui_c_cpp.linkSystemLibraryName("d3dcompiler_47");
zgui_c_cpp.linkSystemLibraryName("dwmapi"); zgui_c_cpp.linkSystemLibraryName("dwmapi");
}, },

View File

@ -539,14 +539,11 @@ static void ImGui_ImplWGPU_CreateFontsTexture()
// Create the associated sampler // Create the associated sampler
// (Bilinear sampling is required by default. Set 'io.Fonts->Flags |= ImFontAtlasFlags_NoBakedLines' or 'style.AntiAliasedLinesUseTex = false' to allow point/nearest sampling) // (Bilinear sampling is required by default. Set 'io.Fonts->Flags |= ImFontAtlasFlags_NoBakedLines' or 'style.AntiAliasedLinesUseTex = false' to allow point/nearest sampling)
{ {
const WGPUMipmapFilterMode mipmap_filter_mode = g_config.texture_filter_mode == 1 ? WGPUMipmapFilterMode_Linear : WGPUMipmapFilterMode_Nearest;
const WGPUFilterMode filter_mode = g_config.texture_filter_mode == 1 ? WGPUFilterMode_Linear : WGPUFilterMode_Nearest; const WGPUFilterMode filter_mode = g_config.texture_filter_mode == 1 ? WGPUFilterMode_Linear : WGPUFilterMode_Nearest;
WGPUSamplerDescriptor sampler_desc = {}; WGPUSamplerDescriptor sampler_desc = {};
sampler_desc.minFilter = filter_mode; sampler_desc.minFilter = filter_mode;
sampler_desc.magFilter = filter_mode; sampler_desc.magFilter = filter_mode;
sampler_desc.mipmapFilter = mipmap_filter_mode; sampler_desc.mipmapFilter = filter_mode;
sampler_desc.addressModeU = WGPUAddressMode_Repeat; sampler_desc.addressModeU = WGPUAddressMode_Repeat;
sampler_desc.addressModeV = WGPUAddressMode_Repeat; sampler_desc.addressModeV = WGPUAddressMode_Repeat;
sampler_desc.addressModeW = WGPUAddressMode_Repeat; sampler_desc.addressModeW = WGPUAddressMode_Repeat;

View File

@ -226,10 +226,6 @@ pub const io = struct {
pub const getFontsTexId = zguiIoGetFontsTexId; pub const getFontsTexId = zguiIoGetFontsTexId;
extern fn zguiIoGetFontsTexId() TextureIdent; extern fn zguiIoGetFontsTexId() TextureIdent;
/// `pub fn zguiIoSetConfigWindowsMoveFromTitleBarOnly(bool) void`
pub const setConfigWindowsMoveFromTitleBarOnly = zguiIoSetConfigWindowsMoveFromTitleBarOnly;
extern fn zguiIoSetConfigWindowsMoveFromTitleBarOnly(enabled: bool) void;
/// `pub fn zguiIoGetWantCaptureMouse() bool` /// `pub fn zguiIoGetWantCaptureMouse() bool`
pub const getWantCaptureMouse = zguiIoGetWantCaptureMouse; pub const getWantCaptureMouse = zguiIoGetWantCaptureMouse;
extern fn zguiIoGetWantCaptureMouse() bool; extern fn zguiIoGetWantCaptureMouse() bool;
@ -1165,13 +1161,6 @@ pub const setMouseCursor = zguiSetMouseCursor;
extern fn zguiGetMouseCursor() Cursor; extern fn zguiGetMouseCursor() Cursor;
extern fn zguiSetMouseCursor(cursor: Cursor) void; extern fn zguiSetMouseCursor(cursor: Cursor) void;
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
pub fn getMousePos() [2]f32 {
var pos: [2]f32 = undefined;
zguiGetMousePos(&pos);
return pos;
}
extern fn zguiGetMousePos(pos: *[2]f32) void;
//--------------------------------------------------------------------------------------------------
/// `pub fn alignTextToFramePadding() void` /// `pub fn alignTextToFramePadding() void`
pub const alignTextToFramePadding = zguiAlignTextToFramePadding; pub const alignTextToFramePadding = zguiAlignTextToFramePadding;
/// `pub fn getTextLineHeight() f32` /// `pub fn getTextLineHeight() f32`
@ -1463,43 +1452,6 @@ pub fn combo(label: [:0]const u8, args: Combo) bool {
args.popup_max_height_in_items, args.popup_max_height_in_items,
); );
} }
/// creates a combo box directly from a pointer to an enum value using zig's
/// comptime mechanics to infer the items for the list at compile time
pub fn comboFromEnum(
label: [:0]const u8,
/// must be a pointer to an enum value (var my_enum: *FoodKinds = .Banana)
/// that is backed by some kind of integer that can safely cast into an
/// i32 (the underlying imgui restriction)
current_item: anytype,
) bool {
const item_names = comptime lbl: {
const item_type = @typeInfo(@TypeOf(current_item.*));
switch (item_type) {
.Enum => |e| {
comptime var str: [:0]const u8 = "";
inline for (e.fields) |f| {
str = str ++ f.name ++ "\x00";
}
break :lbl str;
},
else => {
@compileError("Error: current_item must be a pointer-to-an-enum, not a " ++ @TypeOf(current_item));
},
}
};
var item: i32 = @intCast(@intFromEnum(current_item.*));
const result = combo(label, .{
.items_separated_by_zeros = item_names,
.current_item = &item,
});
current_item.* = @enumFromInt(item);
return result;
}
extern fn zguiCombo( extern fn zguiCombo(
label: [*:0]const u8, label: [*:0]const u8,
current_item: *i32, current_item: *i32,
@ -2909,8 +2861,8 @@ pub const BeginTable = struct {
outer_size: [2]f32 = .{ 0, 0 }, outer_size: [2]f32 = .{ 0, 0 },
inner_width: f32 = 0, inner_width: f32 = 0,
}; };
pub fn beginTable(name: [:0]const u8, args: BeginTable) bool { pub fn beginTable(name: [:0]const u8, args: BeginTable) void {
return zguiBeginTable(name, args.column, args.flags, &args.outer_size, args.inner_width); zguiBeginTable(name, args.column, args.flags, &args.outer_size, args.inner_width);
} }
extern fn zguiBeginTable( extern fn zguiBeginTable(
str_id: [*:0]const u8, str_id: [*:0]const u8,
@ -2918,7 +2870,7 @@ extern fn zguiBeginTable(
flags: TableFlags, flags: TableFlags,
outer_size: *const [2]f32, outer_size: *const [2]f32,
inner_width: f32, inner_width: f32,
) bool; ) void;
pub fn endTable() void { pub fn endTable() void {
zguiEndTable(); zguiEndTable();
@ -3018,11 +2970,6 @@ pub const MouseButton = enum(u32) {
right = 1, right = 1,
middle = 2, middle = 2,
}; };
/// `pub fn isMouseDown(mouse_button: MouseButton) bool`
pub const isMouseDown = zguiIsMouseDown;
/// `pub fn isMouseClicked(mouse_button: MouseButton) bool`
pub const isMouseClicked = zguiIsMouseClicked;
/// `pub fn isMouseDoubleClicked(mouse_button: MouseButton) bool` /// `pub fn isMouseDoubleClicked(mouse_button: MouseButton) bool`
pub const isMouseDoubleClicked = zguiIsMouseDoubleClicked; pub const isMouseDoubleClicked = zguiIsMouseDoubleClicked;
/// `pub fn isItemClicked(mouse_button: MouseButton) bool` /// `pub fn isItemClicked(mouse_button: MouseButton) bool`
@ -3045,8 +2992,6 @@ pub const isAnyItemHovered = zguiIsAnyItemHovered;
pub const isAnyItemActive = zguiIsAnyItemActive; pub const isAnyItemActive = zguiIsAnyItemActive;
/// `pub fn isAnyItemFocused() bool` /// `pub fn isAnyItemFocused() bool`
pub const isAnyItemFocused = zguiIsAnyItemFocused; pub const isAnyItemFocused = zguiIsAnyItemFocused;
extern fn zguiIsMouseDown(mouse_button: MouseButton) bool;
extern fn zguiIsMouseClicked(mouse_button: MouseButton) bool;
extern fn zguiIsMouseDoubleClicked(mouse_button: MouseButton) bool; extern fn zguiIsMouseDoubleClicked(mouse_button: MouseButton) bool;
extern fn zguiIsItemHovered(flags: HoveredFlags) bool; extern fn zguiIsItemHovered(flags: HoveredFlags) bool;
extern fn zguiIsItemActive() bool; extern fn zguiIsItemActive() bool;
@ -3231,8 +3176,6 @@ pub fn beginPopupModal(name: [:0]const u8, args: Begin) bool {
pub fn openPopup(str_id: [:0]const u8, flags: PopupFlags) void { pub fn openPopup(str_id: [:0]const u8, flags: PopupFlags) void {
zguiOpenPopup(str_id, flags); zguiOpenPopup(str_id, flags);
} }
/// `pub fn beginPopup(str_id: [:0]const u8, flags: WindowFlags) bool`
pub const beginPopup = zguiBeginPopup;
/// `pub fn endPopup() void` /// `pub fn endPopup() void`
pub const endPopup = zguiEndPopup; pub const endPopup = zguiEndPopup;
/// `pub fn closeCurrentPopup() void` /// `pub fn closeCurrentPopup() void`
@ -3240,7 +3183,6 @@ pub const closeCurrentPopup = zguiCloseCurrentPopup;
extern fn zguiBeginPopupContextWindow() bool; extern fn zguiBeginPopupContextWindow() bool;
extern fn zguiBeginPopupContextItem() bool; extern fn zguiBeginPopupContextItem() bool;
extern fn zguiBeginPopupModal(name: [*:0]const u8, popen: ?*bool, flags: WindowFlags) bool; extern fn zguiBeginPopupModal(name: [*:0]const u8, popen: ?*bool, flags: WindowFlags) bool;
extern fn zguiBeginPopup(str_id: [*:0]const u8, flags: WindowFlags) bool;
extern fn zguiEndPopup() void; extern fn zguiEndPopup() void;
extern fn zguiOpenPopup(str_id: [*:0]const u8, flags: PopupFlags) void; extern fn zguiOpenPopup(str_id: [*:0]const u8, flags: PopupFlags) void;
extern fn zguiCloseCurrentPopup() void; extern fn zguiCloseCurrentPopup() void;

View File

@ -260,12 +260,6 @@ ZGUI_API void zguiSetMouseCursor(int cursor) {
ImGui::SetMouseCursor(cursor); ImGui::SetMouseCursor(cursor);
} }
ZGUI_API void zguiGetMousePos(float pos[2]) {
const ImVec2 p = ImGui::GetMousePos();
pos[0] = p.x;
pos[1] = p.y;
}
ZGUI_API void zguiAlignTextToFramePadding(void) { ZGUI_API void zguiAlignTextToFramePadding(void) {
ImGui::AlignTextToFramePadding(); ImGui::AlignTextToFramePadding();
} }
@ -1084,10 +1078,6 @@ ZGUI_API bool zguiTreeNode(const char* label) {
return ImGui::TreeNode(label); return ImGui::TreeNode(label);
} }
ZGUI_API bool zguiTreeNodeFlags(const char* label, ImGuiTreeNodeFlags flags) {
return ImGui::TreeNodeEx(label, flags);
}
ZGUI_API bool zguiTreeNodeStrId(const char* str_id, const char* fmt, ...) { ZGUI_API bool zguiTreeNodeStrId(const char* str_id, const char* fmt, ...) {
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
@ -1242,10 +1232,6 @@ ZGUI_API ImTextureID zguiIoGetFontsTexId(void) {
return ImGui::GetIO().Fonts->TexID; return ImGui::GetIO().Fonts->TexID;
} }
ZGUI_API void zguiIoSetConfigWindowsMoveFromTitleBarOnly(bool enabled) {
ImGui::GetIO().ConfigWindowsMoveFromTitleBarOnly = enabled;
}
ZGUI_API bool zguiIoGetWantCaptureMouse(void) { ZGUI_API bool zguiIoGetWantCaptureMouse(void) {
return ImGui::GetIO().WantCaptureMouse; return ImGui::GetIO().WantCaptureMouse;
} }
@ -1329,14 +1315,6 @@ ZGUI_API bool zguiIsItemClicked(ImGuiMouseButton mouse_button) {
return ImGui::IsItemClicked(mouse_button); return ImGui::IsItemClicked(mouse_button);
} }
ZGUI_API bool zguiIsMouseDown(ImGuiMouseButton button) {
return ImGui::IsMouseDown(button);
}
ZGUI_API bool zguiIsMouseClicked(ImGuiMouseButton button) {
return ImGui::IsMouseClicked(button);
}
ZGUI_API bool zguiIsMouseDoubleClicked(ImGuiMouseButton button) { ZGUI_API bool zguiIsMouseDoubleClicked(ImGuiMouseButton button) {
return ImGui::IsMouseDoubleClicked(button); return ImGui::IsMouseDoubleClicked(button);
} }
@ -1469,10 +1447,6 @@ ZGUI_API void zguiEndTooltip(void) {
ImGui::EndTooltip(); ImGui::EndTooltip();
} }
ZGUI_API bool zguiBeginPopup(const char* str_id, ImGuiWindowFlags flags){
return ImGui::BeginPopup(str_id, flags);
}
ZGUI_API bool zguiBeginPopupContextWindow(void) { ZGUI_API bool zguiBeginPopupContextWindow(void) {
return ImGui::BeginPopupContextWindow(); return ImGui::BeginPopupContextWindow();
} }
@ -1501,14 +1475,14 @@ ZGUI_API void zguiCloseCurrentPopup(void) {
// Tables // Tables
// //
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
ZGUI_API bool zguiBeginTable( ZGUI_API void zguiBeginTable(
const char* str_id, const char* str_id,
int column, int column,
ImGuiTableFlags flags, ImGuiTableFlags flags,
const float outer_size[2], const float outer_size[2],
float inner_width float inner_width
) { ) {
return ImGui::BeginTable(str_id, column, flags, { outer_size[0], outer_size[1] }, inner_width); ImGui::BeginTable(str_id, column, flags, { outer_size[0], outer_size[1] }, inner_width);
} }
ZGUI_API void zguiEndTable(void) { ZGUI_API void zguiEndTable(void) {
@ -2407,7 +2381,7 @@ ZGUI_API bool zguiPlot_DragPoint(
} }
ZGUI_API void zguiPlot_PlotText( ZGUI_API void zguiPlot_PlotText(
const char* text, const char* text,
double x, double y, double x, double y,
const float pix_offset[2], const float pix_offset[2],
ImPlotTextFlags flags=0 ImPlotTextFlags flags=0