diff options
| author | s-ol <s+removethis@s-ol.nu> | 2026-04-10 17:08:15 +0000 |
|---|---|---|
| committer | s-ol <s+removethis@s-ol.nu> | 2026-04-10 22:22:45 +0000 |
| commit | 5d3f9aef90bed7713ce07614fdd154d50223ba61 (patch) | |
| tree | c6cfdc75e645773de14bf4cad8bbb89f60f267d6 /src/control.zig | |
| parent | more TSV logging (diff) | |
| download | glsl-view-5d3f9aef90bed7713ce07614fdd154d50223ba61.tar.gz glsl-view-5d3f9aef90bed7713ce07614fdd154d50223ba61.zip | |
support arrays of uniforms, remove finished sources
Diffstat (limited to 'src/control.zig')
| -rw-r--r-- | src/control.zig | 128 |
1 files changed, 41 insertions, 87 deletions
diff --git a/src/control.zig b/src/control.zig index 9810645..e52129e 100644 --- a/src/control.zig +++ b/src/control.zig @@ -22,49 +22,9 @@ fn verify_args_all(expected: u8, got: []const u8) !void { } } -fn set_one( - comptime T: type, - dest: *(if (T == bool) c.GLuint else T), - argv: []const [*c]c.lo_arg, - types: []const u8, -) !void { - if (types.len != 1) - return error.sizeMismatch; - - switch (T) { - f32 => { - try verify_args_all('f', types); - dest.* = argv[0].*.f; - }, - f64 => { - try verify_args_all('d', types); - dest.* = argv[0].*.d; - }, - i32 => { - try verify_args_all('d', types); - dest.* = argv[0].*.i; - }, - u32 => { - try verify_args_all('d', types); - const val = argv[0].*.i; - if (val < 0) - return error.signDisallowed; - dest.* = @as(u32, @intCast(val)); - }, - bool => { - dest.* = switch (types[0]) { - 'T' => c.GL_TRUE, - 'F' => c.GL_FALSE, - else => return error.typeMismatch, - }; - }, - else => return error.invalidType, - } -} - fn set_array( comptime T: type, - dest: [](if (T == bool) c.GLuint else T), + dest: []T, argv: []const [*c]c.lo_arg, types: []const u8, ) !void { @@ -197,6 +157,26 @@ pub const ControlServer = struct { } pub fn update(self: *ControlServer) void { + var names: [256][]const u8 = undefined; + var i: usize = 0; + + var tit = self.sources.iterator(); + while (tit.next()) |entry| { + const remove = entry.value_ptr.*.update(); + + if (remove) { + std.debug.print("delete source {s}\n", .{entry.key_ptr.*}); + entry.value_ptr.*.deinit(self.allocator); + names[i] = entry.key_ptr.*; + i += 1; + } + } + + for (names[0..i]) |name| { + _ = self.sources.remove(name); + self.allocator.free(name); + } + while (c.lo_server_recv_noblock(self.server, 0) > 0) {} } @@ -242,20 +222,25 @@ pub const ControlServer = struct { fn set_texture( self: *ControlServer, - dest: *?*gl.Texture, + dest: []?*gl.Texture, texture_type: gl.Texture.Type, types: []const u8, argv: []const [*c]c.lo_arg, ) !void { - if (types.len != 1 or types[0] != 's') return error.invalidType; + try verify_args_all('s', types); - const nameZ: [*:0]const u8 = @ptrCast(&argv[0].*.s); - const name = std.mem.span(nameZ); + if (types.len != dest.len) + return error.sizeMismatch; - const source = self.sources.get(name) orelse return error.texNotFound; - if (source.texture.type != texture_type) return error.wrongTextureType; + for (argv, dest) |arg, *tex| { + const nameZ: [*:0]const u8 = @ptrCast(&arg.*.s); + const name = std.mem.span(nameZ); - dest.* = &source.texture; + const source = self.sources.get(name) orelse return error.texNotFound; + if (source.texture.type != texture_type) return error.wrongTextureType; + + tex.* = &source.texture; + } } fn handle_uniform(self: *ControlServer, path: []const u8, types: []const u8, argv: []const [*c]c.lo_arg) !bool { @@ -270,7 +255,7 @@ pub const ControlServer = struct { break :blk try self.cache.get(nameZ) orelse return false; }; - var value = (uniform.value orelse unreachable).getPointer(); + var value = uniform.value; while (parts.next()) |component| { const i = switch (component[0]) { 'x', 'r', 's' => 0, @@ -286,6 +271,7 @@ pub const ControlServer = struct { return error.invalidIndex; } } + value = value.flatten(); if (std.mem.eql(u8, types, "s")) { const param_stringZ: [*:0]const u8 = @ptrCast(&argv[0].*.s); @@ -304,44 +290,12 @@ pub const ControlServer = struct { } try switch (value) { - .FLOAT => |val| set_one(f32, val, argv, types), - .DOUBLE => |val| set_one(f64, val, argv, types), - .INT => |val| set_one(i32, val, argv, types), - .UNSIGNED_INT => |val| set_one(u32, val, argv, types), - .BOOL => |val| set_one(bool, val, argv, types), - .FLOAT_VEC2 => |val| set_array(f32, val.*[0..], argv, types), - .FLOAT_VEC3 => |val| set_array(f32, val.*[0..], argv, types), - .FLOAT_VEC4 => |val| set_array(f32, val.*[0..], argv, types), - .DOUBLE_VEC2 => |val| set_array(f64, val.*[0..], argv, types), - .DOUBLE_VEC3 => |val| set_array(f64, val.*[0..], argv, types), - .DOUBLE_VEC4 => |val| set_array(f64, val.*[0..], argv, types), - .INT_VEC2 => |val| set_array(i32, val.*[0..], argv, types), - .INT_VEC3 => |val| set_array(i32, val.*[0..], argv, types), - .INT_VEC4 => |val| set_array(i32, val.*[0..], argv, types), - .UNSIGNED_INT_VEC2 => |val| set_array(u32, val.*[0..], argv, types), - .UNSIGNED_INT_VEC3 => |val| set_array(u32, val.*[0..], argv, types), - .UNSIGNED_INT_VEC4 => |val| set_array(u32, val.*[0..], argv, types), - .BOOL_VEC2 => |val| set_array(bool, val.*[0..], argv, types), - .BOOL_VEC3 => |val| set_array(bool, val.*[0..], argv, types), - .BOOL_VEC4 => |val| set_array(bool, val.*[0..], argv, types), - .FLOAT_MAT2 => |val| set_array(f32, val.*[0..], argv, types), - .FLOAT_MAT3 => |val| set_array(f32, val.*[0..], argv, types), - .FLOAT_MAT4 => |val| set_array(f32, val.*[0..], argv, types), - .FLOAT_MAT2x3 => |val| set_array(f32, val.*[0..], argv, types), - .FLOAT_MAT2x4 => |val| set_array(f32, val.*[0..], argv, types), - .FLOAT_MAT3x2 => |val| set_array(f32, val.*[0..], argv, types), - .FLOAT_MAT3x4 => |val| set_array(f32, val.*[0..], argv, types), - .FLOAT_MAT4x2 => |val| set_array(f32, val.*[0..], argv, types), - .FLOAT_MAT4x3 => |val| set_array(f32, val.*[0..], argv, types), - .DOUBLE_MAT2 => |val| set_array(f64, val.*[0..], argv, types), - .DOUBLE_MAT3 => |val| set_array(f64, val.*[0..], argv, types), - .DOUBLE_MAT4 => |val| set_array(f64, val.*[0..], argv, types), - .DOUBLE_MAT2x3 => |val| set_array(f64, val.*[0..], argv, types), - .DOUBLE_MAT2x4 => |val| set_array(f64, val.*[0..], argv, types), - .DOUBLE_MAT3x2 => |val| set_array(f64, val.*[0..], argv, types), - .DOUBLE_MAT3x4 => |val| set_array(f64, val.*[0..], argv, types), - .DOUBLE_MAT4x2 => |val| set_array(f64, val.*[0..], argv, types), - .DOUBLE_MAT4x3 => |val| set_array(f64, val.*[0..], argv, types), + inline .FLOAT, + .DOUBLE, + .INT, + .UNSIGNED_INT, + .BOOL, + => |val| set_array(@TypeOf(val[0]), val, argv, types), .SAMPLER_2D, .SAMPLER_2D_SHADOW, |
