From 05009088588e6171dd26c3002208e338e2c5a65a Mon Sep 17 00:00:00 2001 From: sanine Date: Sun, 19 Mar 2023 01:17:48 -0500 Subject: add shader:configure() --- honey/shader.lua | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'honey') diff --git a/honey/shader.lua b/honey/shader.lua index 82d7e8a..1fb9f5b 100644 --- a/honey/shader.lua +++ b/honey/shader.lua @@ -59,10 +59,45 @@ function Shader.use(self) end +function Shader.setInt(self, name, value) + local location = self:getLocation(name) + gl.Uniform1i(location, value) +end +function Shader.setFloat(self, name, value) + local location = self:getLocation(name) + gl.Uniform1f(location, value) +end + +function Shader.setVec3(self, name, value) + local location = self:getLocation(name) + gl.Uniform3f(location, value[1], value[2], value[3]) +end +function Shader.setVec4(self, name, value) + local location = self:getLocation(name) + gl.Uniform3f(location, value[1], value[2], value[3], value[4]) +end + function Shader.setMatrix(self, name, matrix) local location = self:getLocation(name) gl.UniformMatrix4fv(location, false, matrix.data) end +function Shader.configure(self, tbl) + local processKey = function(key, set) + local subtbl = tbl[key] + if subtbl then + for name, value in pairs(subtbl) do + self[set](self, name, value) + end + end + end + + processKey("int", "setInt") + processKey("float", "setFloat") + processKey("vec3", "setVec3") + processKey("vec4", "setVec4") + processKey("matrix", "setMatrix") +end + return module.Shader -- cgit v1.2.1