aboutsummaryrefslogtreecommitdiffstats
path: root/src/control.zig
diff options
context:
space:
mode:
authors-ol <s+removethis@s-ol.nu>2025-03-20 13:39:03 +0000
committers-ol <s+removethis@s-ol.nu>2025-03-20 16:57:56 +0000
commit6616300ed47e5b349704e64a06b1ece036b16463 (patch)
tree7f9c5ae88d3a261736cb7713f352ea293fc7e242 /src/control.zig
parentprint effective OSC address on listen, reload messages (diff)
downloadglsl-view-6616300ed47e5b349704e64a06b1ece036b16463.tar.gz
glsl-view-6616300ed47e5b349704e64a06b1ece036b16463.zip
wrap Texture in Source
Diffstat (limited to 'src/control.zig')
-rw-r--r--src/control.zig36
1 files changed, 20 insertions, 16 deletions
diff --git a/src/control.zig b/src/control.zig
index 361d079..d36ce01 100644
--- a/src/control.zig
+++ b/src/control.zig
@@ -1,8 +1,8 @@
const c = @import("c.zig");
const gl = @import("gl.zig");
-const video = @import("video.zig");
const std = @import("std");
const cfg = @import("config.zig");
+const build_config = @import("build_config");
fn verify_args(expected: u8, got: []const u8) !void {
for (got) |typ| {
@@ -16,7 +16,7 @@ fn verify_args(expected: u8, got: []const u8) !void {
fn set_one(
comptime T: type,
dest: *T,
- argv: []const[*c]c.lo_arg,
+ argv: []const [*c]c.lo_arg,
types: []const u8,
) !void {
if (types.len != 1)
@@ -49,7 +49,7 @@ fn set_one(
fn set_array(
comptime T: type,
dest: []T,
- argv: []const[*c]c.lo_arg,
+ argv: []const [*c]c.lo_arg,
types: []const u8,
) !void {
if (types.len != dest.len)
@@ -89,17 +89,17 @@ fn set_texture(
dest: *?*gl.Texture,
texture_type: gl.Texture.Type,
types: []const u8,
- argv: []const[*c]c.lo_arg,
+ argv: []const [*c]c.lo_arg,
) !void {
if (types.len != 1 or types[0] != 's') return error.invalidType;
const nameZ: [*:0]const u8 = @ptrCast(&argv[0].*.s);
const name = std.mem.span(nameZ);
- const tex = cache.textures.getPtr(name) orelse return error.texNotFound;
- if (tex.type != texture_type) return error.wrongTextureType;
+ const source = cache.textures.get(name) orelse return error.texNotFound;
+ if (source.texture.type != texture_type) return error.wrongTextureType;
- dest.* = tex;
+ dest.* = &source.texture;
}
pub const ControlServer = struct {
@@ -110,7 +110,7 @@ pub const ControlServer = struct {
progress: std.Progress.Node,
allocator: std.mem.Allocator,
- const ZigCallback = fn (*ControlServer, []const u8, []const u8, []const[*c]c.lo_arg) anyerror!bool;
+ const ZigCallback = fn (*ControlServer, []const u8, []const u8, []const [*c]c.lo_arg) anyerror!bool;
const CCallback = fn ([*c]const u8, [*c]const u8, [*c][*c]c.lo_arg, c_int, c.lo_message, ?*anyopaque) callconv(.C) c_int;
fn wrapCallback(comptime inner: ZigCallback) CCallback {
return struct {
@@ -186,7 +186,7 @@ pub const ControlServer = struct {
);
}
- fn handle_shader(self: *ControlServer, path: []const u8, types: []const u8, argv: []const[*c]c.lo_arg) !bool {
+ fn handle_shader(self: *ControlServer, path: []const u8, types: []const u8, argv: []const [*c]c.lo_arg) !bool {
_ = path;
_ = types;
@@ -197,7 +197,7 @@ pub const ControlServer = struct {
return true;
}
- fn handle_reload(self: *ControlServer, path: []const u8, types: []const u8, argv: []const[*c]c.lo_arg) !bool {
+ fn handle_reload(self: *ControlServer, path: []const u8, types: []const u8, argv: []const [*c]c.lo_arg) !bool {
_ = path;
_ = types;
_ = argv;
@@ -207,7 +207,7 @@ pub const ControlServer = struct {
return true;
}
- fn handle_uniform(self: *ControlServer, path: []const u8, types: []const u8, argv: []const[*c]c.lo_arg) !bool {
+ fn handle_uniform(self: *ControlServer, path: []const u8, types: []const u8, argv: []const [*c]c.lo_arg) !bool {
var parts = std.mem.tokenizeScalar(u8, path, '/');
_ = parts.next(); // skip /uniform
@@ -300,7 +300,10 @@ pub const ControlServer = struct {
return true;
}
- fn handle_load_texture(self: *ControlServer, path: []const u8, types: []const u8, argv: []const[*c]c.lo_arg) !bool {
+ fn handle_load_texture(self: *ControlServer, path: []const u8, types: []const u8, argv: []const [*c]c.lo_arg) !bool {
+ if (!build_config.have_ffmpeg) return error.supportDisabled;
+ const ffmpeg = @import("ffmpeg.zig");
+
_ = types;
var parts = std.mem.tokenizeScalar(u8, path, '/');
@@ -315,13 +318,13 @@ pub const ControlServer = struct {
const key = try self.cache.allocator.dupe(u8, name);
errdefer self.cache.allocator.free(key);
- const texture = try video.loadVideo(self.progress, filenameZ, texture_type);
- try self.cache.textures.put(key, texture);
+ const source = try ffmpeg.VideoSource.init(self.cache.allocator, self.progress, filenameZ, texture_type);
+ try self.cache.textures.put(key, source);
return true;
}
- fn handle_destroy_texture(self: *ControlServer, path: []const u8, types: []const u8, argv: []const[*c]c.lo_arg) !bool {
+ fn handle_destroy_texture(self: *ControlServer, path: []const u8, types: []const u8, argv: []const [*c]c.lo_arg) !bool {
_ = types;
_ = argv;
@@ -330,7 +333,8 @@ pub const ControlServer = struct {
const name = parts.next() orelse unreachable;
if (self.cache.textures.fetchRemove(name)) |kv| {
- kv.value.destroy();
+ // @TODO: find all references to kv.value.texture in UniformCache and unassign
+ kv.value.deinit(self.cache.allocator);
self.cache.allocator.free(kv.key);
} else return false;