63 lines
1.7 KiB
C++
Executable File
63 lines
1.7 KiB
C++
Executable File
#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(id);
|
|
}
|
|
|
|
inline void shader_program_handle::unbind()
|
|
{
|
|
glUseProgram(0);
|
|
}
|
|
|
|
template<shader_program_variable::info_type VariableInfo, typename T>
|
|
void shader_program_handle::set_uniform(const T& value) const
|
|
{
|
|
if constexpr (std::same_as<T, glm::mat4x4>)
|
|
{
|
|
static_assert(VariableInfo.type == GL_FLOAT_MAT4);
|
|
glUniformMatrix4fv(VariableInfo.location, 1, false, glm::value_ptr(value));
|
|
}
|
|
else if constexpr (std::same_as<T, glm::mat3x3>)
|
|
{
|
|
static_assert(VariableInfo.type == GL_FLOAT_MAT3);
|
|
glUniformMatrix3fv(VariableInfo.location, 1, false, glm::value_ptr(value));
|
|
}
|
|
else if constexpr (std::same_as<T, glm::fvec4>)
|
|
{
|
|
static_assert(VariableInfo.type == GL_FLOAT_VEC4);
|
|
glUniform4fv(VariableInfo.location, 1, glm::value_ptr(value));
|
|
}
|
|
else if constexpr (std::same_as<T, glm::fvec3>)
|
|
{
|
|
static_assert(VariableInfo.type == GL_FLOAT_VEC3);
|
|
glUniform3fv(VariableInfo.location, 1, glm::value_ptr(value));
|
|
}
|
|
else if constexpr (std::same_as<T, glm::fvec2>)
|
|
{
|
|
static_assert(VariableInfo.type == GL_FLOAT_VEC2);
|
|
glUniform2fv(VariableInfo.location, 1, glm::value_ptr(value));
|
|
}
|
|
else if constexpr (std::same_as<T, float>)
|
|
{
|
|
static_assert(VariableInfo.type == GL_FLOAT);
|
|
glUniform1f(VariableInfo.location, value);
|
|
}
|
|
else if constexpr (std::same_as<T, int>)
|
|
{
|
|
static_assert(VariableInfo.type == GL_INT or VariableInfo.type == GL_SAMPLER_2D);
|
|
glUniform1i(VariableInfo.location, value);
|
|
}
|
|
else
|
|
{
|
|
T::_unknown_shader_uniform_type_;
|
|
}
|
|
}
|
|
} |