summaryrefslogtreecommitdiff
path: root/honey/shader.lua
diff options
context:
space:
mode:
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