- Zig 94.9%
- C 4.3%
- HTML 0.8%
| examples | GLFW support and running examples. | |
| src | Format generated bindings. | |
| .gitignore | Initial import. | |
| build.zig | Update dependencies. | |
| build.zig.zon | Update emsdkz. | |
| LICENSE-APACHE | Initial import. | |
| LICENSE-MIT | Initial import. | |
| README.md | Enable emscripten builds and documentation. | |
WGPUZ
WebGPU integration and bindings for Zig. Can be used either as a raw C library via the wgpuz.c module, or with lightweight Zig bindings via the wgpuz.wgpu module. Includes optional support for GLFW to configure window surfaces. The GLFW support is found in wgpuz.glfwz.
Getting Started
On the command line.
zig fetch --save=wgpuz git+https://codeberg.org/scriblz/wgpuz
In build.zig
fn(b:*std.Build)void{constwgpuz_dep=b.dependency("wgpuz",.{.target=target,.optimize=optimize,});constmod=b.addModule(...);mod.addImport("wgpuz",wgpuz_dep.module("wgpuz"));}For usage, see the Examples.
C Library
WGPUZ translates the WebGPU header file and links against Dawn, wgpu-native, or emdawnwebgpu depending on the target OS and build options.
The C API can be accessed directly via wgpuz.c. The C module uses Zig's TranslateC to produce the API.
constwgpuz=@import("wgpuz");constwgpu_c=wgpuz.c;Supported OS/WebGPU Backend
Yes - supported backend for target OS No - not currently supported, should be added and tested N/A - no planned support
| Target OS | Dawn | wgpu-native |
|---|---|---|
| Mac OS | Yes | No |
| Windows | No | No |
| Linux | No | No |
| Emscripten | Yes | N/A |
WGPU Zig Wrapper
WGPUZ generates Zig bindings to WebGPU using bindz. The bindings are very lightweight, and don't require any memory allocations. The bindings are more friendly to work with than directly with the C API. See the code in the examples directory for usage.
GLFW Support
GLFW support is optional and will currently link GLFW to your project if enabled. To enable GLFW support, modify your build.zig file as so:
fn(b:*std.Build)void{constwgpuz_dep=b.dependency("wgpuz",.{.target=target,.optimize=optimize,.glfw_support=true,});}Enabling GLFW support will link GLFW 3.4 into your project and provide 2 helper functions for working with GLFW/WebGPU. The C API to GLFW is available via wgpuz.c. The support functions are available via wgpuz.glfwz.GlfwUtil. For usage, see examples/main.zig.
GLFW Support Helper Functions
| Function | Description |
|---|---|
| createWindowSurface | Creates a WebGPU surface from a GLFW Window |
| configureWindowHdr | Configures the underlying Window layer for rendering HDR content |
Emscripten Support
Emscripten is a supported build target, simply pass the current build target to the wgpuz dependency, and you should be set. Emscripten support is provided by emsdkz.
Examples
The examples executable allows running an example in a GLFW window. In order to run an example, use the following command on the command line:
zig build examples -- <example name>
For emscripten:
# NOTE: does not work with latest version of Zig
zig build examples -Dtarget=wasm32-emscripten \
-Dbrowser=chrome \ # optional specify browser to run
-- <example name>
List of Examples
| Example Name | Description |
|---|---|
| triangle | A simple triangle with a solid color |
| rotating_cube | A rotating cube with a color gradient |