aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/mgl/gl.h3
-rw-r--r--include/mgl/graphics/shader.h2
-rw-r--r--include/mgl/system/vec.h16
-rw-r--r--src/gl.c3
-rw-r--r--src/graphics/shader.c28
5 files changed, 50 insertions, 2 deletions
diff --git a/include/mgl/gl.h b/include/mgl/gl.h
index c1059b6..2537d96 100644
--- a/include/mgl/gl.h
+++ b/include/mgl/gl.h
@@ -33,7 +33,6 @@ typedef struct {
void (*glTexSubImage2D)(unsigned int target, int level, int xoffset, int yoffset, int width, int height, unsigned int format, unsigned int type, const void *pixels);
void (*glBindTexture)(unsigned int target, unsigned int texture);
void (*glTexParameteri)(unsigned int target, unsigned int pname, int param);
- void (*glHint)(unsigned int target, unsigned int mode);
void (*glBegin)(unsigned int mode);
void (*glEnd)(void);
void (*glVertex3f)(float x, float y, float z);
@@ -73,6 +72,8 @@ typedef struct {
int (*glGetUniformLocation)(unsigned int program, const char *name);
void (*glUniform1f)(int location, float v0);
void (*glUniform2f)(int location, float v0, float v1);
+ void (*glUniform3f)(int location, float v0, float v1, float v2);
+ void (*glUniform4f)(int location, float v0, float v1, float v2, float v3);
unsigned int (*glGetError)(void);
const unsigned char* (*glGetString)(unsigned int name);
void (*glGetIntegerv)(unsigned int pname, int *params);
diff --git a/include/mgl/graphics/shader.h b/include/mgl/graphics/shader.h
index daf8ac3..16b573a 100644
--- a/include/mgl/graphics/shader.h
+++ b/include/mgl/graphics/shader.h
@@ -24,6 +24,8 @@ int mgl_shader_program_finalize(mgl_shader_program *self);
int mgl_shader_program_set_uniform_float(mgl_shader_program *self, const char *uniform_name, float value);
int mgl_shader_program_set_uniform_vec2f(mgl_shader_program *self, const char *uniform_name, mgl_vec2f value);
+int mgl_shader_program_set_uniform_vec3f(mgl_shader_program *self, const char *uniform_name, mgl_vec3f value);
+int mgl_shader_program_set_uniform_vec4f(mgl_shader_program *self, const char *uniform_name, mgl_vec4f value);
/* If |shader_program| is NULL then no shader is used */
void mgl_shader_program_use(mgl_shader_program *shader_program);
diff --git a/include/mgl/system/vec.h b/include/mgl/system/vec.h
index 8b87376..444efcf 100644
--- a/include/mgl/system/vec.h
+++ b/include/mgl/system/vec.h
@@ -6,7 +6,23 @@ typedef struct {
} mgl_vec2f;
typedef struct {
+ float x, y, z;
+} mgl_vec3f;
+
+typedef struct {
+ float x, y, z, w;
+} mgl_vec4f;
+
+typedef struct {
int x, y;
} mgl_vec2i;
+typedef struct {
+ int x, y, z;
+} mgl_vec3i;
+
+typedef struct {
+ int x, y, z, w;
+} mgl_vec4i;
+
#endif /* MGL_VEC_H */
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();