commit e7a7f0e33865a00e05e3fbafe46e61c69ca2c34c
parent 241edb630712713e8eec757b07da82c642f7e544
Author: Christian Ermann <christianermann@gmail.com>
Date: Tue, 23 Apr 2024 20:15:16 -0400
Add mach-gpu
Diffstat:
3 files changed, 24 insertions(+), 4 deletions(-)
diff --git a/build.zig b/build.zig
@@ -1,4 +1,5 @@
const std = @import("std");
+const gpu = @import("mach-gpu");
// Although this function looks imperative, note that its job is to
// declaratively construct a build graph that will be executed by an external
@@ -40,7 +41,14 @@ pub fn build(b: *std.Build) void {
.target = target,
.optimize = optimize,
});
- exe.root_module.addImport("mach-glfw", glfw_dep.module("mach-glfw"));
+ exe.root_module.addImport("mach_glfw", glfw_dep.module("mach-glfw"));
+
+ const gpu_dep = b.dependency("mach-gpu", .{
+ .target = target,
+ .optimize = optimize,
+ });
+ exe.root_module.addImport("mach_gpu", gpu_dep.module("mach-gpu"));
+ try gpu.link(gpu_dep.builder, exe, &exe.root_module, .{});
// This declares intent for the executable to be installed into the
// standard location when the user invokes the "install" step (the default
diff --git a/build.zig.zon b/build.zig.zon
@@ -19,6 +19,10 @@
.url = "https://pkg.machengine.org/mach-glfw/e57190c095097810980703aa26d4f0669a21dbab.tar.gz",
.hash = "12205a32c8e6ca23c68191b1e95405d2bd5f8e3055cba1c8ce0738d673ef49aef913",
},
+ .@"mach-gpu" = .{
+ .url = "https://pkg.machengine.org/mach-gpu/528dad0823dafeae5d474c88cc658b091bf2e605.tar.gz",
+ .hash = "1220fe2e555ca66741539bc0f97769b2513c5e609c968d27eb8997f577a1d195f048",
+ },
},
.paths = .{
// This makes *all* files, recursively, included in this package. It is generally
diff --git a/src/main.zig b/src/main.zig
@@ -1,5 +1,6 @@
const std = @import("std");
-const glfw = @import("mach-glfw");
+const glfw = @import("mach_glfw");
+const gpu = @import("mach_gpu");
fn errorCallback(error_code: glfw.ErrorCode, description: [:0]const u8) void {
std.log.err("glfw: {}: {s}\n", .{ error_code, description });
@@ -13,8 +14,10 @@ pub fn main() !void {
}
defer glfw.terminate();
- const window = glfw.Window.create(640, 480, "Hello, World!", null, null, .{}) orelse {
- std.log.err("failed to create GLFW window: {?s}", .{glfw.getErrorString()});
+ const title = "Hello, World!";
+ const window = glfw.Window.create(640, 480, title, null, null, .{}) orelse {
+ const msg = "failed to create GLFW window: {?s}";
+ std.log.err(msg, .{glfw.getErrorString()});
std.process.exit(1);
};
defer window.destroy();
@@ -23,4 +26,9 @@ pub fn main() !void {
window.swapBuffers();
glfw.pollEvents();
}
+
+ var gpa = std.heap.GeneralPurposeAllocator(.{}){};
+ const allocator = gpa.allocator();
+
+ try gpu.Impl.init(allocator, .{});
}