diff options
author | sanine <sanine.not@pm.me> | 2023-03-19 01:17:48 -0500 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2023-03-19 01:17:48 -0500 |
commit | 05009088588e6171dd26c3002208e338e2c5a65a (patch) | |
tree | d3bb7afa0a7388b8a0ac2219c06e32fbd8f6e47e /honey/shader.lua | |
parent | d94d9fb122e42264eca20bb037fe8a82290bd3e2 (diff) |
add shader:configure()
Diffstat (limited to 'honey/shader.lua')
-rw-r--r-- | honey/shader.lua | 35 |
1 files changed, 35 insertions, 0 deletions
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 |