matf-rg-engine 1.0.0
Base for project for the Computer Graphics course at Faculty of Mathematics, University of Belgrade
Loading...
Searching...
No Matches
Shader.hpp
Go to the documentation of this file.
1
6#ifndef MATF_RG_PROJECT_SHADER_HPP
7#define MATF_RG_PROJECT_SHADER_HPP
9#include <string>
10#include <glm/glm.hpp>
11
12namespace engine::resources {
13 using ShaderName = std::string;
14
20
26 std::string_view to_string(ShaderType type);
27
32 class Shader {
33 friend class ShaderCompiler;
34
35 public:
39 void use() const;
40
45 unsigned id() const;
46
52 void set_bool(const std::string &name, bool value) const;
53
59 void set_int(const std::string &name, int value) const;
60
66 void set_float(const std::string &name, float value) const;
67
73 void set_vec2(const std::string &name, const glm::vec2 &value) const;
74
80 void set_vec3(const std::string &name, const glm::vec3 &value) const;
81
87 void set_vec4(const std::string &name, const glm::vec4 &value) const;
88
94 void set_mat2(const std::string &name, const glm::mat2 &mat) const;
95
101 void set_mat3(const std::string &name, const glm::mat3 &mat) const;
102
108 void set_mat4(const std::string &name, const glm::mat4 &mat) const;
109
114 const std::string &name() const;
115
120 const std::string &source() const;
121
126 const std::filesystem::path &source_path() const;
127
128 private:
136 Shader(unsigned shader_id, std::string name, std::string source,
137 std::filesystem::path source_path = "");
138
142 void destroy() const;
143
147 unsigned m_shaderId;
148
152 std::string m_name;
153 std::string m_source;
154 std::filesystem::path m_source_path;
155 };
156} // namespace engine
157
158#endif//MATF_RG_PROJECT_SHADER_HPP
Defines utility functions, macros, algorithms, and data structures.
Compiles GLSL shaders from a single source file. Vertex, Fragment and Geometry shaders are seperated ...
Definition ShaderCompiler.hpp:48
Represents a linked shader program object within the OpenGL context.
Definition Shader.hpp:32
std::string m_name
The name of the shader program.
Definition Shader.hpp:152
void set_vec3(const std::string &name, const glm::vec3 &value) const
Sets a 3D vector uniform value.
Definition Shader.cpp:39
void set_float(const std::string &name, float value) const
Sets a float uniform value.
Definition Shader.cpp:29
std::string m_source
Definition Shader.hpp:153
std::filesystem::path m_source_path
Definition Shader.hpp:154
const std::filesystem::path & source_path() const
Returns the path to the source file from which the shader program was compiled.
unsigned id() const
Returns the OpenGL ID of the shader program.
Definition Shader.cpp:15
void set_mat3(const std::string &name, const glm::mat3 &mat) const
Sets a 3x3 matrix uniform value.
Definition Shader.cpp:54
void set_mat4(const std::string &name, const glm::mat4 &mat) const
Sets a 4x4 matrix uniform value.
Definition Shader.cpp:59
unsigned m_shaderId
The OpenGL ID of the shader program.
Definition Shader.hpp:147
void set_vec2(const std::string &name, const glm::vec2 &value) const
Sets a 2D vector uniform value.
Definition Shader.cpp:34
void set_bool(const std::string &name, bool value) const
Sets a boolean uniform value.
Definition Shader.cpp:19
const std::string & name() const
Returns the name of the shader program by which it can be referenced using the engine::resources::Res...
void destroy() const
Destroys the shader program in the OpenGL context.
Definition Shader.cpp:11
void set_int(const std::string &name, int value) const
Sets an integer uniform value.
Definition Shader.cpp:24
void use() const
Binds the shader program.
Definition Shader.cpp:7
void set_mat2(const std::string &name, const glm::mat2 &mat) const
Sets a 2x2 matrix uniform value.
Definition Shader.cpp:49
void set_vec4(const std::string &name, const glm::vec4 &value) const
Sets a 4D vector uniform value.
Definition Shader.cpp:44
const std::string & source() const
Returns the source code of the shader program.
Definition GraphicsController.hpp:14
ShaderType
The type of the shader.
Definition Shader.hpp:19
std::string_view to_string(ShaderType type)
Converts a ShaderType to a string.
Definition ShaderCompiler.cpp:109
std::string ShaderName
Definition Shader.hpp:13
Represents a vertex in the mesh.
Definition Mesh.hpp:18