#ifndef INCLUDE_GL_SHADER_PROGRAM_INSTANCE_IMPLEMENTATION #error Never include this file directly include 'shader_program_handle.hpp' #endif #include "glm/glm.hpp" #include "glm/gtc/type_ptr.hpp" namespace zgl { inline void shader_program_handle::bind() const { glUseProgram(program_id); } inline void shader_program_handle::unbind() { glUseProgram(0); } template void shader_program_handle::set_uniform(const T& value) const { if constexpr (std::same_as) { static_assert(VariableInfo.type == GL_FLOAT_MAT4); glUniformMatrix4fv(VariableInfo.location, 1, false, glm::value_ptr(value)); } else if constexpr (std::same_as) { static_assert(VariableInfo.type == GL_FLOAT_MAT3); glUniformMatrix3fv(VariableInfo.location, 1, false, glm::value_ptr(value)); } else if constexpr (std::same_as) { static_assert(VariableInfo.type == GL_FLOAT_VEC4); glUniform4fv(VariableInfo.location, 1, glm::value_ptr(value)); } else if constexpr (std::same_as) { static_assert(VariableInfo.type == GL_FLOAT_VEC3); glUniform3fv(VariableInfo.location, 1, glm::value_ptr(value)); } else if constexpr (std::same_as) { static_assert(VariableInfo.type == GL_FLOAT_VEC2); glUniform2fv(VariableInfo.location, 1, glm::value_ptr(value)); } else if constexpr (std::same_as) { static_assert(VariableInfo.type == GL_FLOAT); glUniform1f(VariableInfo.location, value); } else if constexpr (std::same_as) { static_assert(VariableInfo.type == GL_INT or VariableInfo.type == GL_SAMPLER_2D); glUniform1i(VariableInfo.location, value); } else { T::_unknown_shader_uniform_type_; } } }