aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2024-07-24 20:20:57 +0200
committerdec05eba <dec05eba@protonmail.com>2024-07-24 20:20:57 +0200
commit5cc09d9389243791f8f65f96a4d19a74337f2a73 (patch)
treea44372d5381983bd631b8e88c55cb6647abe78e7 /src
parent1a1ce3f6733b524122bdfe33e4b662803a698163 (diff)
add vec3 and vec4 and shader uniform functions for those
Diffstat (limited to 'src')
-rw-r--r--src/gl.c3
-rw-r--r--src/graphics/shader.c28
2 files changed, 30 insertions, 1 deletions
diff --git a/src/gl.c b/src/gl.c
index 90880c4..adc7c89 100644
--- a/src/gl.c
+++ b/src/gl.c
@@ -46,7 +46,6 @@ int mgl_gl_load(mgl_gl *self) {
{ (void**)&self->glTexSubImage2D, "glTexSubImage2D" },
{ (void**)&self->glBindTexture, "glBindTexture" },
{ (void**)&self->glTexParameteri, "glTexParameteri" },
- { (void**)&self->glHint, "glHint" },
{ (void**)&self->glBegin, "glBegin" },
{ (void**)&self->glEnd, "glEnd" },
{ (void**)&self->glVertex3f, "glVertex3f" },
@@ -86,6 +85,8 @@ int mgl_gl_load(mgl_gl *self) {
{ (void**)&self->glGetUniformLocation, "glGetUniformLocation" },
{ (void**)&self->glUniform1f, "glUniform1f" },
{ (void**)&self->glUniform2f, "glUniform2f" },
+ { (void**)&self->glUniform3f, "glUniform3f" },
+ { (void**)&self->glUniform4f, "glUniform4f" },
{ (void**)&self->glGetError, "glGetError" },
{ (void**)&self->glGetString, "glGetString" },
{ (void**)&self->glGetIntegerv, "glGetIntegerv" },
diff --git a/src/graphics/shader.c b/src/graphics/shader.c
index 83c8407..f7f5545 100644
--- a/src/graphics/shader.c
+++ b/src/graphics/shader.c
@@ -203,6 +203,34 @@ int mgl_shader_program_set_uniform_vec2f(mgl_shader_program *self, const char *u
return 0;
}
+int mgl_shader_program_set_uniform_vec3f(mgl_shader_program *self, const char *uniform_name, mgl_vec3f value) {
+ mgl_context *context = mgl_get_context();
+ int uniform_location = context->gl.glGetUniformLocation(self->id, uniform_name);
+ if(uniform_location == -1) {
+ fprintf(stderr, "mgl error: no uniform by the name %s was found in the shader\n", uniform_name);
+ return -1;
+ }
+
+ context->gl.glUseProgram(self->id);
+ context->gl.glUniform3f(uniform_location, value.x, value.y, value.z);
+ context->gl.glUseProgram(0);
+ return 0;
+}
+
+int mgl_shader_program_set_uniform_vec4f(mgl_shader_program *self, const char *uniform_name, mgl_vec4f value) {
+ mgl_context *context = mgl_get_context();
+ int uniform_location = context->gl.glGetUniformLocation(self->id, uniform_name);
+ if(uniform_location == -1) {
+ fprintf(stderr, "mgl error: no uniform by the name %s was found in the shader\n", uniform_name);
+ return -1;
+ }
+
+ context->gl.glUseProgram(self->id);
+ context->gl.glUniform4f(uniform_location, value.x, value.y, value.z, value.w);
+ context->gl.glUseProgram(0);
+ return 0;
+}
+
/* TODO: Optimize glUseProgram */
void mgl_shader_program_use(mgl_shader_program *shader_program) {
mgl_context *context = mgl_get_context();