Remove use of Shader::use() by keeping track of the inuse shader program

This commit is contained in:
SeanOMik 2022-10-12 23:01:31 -04:00
parent 62321132cc
commit 4c3a2729c7
Signed by: SeanOMik
GPG Key ID: 568F326C7EB33ACB
6 changed files with 205 additions and 298 deletions

View File

@ -18,8 +18,8 @@ namespace simpleengine::gfx {
virtual void update(const float& delta_time) override { virtual void update(const float& delta_time) override {
shader.use(); shader.use();
shader.set_uniform_float_vec3("u_light_position", position, false); shader.set_uniform_float_vec3("u_light_position", position);
shader.set_uniform_float_vec3("u_light_color", color, false); shader.set_uniform_float_vec3("u_light_color", color);
shader.unuse(); shader.unuse();
} }

View File

@ -26,6 +26,10 @@ namespace simpleengine::gfx {
private: private:
GLFWwindow* window; GLFWwindow* window;
protected: protected:
bool is_initialized = false;
void check_if_initialized();
public: public:
std::queue<RenderingJob> transparent_render_queue; std::queue<RenderingJob> transparent_render_queue;
std::queue<RenderingJob> other_render_queue; std::queue<RenderingJob> other_render_queue;

View File

@ -39,6 +39,9 @@ namespace simpleengine::gfx {
}; };
class Shader { class Shader {
private:
static GLuint inuse_program;
//static GLuint inuse_shader;
public: public:
GLuint program; GLuint program;
GLuint shader; GLuint shader;
@ -92,7 +95,7 @@ namespace simpleengine::gfx {
* @brief Un-use the shader program by using the id of "0". * @brief Un-use the shader program by using the id of "0".
* *
*/ */
static void unuse(); void unuse();
/** /**
* @brief Attach the shader to a program. No need to call this if its already attached once. * @brief Attach the shader to a program. No need to call this if its already attached once.
@ -181,73 +184,73 @@ namespace simpleengine::gfx {
*/ */
GLdouble get_uniform_double(const char* uniform_name) const; GLdouble get_uniform_double(const char* uniform_name) const;
void set_uniform_float(GLint location, GLfloat fl, bool bind_shader = true); void set_uniform_float(GLint location, GLfloat fl);
void set_uniform_float(const char* uniform_name, GLfloat fl, bool bind_shader = true); void set_uniform_float(const char* uniform_name, GLfloat fl);
void set_uniform_float_array(GLint location, int count, GLfloat* arr, bool bind_shader = true); void set_uniform_float_array(GLint location, int count, GLfloat* arr);
void set_uniform_float_array(const char* uniform_name, int count, GLfloat* arr, bool bind_shader = true); void set_uniform_float_array(const char* uniform_name, int count, GLfloat* arr);
void set_uniform_float_vec2(GLint location, glm::vec2 vec, bool bind_shader = true); void set_uniform_float_vec2(GLint location, glm::vec2 vec);
void set_uniform_float_vec2(const char* uniform_name, glm::vec2 vec, bool bind_shader = true); void set_uniform_float_vec2(const char* uniform_name, glm::vec2 vec);
void set_uniform_float_vec3(GLint location, glm::vec3 vec, bool bind_shader = true); void set_uniform_float_vec3(GLint location, glm::vec3 vec);
void set_uniform_float_vec3(const char* uniform_name, glm::vec3 vec, bool bind_shader = true); void set_uniform_float_vec3(const char* uniform_name, glm::vec3 vec);
void set_uniform_float_vec4(GLint location, glm::vec4 vec, bool bind_shader = true); void set_uniform_float_vec4(GLint location, glm::vec4 vec);
void set_uniform_float_vec4(const char* uniform_name, glm::vec4 vec, bool bind_shader = true); void set_uniform_float_vec4(const char* uniform_name, glm::vec4 vec);
void set_uniform_int(GLint location, GLint i, bool bind_shader = true); void set_uniform_int(GLint location, GLint i);
void set_uniform_int(const char* uniform_name, GLint i, bool bind_shader = true); void set_uniform_int(const char* uniform_name, GLint i);
void set_uniform_int_array(GLint location, int count, GLint* arr, bool bind_shader = true); void set_uniform_int_array(GLint location, int count, GLint* arr);
void set_uniform_int_array(const char* uniform_name, int count, GLint* arr, bool bind_shader = true); void set_uniform_int_array(const char* uniform_name, int count, GLint* arr);
void set_uniform_int_vec2(GLint location, glm::ivec2 vec, bool bind_shader = true); void set_uniform_int_vec2(GLint location, glm::ivec2 vec);
void set_uniform_int_vec2(const char* uniform_name, glm::ivec2 vec, bool bind_shader = true); void set_uniform_int_vec2(const char* uniform_name, glm::ivec2 vec);
void set_uniform_int_vec3(GLint location, glm::ivec3 vec, bool bind_shader = true); void set_uniform_int_vec3(GLint location, glm::ivec3 vec);
void set_uniform_int_vec3(const char* uniform_name, glm::ivec3 vec, bool bind_shader = true); void set_uniform_int_vec3(const char* uniform_name, glm::ivec3 vec);
void set_uniform_int_vec4(GLint location, glm::ivec4 vec, bool bind_shader = true); void set_uniform_int_vec4(GLint location, glm::ivec4 vec);
void set_uniform_int_vec4(const char* uniform_name, glm::ivec4 vec, bool bind_shader = true); void set_uniform_int_vec4(const char* uniform_name, glm::ivec4 vec);
void set_uniform_uint(GLint location, GLuint ui, bool bind_shader = true); void set_uniform_uint(GLint location, GLuint ui);
void set_uniform_uint(const char* uniform_name, GLuint ui, bool bind_shader = true); void set_uniform_uint(const char* uniform_name, GLuint ui);
void set_uniform_uint_vec2(GLint location, glm::uvec2 vec, bool bind_shader = true); void set_uniform_uint_vec2(GLint location, glm::uvec2 vec);
void set_uniform_uint_vec2(const char* uniform_name, glm::uvec2 vec, bool bind_shader = true); void set_uniform_uint_vec2(const char* uniform_name, glm::uvec2 vec);
void set_uniform_uint_vec3(GLint location, glm::uvec3 vec, bool bind_shader = true); void set_uniform_uint_vec3(GLint location, glm::uvec3 vec);
void set_uniform_uint_vec3(const char* uniform_name, glm::uvec3 vec, bool bind_shader = true); void set_uniform_uint_vec3(const char* uniform_name, glm::uvec3 vec);
void set_uniform_uint_vec4(GLint location, glm::uvec4 vec, bool bind_shader = true); void set_uniform_uint_vec4(GLint location, glm::uvec4 vec);
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);
void set_uniform_matrix_2f(GLint location, glm::mat2 mat, bool bind_shader = true, bool transpose = false); void set_uniform_matrix_2f(GLint location, glm::mat2 mat, 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_2f(const char* uniform_name, glm::mat2 mat, 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(GLint location, glm::mat3 mat, 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_3f(const char* uniform_name, glm::mat3 mat, 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(GLint location, glm::mat4 mat, 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_4f(const char* uniform_name, glm::mat4 mat, 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(GLint location, glm::mat2x3 mat, 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_2x3f(const char* uniform_name, glm::mat2x3 mat, 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(GLint location, glm::mat3x2 mat, 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_3x2f(const char* uniform_name, glm::mat3x2 mat, 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(GLint location, glm::mat2x4 mat, 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_2x4f(const char* uniform_name, glm::mat2x4 mat, 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(GLint location, glm::mat4x2 mat, 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_4x2f(const char* uniform_name, glm::mat4x2 mat, 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(GLint location, glm::mat2x4 mat, 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_3x4f(const char* uniform_name, glm::mat3x4 mat, 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(GLint location, glm::mat4x3 mat, bool transpose = false);
void set_uniform_matrix_4x3f(const char* uniform_name, glm::mat4x3 mat, bool bind_shader = true, bool transpose = false); void set_uniform_matrix_4x3f(const char* uniform_name, glm::mat4x3 mat, bool transpose = false);
}; };
} }

View File

@ -96,9 +96,9 @@ namespace simpleengine {
view_matrix = glm::lookAt(position, position + camera_front, camera_up); view_matrix = glm::lookAt(position, position + camera_front, camera_up);
shader.use(); shader.use();
shader.set_uniform_float_vec3("u_view_pos", position, false); shader.set_uniform_float_vec3("u_view_pos", position);
shader.set_uniform_matrix_4f("u_view_matrix", view_matrix, false); shader.set_uniform_matrix_4f("u_view_matrix", view_matrix);
shader.set_uniform_matrix_4f("u_projection_matrix", projection_matrix, false); shader.set_uniform_matrix_4f("u_projection_matrix", projection_matrix);
shader.unuse(); shader.unuse();
} }
} }

View File

@ -11,8 +11,8 @@
#include <assimp/material.h> #include <assimp/material.h>
#include <functional> #include <functional>
#include <glm/geometric.hpp> #include <glm/geometric.hpp>
#include <stdexcept>
// TODO: Check if initialized before trying to do stuff
namespace simpleengine::gfx { namespace simpleengine::gfx {
void create_mesh_buffers(simpleengine::gfx::Mesh &mesh); void create_mesh_buffers(simpleengine::gfx::Mesh &mesh);
@ -32,6 +32,13 @@ namespace simpleengine::gfx {
(type == GL_DEBUG_TYPE_ERROR ? "** GL ERROR **" : ""), type, severity, message); (type == GL_DEBUG_TYPE_ERROR ? "** GL ERROR **" : ""), type, severity, message);
} }
void Renderer::check_if_initialized() {
if (!is_initialized) {
std::cerr << "Renderer is not initialized!" << std::endl;
throw std::runtime_error("Renderer is not initialized!");
}
}
void Renderer::enable_debug() { void Renderer::enable_debug() {
glEnable(GL_DEBUG_OUTPUT); glEnable(GL_DEBUG_OUTPUT);
glDebugMessageCallback(debug_message_callback, 0); glDebugMessageCallback(debug_message_callback, 0);
@ -83,14 +90,14 @@ namespace simpleengine::gfx {
} }
// Enable VAO attributes // Enable VAO attributes
vao.enable_attrib(vbo, 0, 3, GL_FLOAT, sizeof(LitVertex), offsetof(LitVertex, position), false); vao.enable_attrib(vbo, 0, 3, GL_FLOAT, sizeof(LitVertex), offsetof(LitVertex, position));
vao.enable_attrib(vbo, 1, 3, GL_FLOAT, sizeof(LitVertex), offsetof(LitVertex, color), false); vao.enable_attrib(vbo, 1, 3, GL_FLOAT, sizeof(LitVertex), offsetof(LitVertex, color));
vao.enable_attrib(vbo, 2, 3, GL_FLOAT, sizeof(LitVertex), offsetof(LitVertex, normal), false); vao.enable_attrib(vbo, 2, 3, GL_FLOAT, sizeof(LitVertex), offsetof(LitVertex, normal));
vao.enable_attrib(vbo, 3, 2, GL_FLOAT, sizeof(LitVertex), offsetof(LitVertex, tex_coord), false); vao.enable_attrib(vbo, 3, 2, GL_FLOAT, sizeof(LitVertex), offsetof(LitVertex, tex_coord));
rendering_mesh->tangent_vbo.buffer(rendering_mesh->tangents.data(), 0, rendering_mesh->tangent_vbo.buffer(rendering_mesh->tangents.data(), 0,
rendering_mesh->tangents.size() * sizeof(Vectorf)); rendering_mesh->tangents.size() * sizeof(Vectorf));
vao.enable_attrib(rendering_mesh->tangent_vbo, 4, 3, GL_FLOAT, sizeof(Vectorf), 0, false); vao.enable_attrib(rendering_mesh->tangent_vbo, 4, 3, GL_FLOAT, sizeof(Vectorf), 0);
vbo.unbind(); vbo.unbind();
vao.unbind(); vao.unbind();
@ -101,7 +108,9 @@ namespace simpleengine::gfx {
} }
} }
void Renderer::update(const float &delta_time) {} void Renderer::update(const float &delta_time) {
check_if_initialized();
}
void Renderer::initialize() { void Renderer::initialize() {
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
@ -111,6 +120,8 @@ namespace simpleengine::gfx {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
this->is_initialized = true;
std::cout << "Base Renderer initialized" << std::endl; std::cout << "Base Renderer initialized" << std::endl;
} }
@ -125,21 +136,21 @@ namespace simpleengine::gfx {
bool Renderer::render_job(const RenderingJob &job) { bool Renderer::render_job(const RenderingJob &job) {
Mesh *mesh = job.rendering_mesh; Mesh *mesh = job.rendering_mesh;
shader.set_uniform_matrix_4f("u_transform_matrix", job.transform_mat, false); shader.set_uniform_matrix_4f("u_transform_matrix", job.transform_mat);
std::optional<Material> &material = mesh->material; std::optional<Material> &material = mesh->material;
if (material.has_value()) { if (material.has_value()) {
shader.set_uniform_float("u_material.ambient_strength", material->ambient_strength, false); shader.set_uniform_float("u_material.ambient_strength", material->ambient_strength);
shader.set_uniform_float("u_material.diffuse_strength", material->diffuse_strength, false); shader.set_uniform_float("u_material.diffuse_strength", material->diffuse_strength);
shader.set_uniform_float("u_material.specular_strength", material->specular_strength, false); shader.set_uniform_float("u_material.specular_strength", material->specular_strength);
shader.set_uniform_float("u_material.shine_factor", material->shine_factor, false); shader.set_uniform_float("u_material.shine_factor", material->shine_factor);
// shader.set_uniform_float("u_material.reflect_factor", .1f, false); // shader.set_uniform_float("u_material.reflect_factor", .1f);
auto diffuse_maps = material->textures.find(aiTextureType_DIFFUSE); auto diffuse_maps = material->textures.find(aiTextureType_DIFFUSE);
auto diffuse_map = diffuse_maps->second.front(); auto diffuse_map = diffuse_maps->second.front();
shader.set_uniform_int("u_material.diffuse", 0, false); shader.set_uniform_int("u_material.diffuse", 0);
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
diffuse_map->bind(); diffuse_map->bind();
@ -149,13 +160,13 @@ namespace simpleengine::gfx {
if (specular_maps != material->textures.end()) { if (specular_maps != material->textures.end()) {
auto spec = specular_maps->second.front(); auto spec = specular_maps->second.front();
shader.set_uniform_int("u_material.has_specular_map", 1, false); shader.set_uniform_int("u_material.has_specular_map", 1);
shader.set_uniform_int("u_material.specular_map", 1, false); shader.set_uniform_int("u_material.specular_map", 1);
glActiveTexture(GL_TEXTURE1); glActiveTexture(GL_TEXTURE1);
spec->bind(); spec->bind();
} else { } else {
shader.set_uniform_int("u_material.has_specular_map", 0, false); shader.set_uniform_int("u_material.has_specular_map", 0);
} }
// Apply the normal map if it exists // Apply the normal map if it exists
@ -163,13 +174,13 @@ namespace simpleengine::gfx {
if (normal_maps != material->textures.end()) { if (normal_maps != material->textures.end()) {
auto normal = normal_maps->second.front(); auto normal = normal_maps->second.front();
shader.set_uniform_int("u_material.has_normal_map", 1, false); shader.set_uniform_int("u_material.has_normal_map", 1);
shader.set_uniform_int("u_material.normal_map", 2, false); shader.set_uniform_int("u_material.normal_map", 2);
glActiveTexture(GL_TEXTURE2); glActiveTexture(GL_TEXTURE2);
normal->bind(); normal->bind();
} else { } else {
shader.set_uniform_int("u_material.has_normal_map", 0, false); shader.set_uniform_int("u_material.has_normal_map", 0);
} }
} }
@ -184,8 +195,6 @@ namespace simpleengine::gfx {
} }
void Renderer::render_job_queue(std::queue<RenderingJob> &rendering_queue) { void Renderer::render_job_queue(std::queue<RenderingJob> &rendering_queue) {
shader.use();
while (!rendering_queue.empty()) { while (!rendering_queue.empty()) {
// Get the job from the queue, we'll remove it after we render. // Get the job from the queue, we'll remove it after we render.
RenderingJob &job = rendering_queue.front(); RenderingJob &job = rendering_queue.front();
@ -197,25 +206,21 @@ namespace simpleengine::gfx {
rendering_queue.pop(); rendering_queue.pop();
} }
} }
shader.unuse();
} }
void Renderer::render_job_queue(std::map<float, RenderingJob, std::greater<>>& rendering_queue) { void Renderer::render_job_queue(std::map<float, RenderingJob, std::greater<>>& rendering_queue) {
shader.use();
// Render each job then clear the queue // Render each job then clear the queue
for (const auto& it : rendering_queue) { for (const auto& it : rendering_queue) {
this->render_job(it.second); this->render_job(it.second);
} }
rendering_queue.clear(); rendering_queue.clear();
shader.unuse();
} }
void Renderer::render() { void Renderer::render() {
check_if_initialized();
// Render other (opaque) objects first // Render other (opaque) objects first
this->render_job_queue(other_render_queue); render_job_queue(other_render_queue);
// Render transparent objects // Render transparent objects
std::map<float, RenderingJob, std::greater<>> transparent_jobs; std::map<float, RenderingJob, std::greater<>> transparent_jobs;
@ -228,6 +233,6 @@ namespace simpleengine::gfx {
transparent_render_queue.pop(); transparent_render_queue.pop();
} }
this->render_job_queue(transparent_jobs); render_job_queue(transparent_jobs);
} }
} // namespace simpleengine::gfx } // namespace simpleengine::gfx

View File

@ -5,6 +5,8 @@
#include <memory> #include <memory>
namespace simpleengine::gfx { namespace simpleengine::gfx {
GLuint Shader::inuse_program = 0;
Shader::Shader(GLuint program) : program(program) { Shader::Shader(GLuint program) : program(program) {
} }
@ -99,11 +101,17 @@ namespace simpleengine::gfx {
} }
void Shader::use() const { void Shader::use() const {
glUseProgram(program); if (Shader::inuse_program != program) {
glUseProgram(program);
Shader::inuse_program = program;
}
} }
void Shader::unuse() { void Shader::unuse() {
glUseProgram(0); glUseProgram(0);
Shader::inuse_program = 0;
} }
void Shader::attach(GLuint program) { void Shader::attach(GLuint program) {
@ -174,347 +182,234 @@ namespace simpleengine::gfx {
return get_uniform_double(location); return get_uniform_double(location);
} }
void Shader::set_uniform_float(GLint location, GLfloat fl, bool bind_shader) { void Shader::set_uniform_float(GLint location, GLfloat fl) {
if (bind_shader) { use();
use();
}
glUniform1fv(location, 1, &fl); glUniform1fv(location, 1, &fl);
if (bind_shader) {
unuse();
}
} }
void Shader::set_uniform_float(const char* uniform_name, GLfloat fl, bool bind_shader) { void Shader::set_uniform_float(const char* uniform_name, GLfloat fl) {
int location = get_uniform_location(uniform_name); int location = get_uniform_location(uniform_name);
set_uniform_float(location, fl, bind_shader); set_uniform_float(location, fl);
} }
void Shader::set_uniform_float_array(GLint location, int count, GLfloat* arr, bool bind_shader) { void Shader::set_uniform_float_array(GLint location, int count, GLfloat* arr) {
if (bind_shader) { use();
use();
}
glUniform1fv(location, count, arr); glUniform1fv(location, count, arr);
if (bind_shader) {
unuse();
}
} }
void Shader::set_uniform_float_array(const char* uniform_name, int count, GLfloat* arr, bool bind_shader) { void Shader::set_uniform_float_array(const char* uniform_name, int count, GLfloat* arr) {
int location = get_uniform_location(uniform_name); int location = get_uniform_location(uniform_name);
set_uniform_float_array(location, count, arr, bind_shader); set_uniform_float_array(location, count, arr);
} }
void Shader::set_uniform_float_vec2(GLint location, glm::vec2 vec, bool bind_shader) { void Shader::set_uniform_float_vec2(GLint location, glm::vec2 vec) {
if (bind_shader) { use();
use();
}
glUniform2fv(location, 1, glm::value_ptr(vec)); glUniform2fv(location, 1, glm::value_ptr(vec));
if (bind_shader) {
unuse();
}
} }
void Shader::set_uniform_float_vec2(const char* uniform_name, glm::vec2 vec, bool bind_shader) { void Shader::set_uniform_float_vec2(const char* uniform_name, glm::vec2 vec) {
int location = get_uniform_location(uniform_name); int location = get_uniform_location(uniform_name);
set_uniform_float_vec2(location, vec, bind_shader); set_uniform_float_vec2(location, vec);
} }
void Shader::set_uniform_float_vec3(GLint location, glm::vec3 vec, bool bind_shader) { void Shader::set_uniform_float_vec3(GLint location, glm::vec3 vec) {
if (bind_shader) { use();
use();
}
glUniform3fv(location, 1, glm::value_ptr(vec)); glUniform3fv(location, 1, glm::value_ptr(vec));
if (bind_shader) {
unuse();
}
} }
void Shader::set_uniform_float_vec3(const char* uniform_name, glm::vec3 vec, bool bind_shader) { void Shader::set_uniform_float_vec3(const char* uniform_name, glm::vec3 vec) {
int location = get_uniform_location(uniform_name); int location = get_uniform_location(uniform_name);
set_uniform_float_vec3(location, vec, bind_shader); set_uniform_float_vec3(location, vec);
} }
void Shader::set_uniform_float_vec4(GLint location, glm::vec4 vec, bool bind_shader) { void Shader::set_uniform_float_vec4(GLint location, glm::vec4 vec) {
if (bind_shader) { use();
use();
}
glUniform4fv(location, 1, glm::value_ptr(vec)); glUniform4fv(location, 1, glm::value_ptr(vec));
if (bind_shader) {
unuse();
}
} }
void Shader::set_uniform_float_vec4(const char* uniform_name, glm::vec4 vec, bool bind_shader) { void Shader::set_uniform_float_vec4(const char* uniform_name, glm::vec4 vec) {
int location = get_uniform_location(uniform_name); int location = get_uniform_location(uniform_name);
set_uniform_float_vec4(location, vec, bind_shader); set_uniform_float_vec4(location, vec);
} }
void Shader::set_uniform_int(GLint location, GLint i, bool bind_shader) { void Shader::set_uniform_int(GLint location, GLint i) {
if (bind_shader) { use();
use();
}
glUniform1iv(location, 1, &i); glUniform1iv(location, 1, &i);
if (bind_shader) {
unuse();
}
} }
void Shader::set_uniform_int(const char* uniform_name, GLint i, bool bind_shader) { void Shader::set_uniform_int(const char* uniform_name, GLint i) {
int location = get_uniform_location(uniform_name); int location = get_uniform_location(uniform_name);
set_uniform_int(location, i, bind_shader); set_uniform_int(location, i);
} }
void Shader::set_uniform_int_array(GLint location, int count, GLint* arr, bool bind_shader) { void Shader::set_uniform_int_array(GLint location, int count, GLint* arr) {
if (bind_shader) { use();
use();
}
glUniform1iv(location, count, arr); glUniform1iv(location, count, arr);
} }
void Shader::set_uniform_int_array(const char* uniform_name, int count, GLint* arr, bool bind_shader) { void Shader::set_uniform_int_array(const char* uniform_name, int count, GLint* arr) {
int location = get_uniform_location(uniform_name); int location = get_uniform_location(uniform_name);
set_uniform_int_array(location, count, arr, bind_shader); set_uniform_int_array(location, count, arr);
} }
void Shader::set_uniform_int_vec2(GLint location, glm::ivec2 vec, bool bind_shader) { void Shader::set_uniform_int_vec2(GLint location, glm::ivec2 vec) {
if (bind_shader) { use();
use();
}
glUniform2iv(location, 1, glm::value_ptr(vec)); glUniform2iv(location, 1, glm::value_ptr(vec));
if (bind_shader) {
unuse();
}
} }
void Shader::set_uniform_int_vec2(const char* uniform_name, glm::ivec2 vec, bool bind_shader) { void Shader::set_uniform_int_vec2(const char* uniform_name, glm::ivec2 vec) {
int location = get_uniform_location(uniform_name); int location = get_uniform_location(uniform_name);
set_uniform_int_vec2(location, vec, bind_shader); set_uniform_int_vec2(location, vec);
} }
void Shader::set_uniform_int_vec3(GLint location, glm::ivec3 vec, bool bind_shader) { void Shader::set_uniform_int_vec3(GLint location, glm::ivec3 vec) {
if (bind_shader) { use();
use();
}
glUniform3iv(location, 1, glm::value_ptr(vec)); glUniform3iv(location, 1, glm::value_ptr(vec));
if (bind_shader) {
unuse();
}
} }
void Shader::set_uniform_int_vec3(const char* uniform_name, glm::ivec3 vec, bool bind_shader) { void Shader::set_uniform_int_vec3(const char* uniform_name, glm::ivec3 vec) {
int location = get_uniform_location(uniform_name); int location = get_uniform_location(uniform_name);
set_uniform_int_vec3(location, vec, bind_shader); set_uniform_int_vec3(location, vec);
} }
void Shader::set_uniform_int_vec4(GLint location, glm::ivec4 vec, bool bind_shader) { void Shader::set_uniform_int_vec4(GLint location, glm::ivec4 vec) {
if (bind_shader) { use();
use();
}
glUniform4iv(location, 1, glm::value_ptr(vec)); glUniform4iv(location, 1, glm::value_ptr(vec));
if (bind_shader) {
unuse();
}
} }
void Shader::set_uniform_int_vec4(const char* uniform_name, glm::ivec4 vec, bool bind_shader) { void Shader::set_uniform_int_vec4(const char* uniform_name, glm::ivec4 vec) {
int location = get_uniform_location(uniform_name); int location = get_uniform_location(uniform_name);
set_uniform_int_vec4(location, vec, bind_shader); set_uniform_int_vec4(location, vec);
} }
void Shader::set_uniform_uint(GLint location, GLuint ui, bool bind_shader) { void Shader::set_uniform_uint(GLint location, GLuint ui) {
if (bind_shader) { use();
use();
}
glUniform1uiv(location, 1, &ui); glUniform1uiv(location, 1, &ui);
if (bind_shader) {
unuse();
}
} }
void Shader::set_uniform_uint(const char* uniform_name, GLuint ui, bool bind_shader) { void Shader::set_uniform_uint(const char* uniform_name, GLuint ui) {
int location = get_uniform_location(uniform_name); int location = get_uniform_location(uniform_name);
set_uniform_uint(location, ui, bind_shader); set_uniform_uint(location, ui);
} }
void Shader::set_uniform_uint_vec2(GLint location, glm::uvec2 vec, bool bind_shader) { void Shader::set_uniform_uint_vec2(GLint location, glm::uvec2 vec) {
if (bind_shader) { use();
use();
}
glUniform2uiv(location, 1,glm::value_ptr(vec)); glUniform2uiv(location, 1,glm::value_ptr(vec));
if (bind_shader) {
unuse();
}
} }
void Shader::set_uniform_uint_vec2(const char* uniform_name, glm::uvec2 vec, bool bind_shader) { void Shader::set_uniform_uint_vec2(const char* uniform_name, glm::uvec2 vec) {
int location = get_uniform_location(uniform_name); int location = get_uniform_location(uniform_name);
set_uniform_uint_vec2(location, vec, bind_shader); set_uniform_uint_vec2(location, vec);
} }
void Shader::set_uniform_uint_vec3(GLint location, glm::uvec3 vec, bool bind_shader) { void Shader::set_uniform_uint_vec3(GLint location, glm::uvec3 vec) {
if (bind_shader) { use();
use();
}
glUniform3uiv(location, 1, glm::value_ptr(vec)); glUniform3uiv(location, 1, glm::value_ptr(vec));
if (bind_shader) {
unuse();
}
} }
void Shader::set_uniform_uint_vec3(const char* uniform_name, glm::uvec3 vec, bool bind_shader) { void Shader::set_uniform_uint_vec3(const char* uniform_name, glm::uvec3 vec) {
int location = get_uniform_location(uniform_name); int location = get_uniform_location(uniform_name);
set_uniform_uint_vec3(location, vec, bind_shader); set_uniform_uint_vec3(location, vec);
} }
void Shader::set_uniform_uint_vec4(GLint location, glm::uvec4 vec, bool bind_shader) { void Shader::set_uniform_uint_vec4(GLint location, glm::uvec4 vec) {
if (bind_shader) { use();
use();
}
glUniform4uiv(location, 1, glm::value_ptr(vec)); glUniform4uiv(location, 1, glm::value_ptr(vec));
if (bind_shader) {
unuse();
}
} }
void Shader::set_uniform_uint_vec4(const char* uniform_name, glm::uvec4 vec, bool bind_shader) { void Shader::set_uniform_uint_vec4(const char* uniform_name, glm::uvec4 vec) {
int location = get_uniform_location(uniform_name); int location = get_uniform_location(uniform_name);
set_uniform_uint_vec4(location, vec, bind_shader); set_uniform_uint_vec4(location, vec);
} }
void Shader::set_uniform_matrix_2f(GLint location, glm::mat2 mat, bool bind_shader, bool transpose) { void Shader::set_uniform_matrix_2f(GLint location, glm::mat2 mat, bool transpose) {
if (bind_shader) { use();
use(); glUniformMatrix2fv(location, 1, transpose, glm::value_ptr(mat));
}
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) { void Shader::set_uniform_matrix_2f(const char* uniform_name, glm::mat2 mat, bool transpose) {
int location = get_uniform_location(uniform_name); int location = get_uniform_location(uniform_name);
set_uniform_matrix_2f(location, mat, bind_shader, transpose); set_uniform_matrix_2f(location, mat, transpose);
} }
void Shader::set_uniform_matrix_3f(GLint location, glm::mat3 mat, bool bind_shader, bool transpose) { void Shader::set_uniform_matrix_3f(GLint location, glm::mat3 mat, bool transpose) {
if (bind_shader) { use();
use(); glUniformMatrix3fv(location, 1, transpose, glm::value_ptr(mat));
}
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) { void Shader::set_uniform_matrix_3f(const char* uniform_name, glm::mat3 mat, bool transpose) {
int location = get_uniform_location(uniform_name); int location = get_uniform_location(uniform_name);
set_uniform_matrix_3f(location, mat, bind_shader, transpose); set_uniform_matrix_3f(location, mat, transpose);
} }
void Shader::set_uniform_matrix_4f(GLint location, glm::mat4 mat, bool bind_shader, bool transpose) { void Shader::set_uniform_matrix_4f(GLint location, glm::mat4 mat, bool transpose) {
if (bind_shader) { use();
use(); glUniformMatrix4fv(location, 1, transpose, glm::value_ptr(mat));
}
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) { void Shader::set_uniform_matrix_4f(const char* uniform_name, glm::mat4 mat, bool transpose) {
int location = get_uniform_location(uniform_name); int location = get_uniform_location(uniform_name);
set_uniform_matrix_4f(location, mat, bind_shader, transpose); set_uniform_matrix_4f(location, mat, transpose);
} }
void Shader::set_uniform_matrix_2x3f(GLint location, glm::mat2x3 mat, bool bind_shader, bool transpose) { void Shader::set_uniform_matrix_2x3f(GLint location, glm::mat2x3 mat, bool transpose) {
if (bind_shader) { use();
use(); glUniformMatrix2x3fv(location, 1, transpose, glm::value_ptr(mat));
}
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) { void Shader::set_uniform_matrix_2x3f(const char* uniform_name, glm::mat2x3 mat, bool transpose) {
int location = get_uniform_location(uniform_name); int location = get_uniform_location(uniform_name);
set_uniform_matrix_2x3f(location, mat, bind_shader, transpose); set_uniform_matrix_2x3f(location, mat, transpose);
} }
void Shader::set_uniform_matrix_3x2f(GLint location, glm::mat3x2 mat, bool bind_shader, bool transpose) { void Shader::set_uniform_matrix_3x2f(GLint location, glm::mat3x2 mat, bool transpose) {
if (bind_shader) { use();
use(); glUniformMatrix3x2fv(location, 1, transpose, glm::value_ptr(mat));
}
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) { void Shader::set_uniform_matrix_3x2f(const char* uniform_name, glm::mat3x2 mat, bool transpose) {
int location = get_uniform_location(uniform_name); int location = get_uniform_location(uniform_name);
set_uniform_matrix_3x2f(location, mat, bind_shader, transpose); set_uniform_matrix_3x2f(location, mat, transpose);
} }
void Shader::set_uniform_matrix_2x4f(GLint location, glm::mat2x4 mat, bool bind_shader, bool transpose) { void Shader::set_uniform_matrix_2x4f(GLint location, glm::mat2x4 mat, bool transpose) {
if (bind_shader) { use();
use(); glUniformMatrix2x4fv(location, 1, transpose, glm::value_ptr(mat));
}
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) { void Shader::set_uniform_matrix_2x4f(const char* uniform_name, glm::mat2x4 mat, bool transpose) {
int location = get_uniform_location(uniform_name); int location = get_uniform_location(uniform_name);
set_uniform_matrix_2x4f(location, mat, bind_shader, transpose); set_uniform_matrix_2x4f(location, mat, transpose);
} }
void Shader::set_uniform_matrix_4x2f(GLint location, glm::mat4x2 mat, bool bind_shader, bool transpose) { void Shader::set_uniform_matrix_4x2f(GLint location, glm::mat4x2 mat, bool transpose) {
if (bind_shader) { use();
use(); glUniformMatrix4x2fv(location, 1, transpose, glm::value_ptr(mat));
}
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) { void Shader::set_uniform_matrix_4x2f(const char* uniform_name, glm::mat4x2 mat, bool transpose) {
int location = get_uniform_location(uniform_name); int location = get_uniform_location(uniform_name);
set_uniform_matrix_4x2f(location, mat, bind_shader, transpose); set_uniform_matrix_4x2f(location, mat, transpose);
} }
void Shader::set_uniform_matrix_3x4f(GLint location, glm::mat2x4 mat, bool bind_shader, bool transpose) { void Shader::set_uniform_matrix_3x4f(GLint location, glm::mat2x4 mat, bool transpose) {
if (bind_shader) { use();
use(); glUniformMatrix3x4fv(location, 1, transpose, glm::value_ptr(mat));
}
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) { void Shader::set_uniform_matrix_3x4f(const char* uniform_name, glm::mat3x4 mat, bool transpose) {
int location = get_uniform_location(uniform_name); int location = get_uniform_location(uniform_name);
set_uniform_matrix_3x4f(location, mat, bind_shader, transpose); set_uniform_matrix_3x4f(location, mat, transpose);
} }
void Shader::set_uniform_matrix_4x3f(GLint location, glm::mat4x3 mat, bool bind_shader, bool transpose) { void Shader::set_uniform_matrix_4x3f(GLint location, glm::mat4x3 mat, bool transpose) {
if (bind_shader) { use();
use(); glUniformMatrix4x3fv(location, 1, transpose, glm::value_ptr(mat));
}
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) { void Shader::set_uniform_matrix_4x3f(const char* uniform_name, glm::mat4x3 mat, bool transpose) {
int location = get_uniform_location(uniform_name); int location = get_uniform_location(uniform_name);
set_uniform_matrix_4x3f(location, mat, bind_shader, transpose); set_uniform_matrix_4x3f(location, mat, transpose);
} }
} }