Shader compile step

This commit is contained in:
duck
2025-03-28 01:02:56 +05:00
parent c95a5e7d1c
commit 5513044d61
5 changed files with 33 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
#version 450
layout(location = 0) in vec2 fragCoord;
layout(location = 0) out vec4 fragColor;
void main() {
fragColor = vec4(fragCoord, 0.0, 1.0);
}

View File

@@ -0,0 +1,8 @@
#version 450
layout(location = 0) in vec2 inCoord;
layout(location = 0) out vec2 outCoord;
void main() {
outCoord = inCoord;
}

View File

@@ -1,5 +1,10 @@
const std = @import("std"); const std = @import("std");
const SHADERS: []const struct { file: []const u8, stage: []const u8 } = &.{
.{ .file = "basic", .stage = "vert" },
.{ .file = "basic", .stage = "frag" },
};
pub fn build(b: *std.Build) void { pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{}); const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{}); const optimize = b.standardOptimizeOption(.{});
@@ -14,6 +19,16 @@ pub fn build(b: *std.Build) void {
exe.linkLibC(); exe.linkLibC();
exe.linkSystemLibrary("SDL3"); exe.linkSystemLibrary("SDL3");
inline for (SHADERS) |shader| {
const glslc = b.addSystemCommand(&.{"glslc"});
glslc.addArg("-fshader-stage=" ++ shader.stage);
glslc.addFileArg(b.path("assets/shaders/" ++ shader.file ++ "." ++ shader.stage));
glslc.addArg("-o");
const filename = shader.file ++ "_" ++ shader.stage ++ ".spv";
const shader_artifact = glslc.addOutputFileArg(filename);
b.getInstallStep().dependOn(&b.addInstallFileWithDir(shader_artifact, .prefix, filename).step);
}
const run_cmd = b.addRunArtifact(exe); const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep()); run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| { if (b.args) |args| {

View File

@@ -6,5 +6,6 @@
"build.zig", "build.zig",
"build.zig.zon", "build.zig.zon",
"src", "src",
"assets",
}, },
} }

1
src/graphics.zig Normal file
View File

@@ -0,0 +1 @@
const sdl = @import("sdl.zig");