25 OpenglShader(
const std::string& vertex,
const std::string& fragment);
27 void bind()
const override;
29 void set_value(
const std::string& name,
float value)
override;
31 void set_value(
const std::string& name,
int value)
override;
33 void set_value(
const std::string& name,
unsigned int value)
override;
35 void set_value(
const std::string& name, glm::mat4 value, Uint32 count = 1)
override;
37 void set_value(
const std::string& name,
const int* value, Uint32 count = 1)
override;
39 void set_value(
const std::string& name,
const float* value, Uint32 count = 1)
override;
41 void set_value(
const std::string& name, glm::vec2 value, Uint32 count = 1)
override;
43 void set_value(
const std::string& name, glm::vec3 value, Uint32 count = 1)
override;
45 void set_value(
const std::string& name, glm::vec4 value, Uint32 count = 1)
override;
49 unsigned int get_id()
const override;
54 unsigned int get_uniform_location(
const std::string& name);
56 unsigned int CompileShader(
unsigned int type,
const char* source);
62 unsigned int location = get_uniform_location(name);
64 LOG_ERROR(
"Shader variable not found: %s", name.c_str());
68 if constexpr (std::is_same_v<T, float>) {
70 glGetUniformfv(
id, location, &value);
72 }
else if constexpr (std::is_same_v<T, int>) {
74 glGetUniformiv(
id, location, &value);
76 }
else if constexpr (std::is_same_v<T, glm::vec2>) {
78 glGetUniformfv(
id, location, data);
79 return glm::vec2(data[0], data[1]);
80 }
else if constexpr (std::is_same_v<T, glm::vec3>) {
82 glGetUniformfv(
id, location, data);
83 return glm::vec3(data[0], data[1], data[2]);
84 }
else if constexpr (std::is_same_v<T, glm::vec4>) {
86 glGetUniformfv(
id, location, data);
87 return glm::vec4(data[0], data[1], data[2], data[3]);
88 }
else if constexpr (std::is_same_v<T, glm::mat4>) {
90 glGetUniformfv(
id, location, data);
91 return glm::make_mat4(data);
93 LOG_ERROR(
"Unsupported type: %s",
typeid(T).name());
Opengl Shader implementation.
Definition: shader_gl.h:18
void destroy() override
Definition: shader_gl.cpp:111
T get_value(const std::string &name)
Definition: shader_gl.h:61
void set_value(const std::string &name, float value) override
Definition: shader_gl.cpp:120
void bind() const override
Definition: shader_gl.cpp:107
unsigned int get_id() const override
Definition: shader_gl.cpp:115
bool is_valid() const override
Definition: shader_gl.cpp:92
Shader Abstract class.
Definition: shader.h:67
#define LOG_ERROR(...)
ERROR logging.
Definition: logging_sys.h:60