Compare commits

..

11 Commits

Author SHA1 Message Date
Rekai Nyangadzayi Musuka 5149d4b1de fix: ensure that main.zig is removed 2023-06-19 10:51:43 -05:00
Rekai Nyangadzayi Musuka 11337f53c6 fix: restore import for glfw w/ opengl3 backend
rebase unalived that specific line. Whoops
2023-06-19 10:44:57 -05:00
Rekai Nyangadzayi Musuka 159eaf8c50 feat: prefer SDL.h instead of SDL/SDL.h on all supported platforms 2023-06-19 10:44:57 -05:00
Rekai Nyangadzayi Musuka ca6d7f02a4 chore: explicitly link SDL2
TODO: What happens on Windows? macOS?
2023-06-19 10:44:57 -05:00
Rekai Nyangadzayi Musuka 90390053e7 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-06-19 10:44:57 -05:00
Rekai Nyangadzayi Musuka a9bdeed635 feat: add sdl2-opengl3 backend impl 2023-06-19 10:44:57 -05:00
Rekai Nyangadzayi Musuka 709389942d chore: handle all cases of enum 2023-06-19 10:44:57 -05:00
Rekai Nyangadzayi Musuka 7bc8b8c014 chore: combine render() and draw() in backend 2023-06-19 10:44:57 -05:00
Rekai Nyangadzayi Musuka 1f42a3a6c7 feat: add backend impl for glfw+opengl3 2023-06-19 10:44:57 -05:00
Rekai Nyangadzayi Musuka 4a4c574f31 feat: add glfw+opengl3 backend option to build.zig 2023-06-19 10:44:57 -05:00
Rekai Nyangadzayi Musuka 0c69830356 chore: add necessary imgui files for opengl3 2023-06-19 10:44:57 -05:00
4 changed files with 22 additions and 118 deletions

View File

