diff options
| author | s-ol <s+removethis@s-ol.nu> | 2025-03-20 13:39:03 +0000 |
|---|---|---|
| committer | s-ol <s+removethis@s-ol.nu> | 2025-03-20 16:57:56 +0000 |
| commit | 6616300ed47e5b349704e64a06b1ece036b16463 (patch) | |
| tree | 7f9c5ae88d3a261736cb7713f352ea293fc7e242 /src/gl.zig | |
| parent | print effective OSC address on listen, reload messages (diff) | |
| download | glsl-view-6616300ed47e5b349704e64a06b1ece036b16463.tar.gz glsl-view-6616300ed47e5b349704e64a06b1ece036b16463.zip | |
wrap Texture in Source
Diffstat (limited to 'src/gl.zig')
| -rw-r--r-- | src/gl.zig | 33 |
1 files changed, 30 insertions, 3 deletions
@@ -878,17 +878,37 @@ pub const ShaderProgram = struct { } }; +pub const Source = struct { + pub const Type = enum { + file, + texture_share_vk, + }; + + texture: Texture, + + update_fn: ?*const fn (self: *Source) void, + deinit_fn: *const fn (self: *const Source, allocator: std.mem.Allocator) void, + + pub fn update(self: *Source) void { + if (self.update_fn) |inner| inner(self); + } + + pub fn deinit(self: *Source, allocator: std.mem.Allocator) void { + self.deinit_fn(self, allocator); + } +}; + pub const UniformCache = struct { allocator: std.mem.Allocator, uniforms: std.StringHashMap(CachedUniform), - textures: std.StringHashMap(Texture), + textures: std.StringHashMap(*Source), shader: *ShaderProgram, pub fn init(allocator: std.mem.Allocator, shader: *ShaderProgram) UniformCache { return UniformCache{ .allocator = allocator, .uniforms = std.StringHashMap(CachedUniform).init(allocator), - .textures = std.StringHashMap(Texture).init(allocator), + .textures = std.StringHashMap(*Source).init(allocator), .shader = shader, }; } @@ -902,7 +922,7 @@ pub const UniformCache = struct { var tit = self.textures.iterator(); while (tit.next()) |entry| { - entry.value_ptr.destroy(); + entry.value_ptr.*.deinit(self.allocator); self.allocator.free(entry.key_ptr.*); } @@ -951,6 +971,13 @@ pub const UniformCache = struct { } } } + + pub fn update(self: *UniformCache) void { + var it = self.textures.iterator(); + while (it.next()) |entry| { + entry.value_ptr.*.update(); + } + } }; pub const FramebufferObject = struct { |
