26 OpenglShader(
const std::string& vertex,
const std::string& fragment);
28 void Bind()
const override;
30 void SetValue(
const std::string& name,
float value)
override;
32 void SetValue(
const std::string& name,
int value)
override;
34 void SetValue(
const std::string& name,
unsigned int value)
override;
36 void SetValue(
const std::string& name, glm::mat4 value)
override;
38 void SetValue(
const std::string& name, glm::vec2 value)
override;
40 void SetValue(
const std::string& name, glm::vec3 value)
override;
42 void SetValue(
const std::string& name, glm::vec4 value)
override;
46 unsigned int GetID()
const override;
51 unsigned int GetUniformLocation(
const std::string& name);
53 unsigned int CompileShader(
unsigned int type,
const char* source);
61 unsigned int location = GetUniformLocation(name);
63 LOG_ERROR(
"Shader variable not found: %s", name.c_str());
67 if constexpr (std::is_same_v<T, float>) {
69 glGetUniformfv(
id, location, &value);
71 }
else if constexpr (std::is_same_v<T, int>) {
73 glGetUniformiv(
id, location, &value);
75 }
else if constexpr (std::is_same_v<T, glm::vec2>) {
77 glGetUniformfv(
id, location, data);
78 return glm::vec2(data[0], data[1]);
79 }
else if constexpr (std::is_same_v<T, glm::vec3>) {
81 glGetUniformfv(
id, location, data);
82 return glm::vec3(data[0], data[1], data[2]);
83 }
else if constexpr (std::is_same_v<T, glm::vec4>) {
85 glGetUniformfv(
id, location, data);
86 return glm::vec4(data[0], data[1], data[2], data[3]);
87 }
else if constexpr (std::is_same_v<T, glm::mat4>) {
89 glGetUniformfv(
id, location, data);
90 return glm::make_mat4(data);
92 LOG_ERROR(
"Unsupported type: %s",
typeid(T).name());
Opengl Shader implementation.
Definition: shader_gl.h:19
void Bind() const override
Definition: shader_gl.cpp:122
unsigned int GetID() const override
Definition: shader_gl.cpp:130
void SetValue(const std::string &name, float value) override
Definition: shader_gl.cpp:135
T GetValue(const std::string &name)
Definition: shader_gl.h:60
bool IsValid() const override
Definition: shader_gl.cpp:107
void Destroy() override
Definition: shader_gl.cpp:126
Shader Abstract class.
Definition: shader.h:44
#define LOG_ERROR(...)
ERROR logging.
Definition: logging.h:60