Add cglm library and add uniform setters for shader programs

This commit is contained in:
2020-06-27 20:10:33 +02:00
parent 8837de9e2a
commit 97d11cf2b0
6 changed files with 191 additions and 3 deletions

View File

@@ -1,7 +1,7 @@
/*
* This file is part of Shimatta OpenGL.
*
* Foobar is free software: you can redistribute it and/or modify
* Shimatta OpenGL is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
@@ -343,3 +343,139 @@ return_value:
return ret_val;
}
int shimatta_opengl_program_get_uniform_location(ShimattaOpenglProgram *program, const char *uniform_name)
{
int ret;
ShimattaOpenglProgramPrivate *priv;
g_return_val_if_fail(SHIMATTA_IS_OPENGL_PROGRAM(program), -1001);
if (!uniform_name)
return -1002;
if (!shimatta_opengl_program_is_compiled(program)) {
g_warning("Trying to get Uniform location of %s for not loaded shader program", uniform_name);
return -1;
}
priv = shimatta_opengl_program_get_instance_private(program);
ret = glGetUniformLocation(priv->shader_id, (const GLchar *)uniform_name);
return ret;
}
int shimatta_opengl_program_get_attrib_location(ShimattaOpenglProgram *program, const char *attrib_name)
{
int ret;
ShimattaOpenglProgramPrivate *priv;
g_return_val_if_fail(SHIMATTA_IS_OPENGL_PROGRAM(program), -1001);
if (!attrib_name)
return -1002;
if (!shimatta_opengl_program_is_compiled(program)) {
g_warning("Trying to get Attribute location of %s for not loaded shader program", attrib_name);
return -1;
}
priv = shimatta_opengl_program_get_instance_private(program);
ret = glGetAttribLocation(priv->shader_id, (const GLchar *)attrib_name);
return ret;
}
void shimatta_opengl_program_set_uniform_float(ShimattaOpenglProgram *program, const char *uniform, float value)
{
int loc;
g_return_if_fail(SHIMATTA_IS_OPENGL_PROGRAM(program));
g_return_if_fail(uniform != NULL);
loc = shimatta_opengl_program_get_uniform_location(program, uniform);
if (loc >= 0)
glUniform1f(loc, value);
}
void shimatta_opengl_program_set_uniform_int(ShimattaOpenglProgram *program, const char *uniform, int value)
{
int loc;
g_return_if_fail(SHIMATTA_IS_OPENGL_PROGRAM(program));
g_return_if_fail(uniform != NULL);
loc = shimatta_opengl_program_get_uniform_location(program, uniform);
if (loc >= 0)
glUniform1i(loc, value);
}
void shimatta_opengl_program_set_uniform_vec2(ShimattaOpenglProgram *program, const char *uniform, vec2 value)
{
int loc;
g_return_if_fail(SHIMATTA_IS_OPENGL_PROGRAM(program));
g_return_if_fail(uniform != NULL);
loc = shimatta_opengl_program_get_uniform_location(program, uniform);
if (loc >= 0)
glUniform2fv(loc, 1, value);
}
void shimatta_opengl_program_set_uniform_vec3(ShimattaOpenglProgram *program, const char *uniform, vec3 value)
{
int loc;
g_return_if_fail(SHIMATTA_IS_OPENGL_PROGRAM(program));
g_return_if_fail(uniform != NULL);
loc = shimatta_opengl_program_get_uniform_location(program, uniform);
if (loc >= 0)
glUniform3fv(loc, 1, value);
}
void shimatta_opengl_program_set_uniform_vec4(ShimattaOpenglProgram *program, const char *uniform, vec4 value)
{
int loc;
g_return_if_fail(SHIMATTA_IS_OPENGL_PROGRAM(program));
g_return_if_fail(uniform != NULL);
loc = shimatta_opengl_program_get_uniform_location(program, uniform);
if (loc >= 0)
glUniform4fv(loc, 1, value);
}
void shimatta_opengl_program_set_uniform_mat2(ShimattaOpenglProgram *program, const char *uniform, mat2 value)
{
int loc;
g_return_if_fail(SHIMATTA_IS_OPENGL_PROGRAM(program));
g_return_if_fail(uniform != NULL);
loc = shimatta_opengl_program_get_uniform_location(program, uniform);
if (loc >= 0)
glUniformMatrix2fv(loc, 1, GL_FALSE, &value[0][0]);
}
void shimatta_opengl_program_set_uniform_mat3(ShimattaOpenglProgram *program, const char *uniform, mat3 value)
{
int loc;
g_return_if_fail(SHIMATTA_IS_OPENGL_PROGRAM(program));
g_return_if_fail(uniform != NULL);
loc = shimatta_opengl_program_get_uniform_location(program, uniform);
if (loc >= 0)
glUniformMatrix3fv(loc, 1, GL_FALSE, &value[0][0]);
}
void shimatta_opengl_program_set_uniform_mat4(ShimattaOpenglProgram *program, const char *uniform, mat4 value)
{
int loc;
g_return_if_fail(SHIMATTA_IS_OPENGL_PROGRAM(program));
g_return_if_fail(uniform != NULL);
loc = shimatta_opengl_program_get_uniform_location(program, uniform);
if (loc >= 0)
glUniformMatrix4fv(loc, 1, GL_FALSE, &value[0][0]);
}