@ -41,7 +41,7 @@ pub fn newFrame(fb_width: u32, fb_height: u32) void {
ImGui_ImplWGPU_NewFrame(); ImGui_ImplWGPU_NewFrame();
ImGui_ImplGlfw_NewFrame(); ImGui_ImplGlfw_NewFrame();
gui.io.setDisplaySize(@as(f32, @floatFromInt(fb_width)), @as(f32, @floatFromInt(fb_height))); gui.io.setDisplaySize(@intToFloat(f32, fb_width), @intToFloat(f32, fb_height));
gui.io.setDisplayFramebufferScale(1.0, 1.0); gui.io.setDisplayFramebufferScale(1.0, 1.0);
gui.newFrame(); gui.newFrame();

View File

@ -51,7 +51,7 @@ pub fn deinit() void {
while (it.next()) |kv| { while (it.next()) |kv| {
const address = kv.key_ptr.*; const address = kv.key_ptr.*;
const size = kv.value_ptr.*; const size = kv.value_ptr.*;
mem_allocator.?.free(@as([*]align(mem_alignment) u8, @ptrFromInt(address))[0..size]); mem_allocator.?.free(@intToPtr([*]align(mem_alignment) u8, address)[0..size]);
std.log.info( std.log.info(
"[zgui] Possible memory leak or static memory usage detected: (address: 0x{x}, size: {d})", "[zgui] Possible memory leak or static memory usage detected: (address: 0x{x}, size: {d})",
.{ address, size }, .{ address, size },
@ -96,7 +96,7 @@ fn zguiMemAlloc(size: usize, _: ?*anyopaque) callconv(.C) ?*anyopaque {
size, size,
) catch @panic("zgui: out of memory"); ) catch @panic("zgui: out of memory");
mem_allocations.?.put(@intFromPtr(mem.ptr), size) catch @panic("zgui: out of memory"); mem_allocations.?.put(@ptrToInt(mem.ptr), size) catch @panic("zgui: out of memory");
return mem.ptr; return mem.ptr;
} }
@ -107,8 +107,8 @@ fn zguiMemFree(maybe_ptr: ?*anyopaque, _: ?*anyopaque) callconv(.C) void {
defer mem_mutex.unlock(); defer mem_mutex.unlock();
if (mem_allocations != null) { if (mem_allocations != null) {
const size = mem_allocations.?.fetchRemove(@intFromPtr(ptr)).?.value; const size = mem_allocations.?.fetchRemove(@ptrToInt(ptr)).?.value;
const mem = @as([*]align(mem_alignment) u8, @ptrCast(@alignCast(ptr)))[0..size]; const mem = @ptrCast([*]align(mem_alignment) u8, @alignCast(mem_alignment, ptr))[0..size];
mem_allocator.?.free(mem); mem_allocator.?.free(mem);
} }
} }
@ -181,7 +181,7 @@ pub const io = struct {
) Font; ) Font;
pub fn addFontFromMemory(fontdata: []const u8, size_pixels: f32) Font { pub fn addFontFromMemory(fontdata: []const u8, size_pixels: f32) Font {
return zguiIoAddFontFromMemory(fontdata.ptr, @as(i32, @intCast(fontdata.len)), size_pixels); return zguiIoAddFontFromMemory(fontdata.ptr, @intCast(i32, fontdata.len), size_pixels);
} }
extern fn zguiIoAddFontFromMemory(font_data: *const anyopaque, font_size: i32, size_pixels: f32) Font; extern fn zguiIoAddFontFromMemory(font_data: *const anyopaque, font_size: i32, size_pixels: f32) Font;
@ -193,7 +193,7 @@ pub const io = struct {
) Font { ) Font {
return zguiIoAddFontFromMemoryWithConfig( return zguiIoAddFontFromMemoryWithConfig(
fontdata.ptr, fontdata.ptr,
@as(i32, @intCast(fontdata.len)), @intCast(i32, fontdata.len),
size_pixels, size_pixels,
if (config) |c| &c else null, if (config) |c| &c else null,
ranges, ranges,
@ -844,10 +844,10 @@ pub const Style = extern struct {
extern fn zguiStyle_ScaleAllSizes(style: *Style, scale_factor: f32) void; extern fn zguiStyle_ScaleAllSizes(style: *Style, scale_factor: f32) void;
pub fn getColor(style: Style, idx: StyleCol) [4]f32 { pub fn getColor(style: Style, idx: StyleCol) [4]f32 {
return style.colors[@intFromEnum(idx)]; return style.colors[@enumToInt(idx)];
} }
pub fn setColor(style: *Style, idx: StyleCol, color: [4]f32) void { pub fn setColor(style: *Style, idx: StyleCol, color: [4]f32) void {
style.colors[@intFromEnum(idx)] = color; style.colors[@enumToInt(idx)] = color;
} }
}; };
/// `pub fn getStyle() *Style` /// `pub fn getStyle() *Style`
@ -3361,12 +3361,10 @@ pub const DrawCmd = extern struct {
vtx_offset: u32, vtx_offset: u32,
idx_offset: u32, idx_offset: u32,
elem_count: u32, elem_count: u32,
user_callback: ?DrawCallback, user_callback: ?*anyopaque,
user_callback_data: ?*anyopaque, user_callback_data: ?*anyopaque,
}; };
pub const DrawCallback = *const fn (*const anyopaque, *const DrawCmd) callconv(.C) void;
pub const getWindowDrawList = zguiGetWindowDrawList; pub const getWindowDrawList = zguiGetWindowDrawList;
pub const getBackgroundDrawList = zguiGetBackgroundDrawList; pub const getBackgroundDrawList = zguiGetBackgroundDrawList;
pub const getForegroundDrawList = zguiGetForegroundDrawList; pub const getForegroundDrawList = zguiGetForegroundDrawList;
@ -3750,7 +3748,7 @@ pub const DrawList = *opaque {
zguiDrawList_AddPolyline( zguiDrawList_AddPolyline(
draw_list, draw_list,
points.ptr, points.ptr,
@as(u32, @intCast(points.len)), @intCast(u32, points.len),
args.col, args.col,
args.flags, args.flags,
args.thickness, args.thickness,
@ -3773,7 +3771,7 @@ pub const DrawList = *opaque {
zguiDrawList_AddConvexPolyFilled( zguiDrawList_AddConvexPolyFilled(
draw_list, draw_list,
points.ptr, points.ptr,
@as(u32, @intCast(points.len)), @intCast(u32, points.len),
col, col,
); );
} }
@ -4155,15 +4153,5 @@ pub const DrawList = *opaque {
draw_list: DrawList, draw_list: DrawList,
idx: DrawIdx, idx: DrawIdx,
) void; ) void;
//---------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------
pub fn addCallback(draw_list: DrawList, callback: DrawCallback, callback_data: ?*anyopaque) void {
zguiDrawList_AddCallback(draw_list, callback, callback_data);
}
extern fn zguiDrawList_AddCallback(draw_list: DrawList, callback: DrawCallback, callback_data: ?*anyopaque) void;
pub fn addResetRenderStateCallback(draw_list: DrawList) void {
zguiDrawList_AddResetRenderStateCallback(draw_list);
}
extern fn zguiDrawList_AddResetRenderStateCallback(draw_list: DrawList) void;
}; };

View File

@ -92,10 +92,10 @@ pub const Style = extern struct {
extern fn zguiPlotStyle_Init() Style; extern fn zguiPlotStyle_Init() Style;
pub fn getColor(style: Style, idx: StyleCol) [4]f32 { pub fn getColor(style: Style, idx: StyleCol) [4]f32 {
return style.colors[@intFromEnum(idx)]; return style.colors[@enumToInt(idx)];
} }
pub fn setColor(style: *Style, idx: StyleCol, color: [4]f32) void { pub fn setColor(style: *Style, idx: StyleCol, color: [4]f32) void {
style.colors[@intFromEnum(idx)] = color; style.colors[@enumToInt(idx)] = color;
} }
}; };
/// `pub fn getStyle() *Style` /// `pub fn getStyle() *Style`
@ -281,9 +281,9 @@ pub fn setupAxis(axis: Axis, args: SetupAxis) void {
extern fn zguiPlot_SetupAxis(axis: Axis, label: ?[*:0]const u8, flags: AxisFlags) void; extern fn zguiPlot_SetupAxis(axis: Axis, label: ?[*:0]const u8, flags: AxisFlags) void;
//---------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------
pub const Condition = enum(u32) { pub const Condition = enum(u32) {
none = @intFromEnum(gui.Condition.none), none = @enumToInt(gui.Condition.none),
always = @intFromEnum(gui.Condition.always), always = @enumToInt(gui.Condition.always),
once = @intFromEnum(gui.Condition.once), once = @enumToInt(gui.Condition.once),
}; };
const SetupAxisLimits = struct { const SetupAxisLimits = struct {
min: f64, min: f64,
@ -363,7 +363,7 @@ pub fn plotLineValues(label_id: [:0]const u8, comptime T: type, args: PlotLineVa
label_id, label_id,
gui.typeToDataTypeEnum(T), gui.typeToDataTypeEnum(T),
args.v.ptr, args.v.ptr,
@as(i32, @intCast(args.v.len)), @intCast(i32, args.v.len),
args.xscale, args.xscale,
args.xstart, args.xstart,
args.flags, args.flags,
@ -399,7 +399,7 @@ pub fn plotLine(label_id: [:0]const u8, comptime T: type, args: PlotLineGen(T))
gui.typeToDataTypeEnum(T), gui.typeToDataTypeEnum(T),
args.xv.ptr, args.xv.ptr,
args.yv.ptr, args.yv.ptr,
@as(i32, @intCast(args.xv.len)), @intCast(i32, args.xv.len),
args.flags, args.flags,
args.offset, args.offset,
args.stride, args.stride,
@ -445,7 +445,7 @@ pub fn plotScatterValues(label_id: [:0]const u8, comptime T: type, args: PlotSca
label_id, label_id,
gui.typeToDataTypeEnum(T), gui.typeToDataTypeEnum(T),
args.v.ptr, args.v.ptr,
@as(i32, @intCast(args.v.len)), @intCast(i32, args.v.len),
args.xscale, args.xscale,
args.xstart, args.xstart,
args.flags, args.flags,
@ -481,7 +481,7 @@ pub fn plotScatter(label_id: [:0]const u8, comptime T: type, args: PlotScatterGe
gui.typeToDataTypeEnum(T), gui.typeToDataTypeEnum(T),
args.xv.ptr, args.xv.ptr,
args.yv.ptr, args.yv.ptr,
@as(i32, @intCast(args.xv.len)), @intCast(i32, args.xv.len),
args.flags, args.flags,
args.offset, args.offset,
args.stride, args.stride,
@ -518,7 +518,7 @@ pub fn plotShaded(label_id: [:0]const u8, comptime T: type, args: PlotShadedGen(
gui.typeToDataTypeEnum(T), gui.typeToDataTypeEnum(T),
args.xv.ptr, args.xv.ptr,
args.yv.ptr, args.yv.ptr,
@as(i32, @intCast(args.xv.len)), @intCast(i32, args.xv.len),
args.yref, args.yref,
args.flags, args.flags,
args.offset, args.offset,
@ -536,54 +536,6 @@ extern fn zguiPlot_PlotShaded(
offset: i32, offset: i32,
stride: i32, stride: i32,
) void; ) void;
//----------------------------------------------------------------------------------------------
pub const DragToolFlags = packed struct(u32) {
no_cursors: bool = false,
no_fit: bool = false,
no_no_inputs: bool = false,
delayed: bool = false,
_padding: u28 = 0,
};
const DragPoint = struct {
x: *f64,
y: *f64,
col: [4]f32,
size: f32 = 4,
flags: DragToolFlags = .{},
};
pub fn dragPoint(id: i32, args: DragPoint) bool {
return zguiPlot_DragPoint(
id,
args.x,
args.y,
&args.col,
args.size,
args.flags,
);
}
extern fn zguiPlot_DragPoint(id: i32, x: *f64, y: *f64, *const [4]f32, size: f32, flags: DragToolFlags) bool;
//----------------------------------------------------------------------------------------------
// PlotText
const PlotTextFlags = packed struct(u32) {
vertical: bool = false,
_padding: u31 = 0,
};
const PlotText = struct {
x: f64,
y: f64,
pix_offset: [2]f32 = .{ 0, 0 },
flags: PlotTextFlags = .{},
};
pub fn plotText(text: [*:0]const u8, args:PlotText) void {
zguiPlot_PlotText(text, args.x, args.y, &args.pix_offset, args.flags);
}
extern fn zguiPlot_PlotText(
text:[*:0]const u8,
x:f64, y:f64,
pix_offset: *const [2]f32,
flags: PlotTextFlags,
) void;
//---------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------
/// `pub fn showDemoWindow(popen: ?*bool) void` /// `pub fn showDemoWindow(popen: ?*bool) void`

View File

@ -2089,14 +2089,6 @@ ZGUI_API void zguiDrawList_PrimWriteVtx(
ZGUI_API void zguiDrawList_PrimWriteIdx( ImDrawList* draw_list, ImDrawIdx idx) { ZGUI_API void zguiDrawList_PrimWriteIdx( ImDrawList* draw_list, ImDrawIdx idx) {
draw_list->PrimWriteIdx(idx); draw_list->PrimWriteIdx(idx);
} }
ZGUI_API void zguiDrawList_AddCallback(ImDrawList* draw_list, ImDrawCallback callback, void* callback_data) {
draw_list->AddCallback(callback, callback_data);
}
ZGUI_API void zguiDrawList_AddResetRenderStateCallback(ImDrawList* draw_list) {
draw_list->AddCallback(ImDrawCallback_ResetRenderState, NULL);
}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
// //
// Viewport // Viewport
@ -2362,33 +2354,5 @@ ZGUI_API void zguiPlot_ShowDemoWindow(bool* p_open) {
ZGUI_API void zguiPlot_EndPlot(void) { ZGUI_API void zguiPlot_EndPlot(void) {
ImPlot::EndPlot(); ImPlot::EndPlot();
} }
ZGUI_API bool zguiPlot_DragPoint(
int id,
double* x,
double* y,
float col[4],
float size,
ImPlotDragToolFlags flags
) {
return ImPlot::DragPoint(
id,
x,
y,
(*(const ImVec4*)&(col[0])),
size,
flags
);
}
ZGUI_API void zguiPlot_PlotText(
const char* text,
double x, double y,
const float pix_offset[2],
ImPlotTextFlags flags=0
) {
const ImVec2 p(pix_offset[0], pix_offset[1]);
ImPlot::PlotText(text, x, y, p, flags);
}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
} /* extern "C" */ } /* extern "C" */