summary refs log tree commit diff
path: root/src/shader
diff options
context:
space:
mode:
authoriurii plugatarov <[email protected]>2024-08-16 20:51:24 +0200
committeriurii plugatarov <[email protected]>2024-08-16 20:51:24 +0200
commitfc3e2bed46c42a9af6a9e562b6609608e09e9850 (patch)
tree2a33d53214c71898014a8b6d135870aa82b494d3 /src/shader
parent586369b63cdede5fa09f5f9ed73abde6c8264425 (diff)
downloadfunhalla-fc3e2bed46c42a9af6a9e562b6609608e09e9850.tar.gz
shaders and textures
Diffstat (limited to '')
-rw-r--r--src/shader/shader.odin50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/shader/shader.odin b/src/shader/shader.odin
new file mode 100644
index 0000000..171d7ad
--- /dev/null
+++ b/src/shader/shader.odin
@@ -0,0 +1,50 @@
+package shader
+
+import "core:os"
+import "core:strings"
+import gl "vendor:OpenGL"
+
+Shader :: struct {
+	id: u32,
+}
+
+SHADER_LOAD_ERROR :: -1
+SHADER_OK :: 0
+
+shader_init :: proc(vsp, fsp: string) -> (^Shader, int) {
+	assert(os.is_file_path(vsp))
+	assert(os.is_file_path(fsp))
+
+	program_id, ok := gl.load_shaders_file(vsp, fsp)
+
+	if !ok {
+		return nil, SHADER_LOAD_ERROR
+	}
+
+	shader := new(Shader)
+	shader.id = program_id
+
+	return shader, SHADER_OK
+}
+
+use :: proc(using shader: ^Shader) {
+	gl.UseProgram(id)
+}
+
+set_bool :: proc(using shader: ^Shader, name: cstring, value: bool) {
+	gl.Uniform1i(gl.GetUniformLocation(id, name), i32(value))
+}
+
+set_i32 :: proc(using shader: ^Shader, name: cstring, value: i32) {
+	gl.Uniform1i(gl.GetUniformLocation(id, name), value)
+}
+
+set_f32 :: proc(using shader: ^Shader, name: cstring, value: f32) {
+	gl.Uniform1f(gl.GetUniformLocation(id, name), value)
+}
+
+set_value :: proc {
+	set_i32,
+	set_f32,
+	set_bool,
+}