aboutsummaryrefslogtreecommitdiffstats
path: root/src/control.zig
diff options
context:
space:
mode:
authors-ol <s+removethis@s-ol.nu>2025-03-16 16:46:52 +0000
committers-ol <s+removethis@s-ol.nu>2025-03-16 19:10:16 +0000
commitf4ec8103c59b3e67273cd7a95ce42c752ec054e1 (patch)
tree149011f38a225a308ae8361bb3dd40e7e7370bda /src/control.zig
parentformatting (diff)
downloadglsl-view-f4ec8103c59b3e67273cd7a95ce42c752ec054e1.tar.gz
glsl-view-f4ec8103c59b3e67273cd7a95ce42c752ec054e1.zip
cache textures by filename
Diffstat (limited to 'src/control.zig')
-rw-r--r--src/control.zig25
1 files changed, 14 insertions, 11 deletions
diff --git a/src/control.zig b/src/control.zig
index 72abf6f..2c272db 100644
--- a/src/control.zig
+++ b/src/control.zig
@@ -86,6 +86,7 @@ fn set_array(
fn set_texture(
progress: std.Progress.Node,
+ cache: *gl.UniformCache,
dest: *?gl.Texture,
texture_type: gl.Texture.Type,
argv: [][*c]c.lo_arg,
@@ -93,16 +94,18 @@ fn set_texture(
) !void {
if (types.len != 1 or types[0] != 's') return error.invalidType;
- if (dest.*) |old| {
- old.destroy();
- dest.* = null;
- }
+ const filenameZ: [*:0]const u8 = @ptrCast(&argv[0].*.s);
+ const filename = std.mem.span(filenameZ);
- var buffer: [1024]u8 = undefined;
- const filepath = try std.fs.cwd().realpathZ(@ptrCast(&argv[0].*.s), buffer[0..]);
- buffer[filepath.len] = 0;
+ if (!cache.textures.contains(filename)) {
+ const key = try cache.allocator.dupe(u8, filename);
+ errdefer cache.allocator.free(key);
+
+ const texture = try video.loadVideo(progress, filenameZ, texture_type);
+ try cache.textures.put(key, texture);
+ }
- dest.* = try video.loadVideo(progress, @ptrCast(filepath), texture_type);
+ dest.* = cache.textures.get(filename);
}
pub const ControlServer = struct {
@@ -237,18 +240,18 @@ pub const ControlServer = struct {
.SAMPLER_2D_SHADOW,
.INT_SAMPLER_2D,
.UNSIGNED_INT_SAMPLER_2D,
- => |val| set_texture(self.progress, val, .TEXTURE_2D, argv, types),
+ => |val| set_texture(self.progress, self.cache, val, .TEXTURE_2D, 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, argv, types),
+ => |val| set_texture(self.progress, self.cache, val, .TEXTURE_2D_ARRAY, argv, types),
.SAMPLER_3D,
.INT_SAMPLER_3D,
.UNSIGNED_INT_SAMPLER_3D,
- => |val| set_texture(self.progress, val, .TEXTURE_3D, argv, types),
+ => |val| set_texture(self.progress, self.cache, val, .TEXTURE_3D, argv, types),
else => error.uniformNotSupported,
};