summaryrefslogtreecommitdiff
path: root/examples/shaders/build.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-16 21:28:20 -0300
committerGabriel Schneider <[email protected]>2026-11-16 21:28:20 -0300
commit6933f99ddb2d7103515d26838496309a807bba26 (patch)
tree991c2fe7d4a57957222876e190fa4d16a0fb889c /examples/shaders/build.zig
parent82fca5c9f29124f37f6dcd08e73e6999ce44a69d (diff)
downloadsketchbook-6933f99ddb2d7103515d26838496309a807bba26.tar.gz
sketchbook-6933f99ddb2d7103515d26838496309a807bba26.zip
Move standalone sketches into sketchbook examples
Diffstat (limited to 'examples/shaders/build.zig')
-rw-r--r--examples/shaders/build.zig41
1 files changed, 41 insertions, 0 deletions
diff --git a/examples/shaders/build.zig b/examples/shaders/build.zig
new file mode 100644
index 0000000..3a20bbf
--- /dev/null
+++ b/examples/shaders/build.zig
@@ -0,0 +1,41 @@
+const std = @import("std");
+const sketchbook = @import("sketchbook");
+
+/// The Book of Shaders examples, each written twice: `shaders/zig/<name>.zig`
+/// and `shaders/glsl/<name>.frag`.
+const examples = [_][]const u8{ "expo", "hsb_wheel", "polar", "truchet", "clouds" };
+
+pub fn build(b: *std.Build) void {
+ const target = b.standardTargetOptions(.{});
+ const optimize = b.standardOptimizeOption(.{});
+ const sb = sketchbook.init(b, .{ .target = target, .optimize = optimize });
+
+ const uniforms = b.createModule(.{ .root_source_file = b.path("src/uniforms.zig") });
+ var glsl_sources: std.ArrayList(std.Build.LazyPath) = .empty;
+ var zig_sources: std.ArrayList(std.Build.LazyPath) = .empty;
+ glsl_sources.append(b.graph.arena, b.path("shaders/glsl/fullscreen.vert")) catch @panic("OOM");
+ zig_sources.append(b.graph.arena, b.path("shaders/zig/fullscreen.zig")) catch @panic("OOM");
+ for (examples) |name| {
+ glsl_sources.append(b.graph.arena, b.path(b.fmt("shaders/glsl/{s}.frag", .{name}))) catch @panic("OOM");
+ zig_sources.append(b.graph.arena, b.path(b.fmt("shaders/zig/{s}.zig", .{name}))) catch @panic("OOM");
+ }
+ const glsl = sb.addShaders(.{ .layouts = .{ .module = uniforms, .types = &.{"Uniforms"} }, .sources = glsl_sources.items });
+ const gl = b.createModule(.{ .root_source_file = b.path("shaders/zig/gl.zig"), .imports = &.{.{ .name = "uniforms", .module = uniforms }} });
+ const zig = sb.addZigShaders(.{ .sources = zig_sources.items, .imports = &.{.{ .name = "gl", .module = gl }} });
+
+ const app = sb.app(.{ .name = "shaders", .root_source_file = b.path("src/main.zig"), .imports = &.{
+ .{ .name = "uniforms", .module = uniforms },
+ .{ .name = "glsl_shaders", .module = glsl.module },
+ .{ .name = "zig_shaders", .module = zig.module },
+ } });
+ const steps = app.addSteps(.{ .web = .{}, .scripts = &.{ b.path("test/shaders.script"), b.path("test/timeline.script") } });
+
+ // Hot reload keeps State through an edit of each kind: a Zig shader, a
+ // GLSL shader, and the sketch's own Zig code.
+ const reload = app.addReloadCheck(.{ .script = b.path("test/reload.script"), .edits = &.{
+ .{ .file = "shaders/zig/expo.zig", .old = ".{ 0, 1, 0 }", .new = ".{ 1, 0, 0 }" },
+ .{ .file = "shaders/glsl/expo.frag", .old = "vec3(0.0, 1.0, 0.0)", .new = "vec3(1.0, 0.0, 0.0)" },
+ .{ .file = "src/main.zig", .old = "0xff8040", .new = "0x40c0ff" },
+ } });
+ steps.e2e.dependOn(&reload.run.step);
+}