75 static std::unordered_map<Types::ShaderName, unsigned int>
shaders;
92 template <
typename... Args>
93 static void New(std::string shader_name, GLenum type, std::string path,
96 std::vector<unsigned int> compiled_shaders = {};
97 compile_shaders(compiled_shaders, type, path, args...);
100 unsigned int ID = glCreateProgram();
101 std::for_each(compiled_shaders.begin(), compiled_shaders.end(),
102 [&ID](
auto shader) { glAttachShader(ID, shader); });
105 Shader::CheckCompileErrors(ID,
"PROGRAM");
108 std::for_each(compiled_shaders.begin(), compiled_shaders.end(),
109 [](
auto shader) { glDeleteShader(shader); });
127 template <
typename... Args>
128 static void New(
const GLchar **feedbackVaryings,
int numVaryings,
129 std::string shader_name, GLenum type, std::string path,
132 std::vector<unsigned int> compiled_shaders = {};
133 compile_shaders(compiled_shaders, type, path, args...);
136 unsigned int ID = glCreateProgram();
137 std::for_each(compiled_shaders.begin(), compiled_shaders.end(),
138 [&ID](
auto shader) { glAttachShader(ID, shader); });
140 if (feedbackVaryings !=
nullptr)
142 glTransformFeedbackVaryings(ID, numVaryings, feedbackVaryings,
143 GL_INTERLEAVED_ATTRIBS);
147 Shader::CheckCompileErrors(ID,
"PROGRAM");
150 std::for_each(compiled_shaders.begin(), compiled_shaders.end(),
151 [](
auto shader) { glDeleteShader(shader); });
154 static void compile_shaders(std::vector<unsigned int> &compiled)
159 template <
typename... Args>
160 static void compile_shaders(std::vector<unsigned int> &compiled,
161 GLenum type, std::string path, Args... args)
165 file.exceptions(std::ifstream::failbit | std::ifstream::badbit);
170 std::stringstream stream;
171 stream << file.rdbuf();
175 catch (std::ifstream::failure &e)
177 ERROR(
"Error reading shader file: ", path);
181 const char *shader_code = code.c_str();
182 unsigned int shader = glCreateShader(type);
183 glShaderSource(shader, 1, &shader_code, NULL);
184 glCompileShader(shader);
185 Shader::CheckCompileErrors(shader,
"SHADER");
187 compiled.push_back(shader);
188 compile_shaders(compiled, args...);
197 static unsigned int GetId(Types::ShaderName shader_name);
206 static void Use(Types::ShaderName shader_name);
217 static void SetBool(Types::ShaderName shader_name,
const std::string &name,
226 static void SetInt(Types::ShaderName shader_name,
const std::string &name,
235 static void SetFloat(Types::ShaderName shader_name,
const std::string &name,
244 static void SetMat4(Types::ShaderName shader_name,
const GLchar *name,
255 static void SetVec3(Types::ShaderName shader_name,
const GLchar *name,
256 float x,
float y,
float z);
264 static void SetVec3(Types::ShaderName shader_name,
const GLchar *name,
268 static void CheckCompileErrors(
unsigned int shader, std::string type);
static void SetVec3(Types::ShaderName shader_name, const GLchar *name, float x, float y, float z)
Set a 3D vector in the shader.
static void New(const GLchar **feedbackVaryings, int numVaryings, std::string shader_name, GLenum type, std::string path, Args... args)
Create a new shader with feedback varyings.