summaryrefslogtreecommitdiff
path: root/honey/shader.lua
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2023-03-29 00:01:54 -0500
committersanine <sanine.not@pm.me>2023-03-29 00:01:54 -0500
commit5a93fb6f6a8fb6f1dad821b407b4f4531bc23783 (patch)
treed7b7fb60868e2381bdd14efa357188ba3a27b804 /honey/shader.lua
parent45dbe47d17303050cbea7c2c51e838acfe21c2fb (diff)
add image caching
Diffstat (limited to 'honey/shader.lua')
-rw-r--r--honey/shader.lua20
1 files changed, 19 insertions, 1 deletions
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