ziglana/zig13-metal
Zig 0.13 bindings for Apple's Metal API.
This library is currently in alpha stage, don't use it in any serious projects!
Bindings are automatically generated using zig and libclang, but there are still some issues with the code generation. The source code for the generator can be found here: https://github.com/dmbfm/zig-metal-gen.
In the examples folder you can find a few samples which were directly translated from apple's metal-cpp samples.
Copy or clone zig-metal
to a subdirectory of your project. For instance, if
you copy it to libs/zig-metal
you should add this to your build.zig
:
const zig_metal = @import("libs/zig-metal/build.zig");
pub fn build(b: *std.Build) void {
...
const zig_metal_pkg = zig_metal.package(b);
zig_metal_pkg.link(exe);
exe.linkFramework("Foundation");
exe.linkFramework("Metal");
exe.linkFramework("AppKit"); // If on macOS
exe.linkFramework("MetalKit"); // If using MTKView
...
}
All of the metal API and parts of the Foundation API which Metal depends on
can are directly imported in the root zig-metal namespace, so you can access
them via @import("zig-metal").MTLDevice, @import("zig-metal").NSString
, etc.
Additionally some basic AppKit bindings can be found in the extras.appkit
namespace, and basic MetalKit bindings in the extras.metalkit
namespace.
You can find some usage examples in the examples
folder. These are
translations from Apple's samples for metal-cpp.
zig build run-window
zig build run-primitive
zig build run-argbuffers
zig build run-animation
zig build run-instancing
zig build run-perspective
zig build run-lighting
zig build run-texturing
zig build run-compute
zig build run-compute-to-render