diff options
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 |