aboutsummaryrefslogtreecommitdiff
path: root/src/graphics/shader.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/graphics/shader.c')
-rw-r--r--src/graphics/shader.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/graphics/shader.c b/src/graphics/shader.c
index 9afde0e..8f44f0f 100644
--- a/src/graphics/shader.c
+++ b/src/graphics/shader.c
@@ -173,6 +173,21 @@ int mgl_shader_program_finalize(mgl_shader_program *self) {
/* TODO: Optimize glUseProgram */
/* TODO: Optimize glGetUniformLocation */
+/* TODO: Check if the uniform type matches the type of the value we want to set it to */
+
+int mgl_shader_program_set_uniform_float(mgl_shader_program *self, const char *uniform_name, float value) {
+ mgl_context *context = mgl_get_context();
+ int uniform_location = context->gl.glGetUniformLocation(self->id, uniform_name);
+ if(uniform_location == -1) {
+ fprintf(stderr, "Error: no uniform by the name %s was found in the shader\n", uniform_name);
+ return -1;
+ }
+
+ context->gl.glUseProgram(self->id);
+ context->gl.glUniform1f(uniform_location, value);
+ context->gl.glUseProgram(0);
+ return 0;
+}
int mgl_shader_program_set_uniform_vec2f(mgl_shader_program *self, const char *uniform_name, mgl_vec2f value) {
mgl_context *context = mgl_get_context();
@@ -183,7 +198,7 @@ int mgl_shader_program_set_uniform_vec2f(mgl_shader_program *self, const char *u
}
context->gl.glUseProgram(self->id);
- context->gl.glUniform2fv(uniform_location, 1, &value.x);
+ context->gl.glUniform2f(uniform_location, value.x, value.y);
context->gl.glUseProgram(0);
return 0;
}