From 5a93fb6f6a8fb6f1dad821b407b4f4531bc23783 Mon Sep 17 00:00:00 2001 From: sanine Date: Wed, 29 Mar 2023 00:01:54 -0500 Subject: add image caching --- honey/shader.lua | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'honey/shader.lua') diff --git a/honey/shader.lua b/honey/shader.lua index 083b260..6b281f7 100644 --- a/honey/shader.lua +++ b/honey/shader.lua @@ -52,6 +52,10 @@ function Shader.new(_, sources) gl.DeleteShader(shader) end + self.__gc = honey.util.gc_canary(function() + gl.DeleteProgram(self.program) + end) + setmetatable(self, Shader) return self end @@ -115,4 +119,18 @@ function Shader.configure(self, tbl) processKey("matrix", "setMatrix") end -return module.Shader + +local shaderCache = {} +function loadShader(vertex, fragment) + local id = vertex .. "+" .. fragment + if not shaderCache[id] then + local shader = Shader{vertexFile=vertex, fragmentFile=fragment} + shaderCache[id] = shader + end + return shaderCache[id] +end +function clearShaderCache() + shaderCache = {} +end + +return module -- cgit v1.2.1