summaryrefslogtreecommitdiff
path: root/src/glsl.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-28 21:07:13 -0300
committerGabriel Schneider <[email protected]>2026-11-12 13:22:02 -0300
commit590ba7b9b579b97e34b51ab7e3460ebc85713343 (patch)
tree6a73a7570ff4f79f41deff078455877b9bc6571b /src/glsl.zig
parentbc8e6eb1bfef0c5e9b3c40fc1e4fd5a1659e2b03 (diff)
downloadsketchbook-590ba7b9b579b97e34b51ab7e3460ebc85713343.tar.gz
sketchbook-590ba7b9b579b97e34b51ab7e3460ebc85713343.zip
sketchbook: Zig 0.17, a Store on disk, requests, a scope (waveform, spectrum, spectrogram), audio codecs and fonts, web host
Diffstat (limited to 'src/glsl.zig')
-rw-r--r--src/glsl.zig20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/glsl.zig b/src/glsl.zig
index 995985b..a1cd2d6 100644
--- a/src/glsl.zig
+++ b/src/glsl.zig
@@ -27,10 +27,10 @@ pub fn source(comptime T: type, comptime name: []const u8) []const u8 {
comptime {
@setEvalBranchQuota(100_000);
const tag = T.glsl;
- const fields = @typeInfo(T).@"struct".fields;
+ const s = @typeInfo(T).@"struct";
var out: []const u8 = "// Generated from the Zig struct " ++ @typeName(T) ++ "; do not edit.\n";
if (@TypeOf(tag) == @TypeOf(.enum_literal) and tag == .vertex) {
- for (fields, 0..) |f, i| out = out ++ std.fmt.comptimePrint("layout(location = {d}) in {s} {s};\n", .{ i, typeName(f.type, .vertex), f.name });
+ for (s.field_names, s.field_types, 0..) |name_, F, i| out = out ++ std.fmt.comptimePrint("layout(location = {d}) in {s} {s};\n", .{ i, typeName(F, .vertex), name_ });
} else if (@TypeOf(tag) == @TypeOf(.enum_literal) and tag == .plain) {
out = out ++ "struct " ++ name ++ " {\n" ++ members(T) ++ "};\n";
} else if (@hasField(@TypeOf(tag), "uniform")) {
@@ -46,15 +46,16 @@ pub fn source(comptime T: type, comptime name: []const u8) []const u8 {
fn members(comptime T: type) []const u8 {
comptime {
var out: []const u8 = "";
- for (@typeInfo(T).@"struct".fields) |f| {
- const array_of_composites = switch (@typeInfo(f.type)) {
+ const s = @typeInfo(T).@"struct";
+ for (s.field_names, s.field_types) |name, F| {
+ const array_of_composites = switch (@typeInfo(F)) {
.array => |a| @typeInfo(a.child) == .array or @typeInfo(a.child) == .@"struct",
else => false,
};
out = out ++ if (array_of_composites)
- std.fmt.comptimePrint(" {s} {s}[{d}];\n", .{ typeName(@typeInfo(f.type).array.child, .uniform), f.name, @typeInfo(f.type).array.len })
+ std.fmt.comptimePrint(" {s} {s}[{d}];\n", .{ typeName(@typeInfo(F).array.child, .uniform), name, @typeInfo(F).array.len })
else
- std.fmt.comptimePrint(" {s} {s};\n", .{ typeName(f.type, .uniform), f.name });
+ std.fmt.comptimePrint(" {s} {s};\n", .{ typeName(F, .uniform), name });
}
return out;
}
@@ -103,9 +104,10 @@ pub fn generate(comptime root: type, comptime paths: []const []const u8, io: std
pub fn assertStd140(comptime U: type) void {
comptime {
if (@typeInfo(U).@"struct".layout != .@"extern") @compileError(@typeName(U) ++ " must be extern to be a uniform block");
- for (@typeInfo(U).@"struct".fields) |f| {
- const want = std140Align(f.type);
- if (@offsetOf(U, f.name) % want != 0) @compileError(std.fmt.comptimePrint("{s}.{s} sits at {d}; std140 wants a multiple of {d}", .{ @typeName(U), f.name, @offsetOf(U, f.name), want }));
+ const s = @typeInfo(U).@"struct";
+ for (s.field_names, s.field_types) |name, F| {
+ const want = std140Align(F);
+ if (@offsetOf(U, name) % want != 0) @compileError(std.fmt.comptimePrint("{s}.{s} sits at {d}; std140 wants a multiple of {d}", .{ @typeName(U), name, @offsetOf(U, name), want }));
}
if (@sizeOf(U) % 16 != 0) @compileError(@typeName(U) ++ " must be a multiple of 16 bytes");
}