diff options
| author | s-ol <s+removethis@s-ol.nu> | 2025-03-16 16:46:52 +0000 |
|---|---|---|
| committer | s-ol <s+removethis@s-ol.nu> | 2025-03-16 19:10:16 +0000 |
| commit | f4ec8103c59b3e67273cd7a95ce42c752ec054e1 (patch) | |
| tree | 149011f38a225a308ae8361bb3dd40e7e7370bda /src/gl.zig | |
| parent | formatting (diff) | |
| download | glsl-view-f4ec8103c59b3e67273cd7a95ce42c752ec054e1.tar.gz glsl-view-f4ec8103c59b3e67273cd7a95ce42c752ec054e1.zip | |
cache textures by filename
Diffstat (limited to 'src/gl.zig')
| -rw-r--r-- | src/gl.zig | 31 |
1 files changed, 13 insertions, 18 deletions
@@ -377,7 +377,8 @@ const UniformValue = union(UniformType) { .UNSIGNED_INT_SAMPLER_BUFFER, .UNSIGNED_INT_SAMPLER_2D_RECT, => |value| { - if (value) |texture| texture.destroy(); + // if (value) |texture| texture.destroy(); + _ = value; }, else => {}, } @@ -529,21 +530,6 @@ pub const CachedUniform = struct { } } - // deinit self WITHOUT freeing contained resources - pub fn move( - self: *CachedUniform, - to: *CachedUniform, - allocator: std.mem.Allocator, - ) CachedUniform { - to.deinit(allocator); - to.buffer = self.buffer; - to.value = self.value; - - self.buffer = null; - - return self; - } - pub fn tryMove( self: *CachedUniform, dest: *CachedUniform, @@ -895,24 +881,33 @@ pub const ShaderProgram = struct { pub const UniformCache = struct { allocator: std.mem.Allocator, uniforms: std.StringHashMap(CachedUniform), + textures: std.StringHashMap(Texture), 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), .shader = shader, }; } pub fn deinit(self: *UniformCache) void { - var it = self.uniforms.iterator(); - while (it.next()) |entry| { + var uit = self.uniforms.iterator(); + while (uit.next()) |entry| { entry.value_ptr.deinit(self.allocator); self.allocator.free(entry.key_ptr.*); } + var tit = self.textures.iterator(); + while (tit.next()) |entry| { + entry.value_ptr.destroy(); + self.allocator.free(entry.key_ptr.*); + } + self.uniforms.deinit(); + self.textures.deinit(); } pub fn get(self: *UniformCache, name: []const u8) !?*CachedUniform { |
