diff --git a/README.md b/README.md index f6af9b8..d79baf9 100644 --- a/README.md +++ b/README.md @@ -35,8 +35,7 @@ pub fn build(b: *std.Build) void { .with_implot = true, }); exe.root_module.addImport("zgui", zgui.module("root")); - exe.linkLibrary(zgui.artifact("imgui")); - + { // Needed for glfw/wgpu rendering backend const zglfw = b.dependency("zglfw", .{}); exe.root_module.addImport("zglfw", zglfw.module("root")); diff --git a/build.zig b/build.zig index 3d56896..6848cce 100644 --- a/build.zig +++ b/build.zig @@ -67,7 +67,7 @@ pub fn build(b: *std.Build) void { const options_module = options_step.createModule(); - _ = b.addModule("root", .{ + const imgui = b.addModule("root", .{ .root_source_file = b.path("src/gui.zig"), .imports = &.{ .{ .name = "zgui_options", .module = options_module }, @@ -87,49 +87,24 @@ pub fn build(b: *std.Build) void { "-Wno-availability", }; - const imgui = if (options.shared) blk: { - const lib = b.addSharedLibrary(.{ - .name = "imgui", - .target = target, - .optimize = optimize, - }); - - if (target.result.os.tag == .windows) { - lib.root_module.addCMacro("IMGUI_API", "__declspec(dllexport)"); - lib.root_module.addCMacro("IMPLOT_API", "__declspec(dllexport)"); - lib.root_module.addCMacro("ZGUI_API", "__declspec(dllexport)"); - } - - if (target.result.os.tag == .macos) { - lib.linker_allow_shlib_undefined = true; - } - - break :blk lib; - } else b.addStaticLibrary(.{ - .name = "imgui", - .target = target, - .optimize = optimize, - }); - - b.installArtifact(imgui); - - const emscripten = target.result.os.tag == .emscripten; - if (emscripten) { - imgui.root_module.addCMacro("__EMSCRIPTEN__", ""); - // TODO: read from enviroment or `emcc --version` - imgui.root_module.addCMacro("__EMSCRIPTEN_major__", "3"); - imgui.root_module.addCMacro("__EMSCRIPTEN_minor__", "1"); - imgui.root_module.stack_protector = false; - //imgui.root_module.disable_stack_probing = true; - } + //Shared Library details + //if (target.result.os.tag == .macos) { + // lib.linker_allow_shlib_undefined = true; + //} + //if (target.result.os.tag == .windows) { + // imgui.addCMacro("IMGUI_API", "__declspec(dllexport)"); + // imgui.addCMacro("IMPLOT_API", "__declspec(dllexport)"); + // imgui.addCMacro("ZGUI_API", "__declspec(dllexport)"); + //} imgui.addIncludePath(b.path("libs")); imgui.addIncludePath(b.path("libs/imgui")); + const emscripten = target.result.os.tag == .emscripten; if (!emscripten) { - imgui.linkLibC(); + imgui.link_libc = true; if (target.result.abi != .msvc) - imgui.linkLibCpp(); + imgui.link_libcpp = true; } imgui.addCSourceFile(.{ @@ -156,11 +131,11 @@ pub fn build(b: *std.Build) void { .file = b.path("libs/imgui/misc/freetype/imgui_freetype.cpp"), .flags = cflags, }); - imgui.root_module.addCMacro("IMGUI_ENABLE_FREETYPE", "1"); + imgui.addCMacro("IMGUI_ENABLE_FREETYPE", "1"); } if (options.use_wchar32) { - imgui.root_module.addCMacro("IMGUI_USE_WCHAR32", "1"); + imgui.addCMacro("IMGUI_USE_WCHAR32", "1"); } if (options.with_implot) { @@ -215,8 +190,8 @@ pub fn build(b: *std.Build) void { .flags = cflags, }); - imgui.root_module.addCMacro("IMGUI_ENABLE_TEST_ENGINE", ""); - imgui.root_module.addCMacro("IMGUI_TEST_ENGINE_ENABLE_COROUTINE_STDTHREAD_IMPL", "1"); + imgui.addCMacro("IMGUI_ENABLE_TEST_ENGINE", ""); + imgui.addCMacro("IMGUI_TEST_ENGINE_ENABLE_COROUTINE_STDTHREAD_IMPL", "1"); imgui.addIncludePath(b.path("libs/imgui_test_engine/")); @@ -267,7 +242,6 @@ pub fn build(b: *std.Build) void { winpthreads.addIncludePath(b.path("libs/winpthreads/include")); winpthreads.addIncludePath(b.path("libs/winpthreads/src")); winpthreads.linkLibC(); - b.installArtifact(winpthreads); imgui.linkLibrary(winpthreads); imgui.addSystemIncludePath(b.path("libs/winpthreads/include")); } @@ -279,6 +253,13 @@ pub fn build(b: *std.Build) void { imgui.addSystemIncludePath(.{ .cwd_relative = b.pathJoin(&.{ b.sysroot.?, "include" }), }); + imgui.addCSourceFiles(.{ + .files = &.{ + "libs/imgui/backends/imgui_impl_glfw.cpp", + "libs/imgui/backends/imgui_impl_wgpu.cpp", + }, + .flags = cflags, + }); } else { if (b.lazyDependency("zglfw", .{})) |zglfw| { imgui.addIncludePath(zglfw.path("libs/glfw/include")); @@ -286,14 +267,14 @@ pub fn build(b: *std.Build) void { if (b.lazyDependency("zgpu", .{})) |zgpu| { imgui.addIncludePath(zgpu.path("libs/dawn/include")); } + imgui.addCSourceFiles(.{ + .files = &.{ + "libs/imgui/backends/imgui_impl_glfw.cpp", + "libs/imgui/backends/imgui_impl_wgpu.cpp", + }, + .flags = &(cflags.* ++ .{"-DIMGUI_IMPL_WEBGPU_BACKEND_WGPU"}), + }); } - imgui.addCSourceFiles(.{ - .files = &.{ - "libs/imgui/backends/imgui_impl_glfw.cpp", - "libs/imgui/backends/imgui_impl_wgpu.cpp", - }, - .flags = cflags, - }); }, .glfw_opengl3 => { if (b.lazyDependency("zglfw", .{})) |zglfw| { @@ -318,7 +299,7 @@ pub fn build(b: *std.Build) void { }, .flags = cflags, }); - imgui.linkSystemLibrary("d3dcompiler_47"); + imgui.linkSystemLibrary("d3dcompiler_47", .{}); }, .win32_dx12 => { imgui.addCSourceFiles(.{ @@ -328,11 +309,11 @@ pub fn build(b: *std.Build) void { }, .flags = cflags, }); - imgui.linkSystemLibrary("d3dcompiler_47"); - imgui.linkSystemLibrary("dwmapi"); + imgui.linkSystemLibrary("d3dcompiler_47", .{}); + imgui.linkSystemLibrary("dwmapi", .{}); switch (target.result.abi) { - .msvc => imgui.linkSystemLibrary("Gdi32"), - .gnu => imgui.linkSystemLibrary("gdi32"), + .msvc => imgui.linkSystemLibrary("Gdi32", .{}), + .gnu => imgui.linkSystemLibrary("gdi32", .{}), else => {}, } }, @@ -373,10 +354,10 @@ pub fn build(b: *std.Build) void { }); }, .osx_metal => { - imgui.linkFramework("Foundation"); - imgui.linkFramework("Metal"); - imgui.linkFramework("Cocoa"); - imgui.linkFramework("QuartzCore"); + imgui.linkFramework("Foundation", .{}); + imgui.linkFramework("Metal", .{}); + imgui.linkFramework("Cocoa", .{}); + imgui.linkFramework("QuartzCore", .{}); imgui.addCSourceFiles(.{ .files = &.{ "libs/imgui/backends/imgui_impl_osx.mm", @@ -406,7 +387,7 @@ pub fn build(b: *std.Build) void { b.installArtifact(tests); tests.root_module.addImport("zgui_options", options_module); - tests.linkLibrary(imgui); + tests.root_module.addImport("zgui", imgui); test_step.dependOn(&b.addRunArtifact(tests).step); } diff --git a/libs/imgui/backends/imgui_impl_wgpu.cpp b/libs/imgui/backends/imgui_impl_wgpu.cpp index b565c4d..26427ff 100644 --- a/libs/imgui/backends/imgui_impl_wgpu.cpp +++ b/libs/imgui/backends/imgui_impl_wgpu.cpp @@ -45,9 +45,6 @@ // When targeting native platforms (i.e. NOT emscripten), one of IMGUI_IMPL_WEBGPU_BACKEND_DAWN // or IMGUI_IMPL_WEBGPU_BACKEND_WGPU must be provided. See imgui_impl_wgpu.h for more details. -// FIX(zig-gamedev) -#define IMGUI_IMPL_WEBGPU_BACKEND_WGPU - #ifndef __EMSCRIPTEN__ #if defined(IMGUI_IMPL_WEBGPU_BACKEND_DAWN) == defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU) #error exactly one of IMGUI_IMPL_WEBGPU_BACKEND_DAWN or IMGUI_IMPL_WEBGPU_BACKEND_WGPU must be defined! @@ -836,8 +833,6 @@ bool ImGui_ImplWGPU_Init(ImGui_ImplWGPU_InitInfo* init_info) io.BackendRendererName = "imgui_impl_webgpu_emscripten"; #elif defined(IMGUI_IMPL_WEBGPU_BACKEND_DAWN) io.BackendRendererName = "imgui_impl_webgpu_dawn"; -#elif defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU) - io.BackendRendererName = "imgui_impl_webgpu_wgpu"; #else io.BackendRendererName = "imgui_impl_webgpu"; #endif diff --git a/libs/imgui/backends/imgui_impl_wgpu.h b/libs/imgui/backends/imgui_impl_wgpu.h index 0457a63..a8edb90 100644 --- a/libs/imgui/backends/imgui_impl_wgpu.h +++ b/libs/imgui/backends/imgui_impl_wgpu.h @@ -8,9 +8,6 @@ // This requirement will be removed once WebGPU stabilizes and backends converge on a unified interface. //#define IMGUI_IMPL_WEBGPU_BACKEND_DAWN -// FIX(zig-gamedev) -#define IMGUI_IMPL_WEBGPU_BACKEND_WGPU - // Implemented features: // [X] Renderer: User texture binding. Use 'WGPUTextureView' as ImTextureID. Read the FAQ about ImTextureID! // [X] Renderer: Large meshes support (64k+ vertices) even with 16-bit indices (ImGuiBackendFlags_RendererHasVtxOffset). diff --git a/src/gui.zig b/src/gui.zig index a2a7e73..ca4e0b1 100644 --- a/src/gui.zig +++ b/src/gui.zig @@ -1678,7 +1678,7 @@ const ImageButton = struct { pub fn imageButton(str_id: [:0]const u8, user_texture_id: TextureIdent, args: ImageButton) bool { return zguiImageButton( str_id, - user_texture_id, + @intFromPtr(user_texture_id), args.w, args.h, &args.uv0, @@ -1689,7 +1689,7 @@ pub fn imageButton(str_id: [:0]const u8, user_texture_id: TextureIdent, args: Im } extern fn zguiImageButton( str_id: [*:0]const u8, - user_texture_id: TextureIdent, + user_texture_id: u64, w: f32, h: f32, uv0: *const [2]f32,