diff options
author | sanine-a <sanine.not@pm.me> | 2020-11-08 19:59:16 -0600 |
---|---|---|
committer | sanine-a <sanine.not@pm.me> | 2020-11-08 19:59:16 -0600 |
commit | 7bdeedd394e4b51d4c2ef4a0dd0470ed0492ac5f (patch) | |
tree | 956195b60e7d7671700baeb3b49c6a531e9ee30a /demo/Shader.lua | |
parent | c00400ce832f2ab81fdef0ecdf6820a08e596eae (diff) |
add Shader and SpatialShader
Diffstat (limited to 'demo/Shader.lua')
-rw-r--r-- | demo/Shader.lua | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/demo/Shader.lua b/demo/Shader.lua new file mode 100644 index 0000000..494bd53 --- /dev/null +++ b/demo/Shader.lua @@ -0,0 +1,53 @@ +local Shader = {} + +Shader.prototype = {} + +Shader.prototype.setInteger = function(self, uniform, integer) + honey.shader.set_int(self.program, uniform, integer) +end + +Shader.prototype.setFloat = function(self, uniform, float) + honey.shader.set_float(self.program, uniform, float) +end + +Shader.prototype.setVec3 = function(self, uniform, vector) + honey.shader.set_vec3(self.program, uniform, vector.array) +end + +Shader.prototype.setVec4 = function(self, uniform, vector) + honey.shader.set_vec4(self.program, uniform, vector.array) +end + +Shader.prototype.setMat3 = function(self, uniform, matrix) + honey.shader.set_mat3(self.program, uniform, matrix.array) +end + +Shader.prototype.setMat4 = function(self, uniform, matrix) + honey.shader.set_mat4(self.program, uniform, matrix.array) +end + +Shader.prototype.drawMesh = function(self, mesh) + honey.mesh.draw(mesh.mesh, self.program) +end + +Shader.prototype.delete = function(self) + honey.shader.delete(self.program) +end + +-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Shader.mt = {} +Shader.mt.__index = Shader.prototype + +-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Shader.new = function(vertexCode, fragmentCode) + local shader = {} + shader.program = honey.shader.new(vertexCode, fragmentCode) + + setmetatable(shader, Shader.mt) + + return shader +end + +return Shader |