Add `set_uniform_matrix` in Shader

This commit is contained in:
SeanOMik 2021-11-30 18:30:07 -05:00
parent 7901413d7b
commit d89715a123
3 changed files with 167 additions and 4 deletions

View File

@ -6,6 +6,7 @@
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#include <glm/fwd.hpp>
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include "../event/event.h" #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(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_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);
}; };
} }

View File

@ -81,21 +81,21 @@ namespace simpleengine {
this->inner_vec.z += z; 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); glm::mat4 trans = glm::mat4(1.0f);
trans = glm::rotate(trans, glm::radians(degrees), rotation_axis); trans = glm::rotate(trans, glm::radians(degrees), rotation_axis);
return trans; 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)); 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)); 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)); return rotation_axis(degrees, glm::vec3(0.f, 0.f, 1.f));
} }

View File

@ -345,4 +345,139 @@ namespace simpleengine::gfx {
int location = glGetUniformLocation(*program, uniform_name); int location = glGetUniformLocation(*program, uniform_name);
set_uniform_uint_vec4(location, vec, bind_shader); 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);
}
} }