initial commit

This commit is contained in:
ZY4N
2024-12-10 13:50:21 +01:00
parent 20bbd06a89
commit 275d47b7c6
33 changed files with 1066 additions and 0 deletions

View File

@@ -0,0 +1,63 @@
#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<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_;
}
}
}