diff options
| author | s-ol <s+removethis@s-ol.nu> | 2025-02-24 10:16:36 +0000 |
|---|---|---|
| committer | s-ol <s+removethis@s-ol.nu> | 2025-02-24 13:18:04 +0000 |
| commit | 96063a5d32d41a70cdbfba68e3f018c9c320aa68 (patch) | |
| tree | 3adadd5cc7ce41f68919ee28f9e56b2b1fec2c54 /src/control.zig | |
| parent | update for zig 0.13.0 (diff) | |
| download | glsl-view-96063a5d32d41a70cdbfba68e3f018c9c320aa68.tar.gz glsl-view-96063a5d32d41a70cdbfba68e3f018c9c320aa68.zip | |
load videos and textures using libav
Diffstat (limited to 'src/control.zig')
| -rw-r--r-- | src/control.zig | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/src/control.zig b/src/control.zig index 2e63b44..9482015 100644 --- a/src/control.zig +++ b/src/control.zig @@ -1,5 +1,6 @@ const c = @import("c.zig"); const gl = @import("gl.zig"); +const video = @import("video.zig"); const std = @import("std"); const cfg = @import("config.zig"); @@ -85,19 +86,41 @@ fn set_array( } } +fn set_texture(progress: std.Progress.Node, dest: *?gl.Texture, texture_type: gl.Texture.Type, argc: c_int, argv: [*c][*c]c.lo_arg, types: []const u8) !void { + if (argc != 1 or types[0] != 's') return error.invalidType; + + if (dest.*) |old| { + old.destroy(); + dest.* = null; + } + + dest.* = gl.Texture.create(texture_type); + try video.loadVideo(progress, @ptrCast(&argv[0].*.s), &dest.*.?); +} + pub const ControlServer = struct { server: c.lo_server, + reload_requested: bool, + cache: *gl.UniformCache, + progress: std.Progress.Node, allocator: std.mem.Allocator, pub fn init( allocator: std.mem.Allocator, + progress: std.Progress.Node, config: cfg.OSCConfig, cache: *gl.UniformCache, ) !*ControlServer { var self: *ControlServer = try allocator.create(ControlServer); - self.allocator = allocator; - self.cache = cache; + self.* = .{ + .server = null, + .reload_requested = false, + + .cache = cache, + .progress = progress, + .allocator = allocator, + }; switch (config) { .Manual => |conf| { @@ -219,6 +242,24 @@ pub const ControlServer = struct { .DOUBLE_MAT3x4 => |val| set_array(f64, val.*[0..], argc, argv, types), .DOUBLE_MAT4x2 => |val| set_array(f64, val.*[0..], argc, argv, types), .DOUBLE_MAT4x3 => |val| set_array(f64, val.*[0..], argc, argv, types), + + .SAMPLER_2D, + .SAMPLER_2D_SHADOW, + .INT_SAMPLER_2D, + .UNSIGNED_INT_SAMPLER_2D, + => |val| set_texture(self.progress, val, .TEXTURE_2D, argc, argv, types), + + .SAMPLER_2D_ARRAY, + .SAMPLER_2D_ARRAY_SHADOW, + .INT_SAMPLER_2D_ARRAY, + .UNSIGNED_INT_SAMPLER_2D_ARRAY, + => |val| set_texture(self.progress, val, .TEXTURE_2D_ARRAY, argc, argv, types), + + .SAMPLER_3D, + .INT_SAMPLER_3D, + .UNSIGNED_INT_SAMPLER_3D, + => |val| set_texture(self.progress, val, .TEXTURE_3D, argc, argv, types), + else => error.uniformNotSupported, }; @@ -239,6 +280,11 @@ pub const ControlServer = struct { const path = _path[0..c.strlen(_path)]; const types = _types[0..@as(u32, @intCast(argc))]; + if (std.mem.eql(u8, path, "/-/reload")) { + self.reload_requested = true; + return 1; + } + self.set_uniform(path, argv, argc, types) catch |err| { std.debug.print("{} while processing {s}\n", .{ err, path }); return 1; |
