Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.
/ zig-naga-oil Public archive

Zig wrapper for naga_oil Rust crate

Notifications You must be signed in to change notification settings

prime31/zig-naga-oil

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

zig-naga-oil

Zig wrapper for naga_oil Rust crate

Build Rust

  • cargo build --release: builds static lib for the current platform
  • cargo build --release --target x86_64-pc-windows-gnu: cross compiles

Add Package to Your Project

const oil_build = @import("path/to/naga_oil/build.zig");
const exe = b.createExe(...);

oil_build.linkArtifact(exe);
exe.addModule("naga_oil", oil_build.getModule(b));

Usage

const oil = @import("oil");

// optionally import types
const Composer = oil.Composer;
const Module = oil.Module;
const ShaderDefs = oil.ShaderDefs;
const Source = oil.Source;

// create a Composer
const composer = Composer.init();
defer composer.deinit();

// add source code modules to the Composer
try composer.addComposableModule(.{
    .source = @embedFile("utils.wgsl"),
    .file_path = "shaders/utils.wgsl",
});

// optionally create ShaderDefs for conditinal compilation
const shader_defs = ShaderDefs.init();

shader_defs.insertBool("HAS_TANGENTS", true);
shader_defs.insertU32("MAX_LIGHTS", 256);

// create a Module with the main shader file
const module = try composer.makeNagaModule(.{
    .source = @embedFile("pbr.wgsl"),
    .file_path = "shaders/pbr.wgsl",
    .shader_defs = shader_defs,
});

// generate the shader source
const source = module.toSource();
defer source.deinit();
std.debug.print("shader: {}\n", .{source.source});

About

Zig wrapper for naga_oil Rust crate

Resources

Stars

Watchers

Forks