diff --git a/include/simpleengine/gfx/shader.h b/include/simpleengine/gfx/shader.h index 2af38cb..75bae66 100644 --- a/include/simpleengine/gfx/shader.h +++ b/include/simpleengine/gfx/shader.h @@ -6,6 +6,7 @@ #include +#include #include #include "../event/event.h" @@ -197,5 +198,32 @@ namespace simpleengine::gfx { void set_uniform_uint_vec4(GLint location, glm::uvec4 vec, bool bind_shader = true); void set_uniform_uint_vec4(const char* uniform_name, glm::uvec4 vec, bool bind_shader = true); + + void set_uniform_matrix_2f(GLint location, glm::mat2 mat, bool bind_shader = true, bool transpose = false); + void set_uniform_matrix_2f(const char* uniform_name, glm::mat2 mat, bool bind_shader = true, bool transpose = false); + + void set_uniform_matrix_3f(GLint location, glm::mat3 mat, bool bind_shader = true, bool transpose = false); + void set_uniform_matrix_3f(const char* uniform_name, glm::mat3 mat, bool bind_shader = true, bool transpose = false); + + void set_uniform_matrix_4f(GLint location, glm::mat4 mat, bool bind_shader = true, bool transpose = false); + void set_uniform_matrix_4f(const char* uniform_name, glm::mat4 mat, bool bind_shader = true, bool transpose = false); + + void set_uniform_matrix_2x3f(GLint location, glm::mat2x3 mat, bool bind_shader = true, bool transpose = false); + void set_uniform_matrix_2x3f(const char* uniform_name, glm::mat2x3 mat, bool bind_shader = true, bool transpose = false); + + void set_uniform_matrix_3x2f(GLint location, glm::mat3x2 mat, bool bind_shader = true, bool transpose = false); + void set_uniform_matrix_3x2f(const char* uniform_name, glm::mat3x2 mat, bool bind_shader = true, bool transpose = false); + + void set_uniform_matrix_2x4f(GLint location, glm::mat2x4 mat, bool bind_shader = true, bool transpose = false); + void set_uniform_matrix_2x4f(const char* uniform_name, glm::mat2x4 mat, bool bind_shader = true, bool transpose = false); + + void set_uniform_matrix_4x2f(GLint location, glm::mat4x2 mat, bool bind_shader = true, bool transpose = false); + void set_uniform_matrix_4x2f(const char* uniform_name, glm::mat4x2 mat, bool bind_shader = true, bool transpose = false); + + void set_uniform_matrix_3x4f(GLint location, glm::mat2x4 mat, bool bind_shader = true, bool transpose = false); + void set_uniform_matrix_3x4f(const char* uniform_name, glm::mat3x4 mat, bool bind_shader = true, bool transpose = false); + + void set_uniform_matrix_4x3f(GLint location, glm::mat4x3 mat, bool bind_shader = true, bool transpose = false); + void set_uniform_matrix_4x3f(const char* uniform_name, glm::mat4x3 mat, bool bind_shader = true, bool transpose = false); }; } \ No newline at end of file diff --git a/include/simpleengine/vector.h b/include/simpleengine/vector.h index 691cd38..f2b73ec 100644 --- a/include/simpleengine/vector.h +++ b/include/simpleengine/vector.h @@ -81,21 +81,21 @@ namespace simpleengine { this->inner_vec.z += z; } - glm::mat4 rotation_matrix(float degrees, glm::vec3 rotation_axis) const { + static glm::mat4 rotation_matrix(float degrees, glm::vec3 rotation_axis) { glm::mat4 trans = glm::mat4(1.0f); trans = glm::rotate(trans, glm::radians(degrees), rotation_axis); return trans; } - glm::mat4 rotation_x_matrix(float degrees) const { + static glm::mat4 rotation_x_matrix(float degrees) { return rotation_axis(degrees, glm::vec3(1.f, 0.f, 0.f)); } - glm::mat4 rotation_y_matrix(float degrees) const { + static glm::mat4 rotation_y_matrix(float degrees) { return rotation_axis(degrees, glm::vec3(0.f, 1.f, 0.f)); } - glm::mat4 rotation_z_matrix(float degrees) const { + static glm::mat4 rotation_z_matrix(float degrees) { return rotation_axis(degrees, glm::vec3(0.f, 0.f, 1.f)); } diff --git a/src/gfx/shader.cpp b/src/gfx/shader.cpp index 0e25ff9..0f99024 100644 --- a/src/gfx/shader.cpp +++ b/src/gfx/shader.cpp @@ -345,4 +345,139 @@ namespace simpleengine::gfx { int location = glGetUniformLocation(*program, uniform_name); set_uniform_uint_vec4(location, vec, bind_shader); } + + void Shader::set_uniform_matrix_2f(GLint location, glm::mat2 mat, bool bind_shader, bool transpose) { + if (bind_shader) { + use(); + } + glUniformMatrix2fv(location, 1, bind_shader, glm::value_ptr(mat)); + if (bind_shader) { + unuse(); + } + } + + void Shader::set_uniform_matrix_2f(const char* uniform_name, glm::mat2 mat, bool bind_shader, bool transpose) { + int location = glGetUniformLocation(*program, uniform_name); + set_uniform_matrix_2f(location, mat, bind_shader, transpose); + } + + void Shader::set_uniform_matrix_3f(GLint location, glm::mat3 mat, bool bind_shader, bool transpose) { + if (bind_shader) { + use(); + } + glUniformMatrix3fv(location, 1, bind_shader, glm::value_ptr(mat)); + if (bind_shader) { + unuse(); + } + } + + void Shader::set_uniform_matrix_3f(const char* uniform_name, glm::mat3 mat, bool bind_shader, bool transpose) { + int location = glGetUniformLocation(*program, uniform_name); + set_uniform_matrix_3f(location, mat, bind_shader, transpose); + } + + void Shader::set_uniform_matrix_4f(GLint location, glm::mat4 mat, bool bind_shader, bool transpose) { + if (bind_shader) { + use(); + } + glUniformMatrix4fv(location, 1, bind_shader, glm::value_ptr(mat)); + if (bind_shader) { + unuse(); + } + } + + void Shader::set_uniform_matrix_4f(const char* uniform_name, glm::mat4 mat, bool bind_shader, bool transpose) { + int location = glGetUniformLocation(*program, uniform_name); + set_uniform_matrix_4f(location, mat, bind_shader, transpose); + } + + void Shader::set_uniform_matrix_2x3f(GLint location, glm::mat2x3 mat, bool bind_shader, bool transpose) { + if (bind_shader) { + use(); + } + glUniformMatrix2x3fv(location, 1, bind_shader, glm::value_ptr(mat)); + if (bind_shader) { + unuse(); + } + } + + void Shader::set_uniform_matrix_2x3f(const char* uniform_name, glm::mat2x3 mat, bool bind_shader, bool transpose) { + int location = glGetUniformLocation(*program, uniform_name); + set_uniform_matrix_2x3f(location, mat, bind_shader, transpose); + } + + void Shader::set_uniform_matrix_3x2f(GLint location, glm::mat3x2 mat, bool bind_shader, bool transpose) { + if (bind_shader) { + use(); + } + glUniformMatrix3x2fv(location, 1, bind_shader, glm::value_ptr(mat)); + if (bind_shader) { + unuse(); + } + } + + void Shader::set_uniform_matrix_3x2f(const char* uniform_name, glm::mat3x2 mat, bool bind_shader, bool transpose) { + int location = glGetUniformLocation(*program, uniform_name); + set_uniform_matrix_3x2f(location, mat, bind_shader, transpose); + } + + void Shader::set_uniform_matrix_2x4f(GLint location, glm::mat2x4 mat, bool bind_shader, bool transpose) { + if (bind_shader) { + use(); + } + glUniformMatrix2x4fv(location, 1, bind_shader, glm::value_ptr(mat)); + if (bind_shader) { + unuse(); + } + } + + void Shader::set_uniform_matrix_2x4f(const char* uniform_name, glm::mat2x4 mat, bool bind_shader, bool transpose) { + int location = glGetUniformLocation(*program, uniform_name); + set_uniform_matrix_2x4f(location, mat, bind_shader, transpose); + } + + void Shader::set_uniform_matrix_4x2f(GLint location, glm::mat4x2 mat, bool bind_shader, bool transpose) { + if (bind_shader) { + use(); + } + glUniformMatrix4x2fv(location, 1, bind_shader, glm::value_ptr(mat)); + if (bind_shader) { + unuse(); + } + } + + void Shader::set_uniform_matrix_4x2f(const char* uniform_name, glm::mat4x2 mat, bool bind_shader, bool transpose) { + int location = glGetUniformLocation(*program, uniform_name); + set_uniform_matrix_4x2f(location, mat, bind_shader, transpose); + } + + void Shader::set_uniform_matrix_3x4f(GLint location, glm::mat2x4 mat, bool bind_shader, bool transpose) { + if (bind_shader) { + use(); + } + glUniformMatrix3x4fv(location, 1, bind_shader, glm::value_ptr(mat)); + if (bind_shader) { + unuse(); + } + } + + void Shader::set_uniform_matrix_3x4f(const char* uniform_name, glm::mat3x4 mat, bool bind_shader, bool transpose) { + int location = glGetUniformLocation(*program, uniform_name); + set_uniform_matrix_3x4f(location, mat, bind_shader, transpose); + } + + void Shader::set_uniform_matrix_4x3f(GLint location, glm::mat4x3 mat, bool bind_shader, bool transpose) { + if (bind_shader) { + use(); + } + glUniformMatrix4x3fv(location, 1, bind_shader, glm::value_ptr(mat)); + if (bind_shader) { + unuse(); + } + } + + void Shader::set_uniform_matrix_4x3f(const char* uniform_name, glm::mat4x3 mat, bool bind_shader, bool transpose) { + int location = glGetUniformLocation(*program, uniform_name); + set_uniform_matrix_4x3f(location, mat, bind_shader, transpose); + } } \ No newline at end of file