diff --git a/include/simpleengine/gfx/light.h b/include/simpleengine/gfx/light.h index 86f362a..f534792 100644 --- a/include/simpleengine/gfx/light.h +++ b/include/simpleengine/gfx/light.h @@ -18,8 +18,8 @@ namespace simpleengine::gfx { virtual void update(const float& delta_time) override { shader.use(); - shader.set_uniform_float_vec3("u_light_position", position, false); - shader.set_uniform_float_vec3("u_light_color", color, false); + shader.set_uniform_float_vec3("u_light_position", position); + shader.set_uniform_float_vec3("u_light_color", color); shader.unuse(); } diff --git a/include/simpleengine/gfx/renderer.h b/include/simpleengine/gfx/renderer.h index 684e7b7..bb0e06b 100644 --- a/include/simpleengine/gfx/renderer.h +++ b/include/simpleengine/gfx/renderer.h @@ -26,6 +26,10 @@ namespace simpleengine::gfx { private: GLFWwindow* window; protected: + bool is_initialized = false; + + void check_if_initialized(); + public: std::queue transparent_render_queue; std::queue other_render_queue; diff --git a/include/simpleengine/gfx/shader.h b/include/simpleengine/gfx/shader.h index b6defe9..c1179a3 100644 --- a/include/simpleengine/gfx/shader.h +++ b/include/simpleengine/gfx/shader.h @@ -39,6 +39,9 @@ namespace simpleengine::gfx { }; class Shader { + private: + static GLuint inuse_program; + //static GLuint inuse_shader; public: GLuint program; GLuint shader; @@ -92,7 +95,7 @@ namespace simpleengine::gfx { * @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. @@ -181,73 +184,73 @@ namespace simpleengine::gfx { */ 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(const char* uniform_name, GLfloat fl, bool bind_shader = true); + void set_uniform_float(GLint location, GLfloat fl); + 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(const char* uniform_name, 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); - void set_uniform_float_vec2(GLint location, glm::vec2 vec, bool bind_shader = true); - void set_uniform_float_vec2(const char* uniform_name, 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); - void set_uniform_float_vec3(GLint location, glm::vec3 vec, bool bind_shader = true); - void set_uniform_float_vec3(const char* uniform_name, 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); - void set_uniform_float_vec4(GLint location, glm::vec4 vec, bool bind_shader = true); - void set_uniform_float_vec4(const char* uniform_name, 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); - void set_uniform_int(GLint location, GLint i, bool bind_shader = true); - void set_uniform_int(const char* uniform_name, GLint i, bool bind_shader = true); + void set_uniform_int(GLint location, GLint i); + 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(const char* uniform_name, 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); - void set_uniform_int_vec2(GLint location, glm::ivec2 vec, bool bind_shader = true); - void set_uniform_int_vec2(const char* uniform_name, 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); - void set_uniform_int_vec3(GLint location, glm::ivec3 vec, bool bind_shader = true); - void set_uniform_int_vec3(const char* uniform_name, 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); - void set_uniform_int_vec4(GLint location, glm::ivec4 vec, bool bind_shader = true); - void set_uniform_int_vec4(const char* uniform_name, 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); - void set_uniform_uint(GLint location, GLuint ui, bool bind_shader = true); - void set_uniform_uint(const char* uniform_name, GLuint ui, bool bind_shader = true); + void set_uniform_uint(GLint location, GLuint ui); + 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(const char* uniform_name, 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); - void set_uniform_uint_vec3(GLint location, glm::uvec3 vec, bool bind_shader = true); - void set_uniform_uint_vec3(const char* uniform_name, 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); - 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(GLint location, glm::uvec4 vec); + 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(const char* uniform_name, 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 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_3f(GLint location, glm::mat3 mat, 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(const char* uniform_name, 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 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_2x3f(GLint location, glm::mat2x3 mat, 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(const char* uniform_name, 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 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_2x4f(GLint location, glm::mat2x4 mat, 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(const char* uniform_name, 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 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_3x4f(GLint location, glm::mat2x4 mat, 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(const char* uniform_name, 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 transpose = false); }; } \ No newline at end of file diff --git a/src/camera.cpp b/src/camera.cpp index 64236f0..5f07904 100644 --- a/src/camera.cpp +++ b/src/camera.cpp @@ -96,9 +96,9 @@ namespace simpleengine { view_matrix = glm::lookAt(position, position + camera_front, camera_up); shader.use(); - shader.set_uniform_float_vec3("u_view_pos", position, false); - shader.set_uniform_matrix_4f("u_view_matrix", view_matrix, false); - shader.set_uniform_matrix_4f("u_projection_matrix", projection_matrix, false); + shader.set_uniform_float_vec3("u_view_pos", position); + shader.set_uniform_matrix_4f("u_view_matrix", view_matrix); + shader.set_uniform_matrix_4f("u_projection_matrix", projection_matrix); shader.unuse(); } } \ No newline at end of file diff --git a/src/gfx/renderer.cpp b/src/gfx/renderer.cpp index 19879e9..dfcd21e 100644 --- a/src/gfx/renderer.cpp +++ b/src/gfx/renderer.cpp @@ -11,8 +11,8 @@ #include #include #include +#include -// TODO: Check if initialized before trying to do stuff namespace simpleengine::gfx { 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); } + 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() { glEnable(GL_DEBUG_OUTPUT); glDebugMessageCallback(debug_message_callback, 0); @@ -83,14 +90,14 @@ namespace simpleengine::gfx { } // Enable VAO attributes - vao.enable_attrib(vbo, 0, 3, GL_FLOAT, sizeof(LitVertex), offsetof(LitVertex, position), false); - vao.enable_attrib(vbo, 1, 3, GL_FLOAT, sizeof(LitVertex), offsetof(LitVertex, color), false); - vao.enable_attrib(vbo, 2, 3, GL_FLOAT, sizeof(LitVertex), offsetof(LitVertex, normal), false); - vao.enable_attrib(vbo, 3, 2, GL_FLOAT, sizeof(LitVertex), offsetof(LitVertex, tex_coord), 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)); + 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)); rendering_mesh->tangent_vbo.buffer(rendering_mesh->tangents.data(), 0, 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(); 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() { glEnable(GL_DEPTH_TEST); @@ -111,6 +120,8 @@ namespace simpleengine::gfx { glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + this->is_initialized = true; + std::cout << "Base Renderer initialized" << std::endl; } @@ -125,21 +136,21 @@ namespace simpleengine::gfx { bool Renderer::render_job(const RenderingJob &job) { 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 = mesh->material; if (material.has_value()) { - shader.set_uniform_float("u_material.ambient_strength", material->ambient_strength, false); - shader.set_uniform_float("u_material.diffuse_strength", material->diffuse_strength, false); - shader.set_uniform_float("u_material.specular_strength", material->specular_strength, false); - shader.set_uniform_float("u_material.shine_factor", material->shine_factor, false); - // shader.set_uniform_float("u_material.reflect_factor", .1f, false); + shader.set_uniform_float("u_material.ambient_strength", material->ambient_strength); + shader.set_uniform_float("u_material.diffuse_strength", material->diffuse_strength); + shader.set_uniform_float("u_material.specular_strength", material->specular_strength); + shader.set_uniform_float("u_material.shine_factor", material->shine_factor); + // shader.set_uniform_float("u_material.reflect_factor", .1f); auto diffuse_maps = material->textures.find(aiTextureType_DIFFUSE); 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); diffuse_map->bind(); @@ -149,13 +160,13 @@ namespace simpleengine::gfx { if (specular_maps != material->textures.end()) { auto spec = specular_maps->second.front(); - shader.set_uniform_int("u_material.has_specular_map", 1, false); - shader.set_uniform_int("u_material.specular_map", 1, false); + shader.set_uniform_int("u_material.has_specular_map", 1); + shader.set_uniform_int("u_material.specular_map", 1); glActiveTexture(GL_TEXTURE1); spec->bind(); } 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 @@ -163,13 +174,13 @@ namespace simpleengine::gfx { if (normal_maps != material->textures.end()) { auto normal = normal_maps->second.front(); - shader.set_uniform_int("u_material.has_normal_map", 1, false); - shader.set_uniform_int("u_material.normal_map", 2, false); + shader.set_uniform_int("u_material.has_normal_map", 1); + shader.set_uniform_int("u_material.normal_map", 2); glActiveTexture(GL_TEXTURE2); normal->bind(); } 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 &rendering_queue) { - shader.use(); - while (!rendering_queue.empty()) { // Get the job from the queue, we'll remove it after we render. RenderingJob &job = rendering_queue.front(); @@ -197,25 +206,21 @@ namespace simpleengine::gfx { rendering_queue.pop(); } } - - shader.unuse(); } void Renderer::render_job_queue(std::map>& rendering_queue) { - shader.use(); - // Render each job then clear the queue for (const auto& it : rendering_queue) { this->render_job(it.second); } rendering_queue.clear(); - - shader.unuse(); } void Renderer::render() { - // Render other (opaque) objects first - this->render_job_queue(other_render_queue); + check_if_initialized(); + + // Render other (opaque) objects first + render_job_queue(other_render_queue); // Render transparent objects std::map> transparent_jobs; @@ -228,6 +233,6 @@ namespace simpleengine::gfx { transparent_render_queue.pop(); } - this->render_job_queue(transparent_jobs); + render_job_queue(transparent_jobs); } } // namespace simpleengine::gfx \ No newline at end of file diff --git a/src/gfx/shader.cpp b/src/gfx/shader.cpp index 329fa40..6716601 100644 --- a/src/gfx/shader.cpp +++ b/src/gfx/shader.cpp @@ -5,6 +5,8 @@ #include namespace simpleengine::gfx { + GLuint Shader::inuse_program = 0; + Shader::Shader(GLuint program) : program(program) { } @@ -99,11 +101,17 @@ namespace simpleengine::gfx { } void Shader::use() const { - glUseProgram(program); + if (Shader::inuse_program != program) { + glUseProgram(program); + + Shader::inuse_program = program; + } } void Shader::unuse() { glUseProgram(0); + + Shader::inuse_program = 0; } void Shader::attach(GLuint program) { @@ -174,347 +182,234 @@ namespace simpleengine::gfx { return get_uniform_double(location); } - void Shader::set_uniform_float(GLint location, GLfloat fl, bool bind_shader) { - if (bind_shader) { - use(); - } + void Shader::set_uniform_float(GLint location, GLfloat fl) { + use(); 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); - 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) { - if (bind_shader) { - use(); - } + void Shader::set_uniform_float_array(GLint location, int count, GLfloat* arr) { + use(); 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); - 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) { - if (bind_shader) { - use(); - } + void Shader::set_uniform_float_vec2(GLint location, glm::vec2 vec) { + use(); 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); - 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) { - if (bind_shader) { - use(); - } + void Shader::set_uniform_float_vec3(GLint location, glm::vec3 vec) { + use(); 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); - 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) { - if (bind_shader) { - use(); - } + void Shader::set_uniform_float_vec4(GLint location, glm::vec4 vec) { + use(); 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); - 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) { - if (bind_shader) { - use(); - } + void Shader::set_uniform_int(GLint location, GLint i) { + use(); 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); - 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) { - if (bind_shader) { - use(); - } - + void Shader::set_uniform_int_array(GLint location, int count, GLint* arr) { + use(); 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); - 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) { - if (bind_shader) { - use(); - } + void Shader::set_uniform_int_vec2(GLint location, glm::ivec2 vec) { + use(); 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); - 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) { - if (bind_shader) { - use(); - } + void Shader::set_uniform_int_vec3(GLint location, glm::ivec3 vec) { + use(); 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); - 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) { - if (bind_shader) { - use(); - } + void Shader::set_uniform_int_vec4(GLint location, glm::ivec4 vec) { + use(); 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); - 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) { - if (bind_shader) { - use(); - } + void Shader::set_uniform_uint(GLint location, GLuint ui) { + use(); 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); - 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) { - if (bind_shader) { - use(); - } + void Shader::set_uniform_uint_vec2(GLint location, glm::uvec2 vec) { + use(); 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); - 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) { - if (bind_shader) { - use(); - } + void Shader::set_uniform_uint_vec3(GLint location, glm::uvec3 vec) { + use(); 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); - 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) { - if (bind_shader) { - use(); - } + void Shader::set_uniform_uint_vec4(GLint location, glm::uvec4 vec) { + use(); 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); - 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) { - if (bind_shader) { - use(); - } - glUniformMatrix2fv(location, 1, bind_shader, glm::value_ptr(mat)); - if (bind_shader) { - unuse(); - } + void Shader::set_uniform_matrix_2f(GLint location, glm::mat2 mat, bool transpose) { + use(); + glUniformMatrix2fv(location, 1, transpose, glm::value_ptr(mat)); } - 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); - 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) { - if (bind_shader) { - use(); - } - glUniformMatrix3fv(location, 1, bind_shader, glm::value_ptr(mat)); - if (bind_shader) { - unuse(); - } + void Shader::set_uniform_matrix_3f(GLint location, glm::mat3 mat, bool transpose) { + use(); + glUniformMatrix3fv(location, 1, transpose, glm::value_ptr(mat)); } - 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); - 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) { - if (bind_shader) { - use(); - } - glUniformMatrix4fv(location, 1, bind_shader, glm::value_ptr(mat)); - if (bind_shader) { - unuse(); - } + void Shader::set_uniform_matrix_4f(GLint location, glm::mat4 mat, bool transpose) { + use(); + glUniformMatrix4fv(location, 1, transpose, glm::value_ptr(mat)); } - 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); - 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) { - if (bind_shader) { - use(); - } - glUniformMatrix2x3fv(location, 1, bind_shader, glm::value_ptr(mat)); - if (bind_shader) { - unuse(); - } + void Shader::set_uniform_matrix_2x3f(GLint location, glm::mat2x3 mat, bool transpose) { + use(); + glUniformMatrix2x3fv(location, 1, transpose, glm::value_ptr(mat)); } - 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); - 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) { - if (bind_shader) { - use(); - } - glUniformMatrix3x2fv(location, 1, bind_shader, glm::value_ptr(mat)); - if (bind_shader) { - unuse(); - } + void Shader::set_uniform_matrix_3x2f(GLint location, glm::mat3x2 mat, bool transpose) { + use(); + glUniformMatrix3x2fv(location, 1, transpose, glm::value_ptr(mat)); } - 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); - 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) { - if (bind_shader) { - use(); - } - glUniformMatrix2x4fv(location, 1, bind_shader, glm::value_ptr(mat)); - if (bind_shader) { - unuse(); - } + void Shader::set_uniform_matrix_2x4f(GLint location, glm::mat2x4 mat, bool transpose) { + use(); + glUniformMatrix2x4fv(location, 1, transpose, glm::value_ptr(mat)); } - 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); - 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) { - if (bind_shader) { - use(); - } - glUniformMatrix4x2fv(location, 1, bind_shader, glm::value_ptr(mat)); - if (bind_shader) { - unuse(); - } + void Shader::set_uniform_matrix_4x2f(GLint location, glm::mat4x2 mat, bool transpose) { + use(); + glUniformMatrix4x2fv(location, 1, transpose, glm::value_ptr(mat)); } - 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); - 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) { - if (bind_shader) { - use(); - } - glUniformMatrix3x4fv(location, 1, bind_shader, glm::value_ptr(mat)); - if (bind_shader) { - unuse(); - } + void Shader::set_uniform_matrix_3x4f(GLint location, glm::mat2x4 mat, bool transpose) { + use(); + glUniformMatrix3x4fv(location, 1, transpose, glm::value_ptr(mat)); } - 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); - 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) { - if (bind_shader) { - use(); - } - glUniformMatrix4x3fv(location, 1, bind_shader, glm::value_ptr(mat)); - if (bind_shader) { - unuse(); - } + void Shader::set_uniform_matrix_4x3f(GLint location, glm::mat4x3 mat, bool transpose) { + use(); + glUniformMatrix4x3fv(location, 1, transpose, glm::value_ptr(mat)); } - 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); - set_uniform_matrix_4x3f(location, mat, bind_shader, transpose); + set_uniform_matrix_4x3f(location, mat, transpose); } } \ No newline at end of file