CG_Labs  2021.2
ShaderProgramManager.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <glad/glad.h>
4 #include <GLFW/glfw3.h>
5 
6 #include <map>
7 #include <string>
8 #include <utility>
9 #include <vector>
10 
11 #include <cstdint>
12 
13 enum class ShaderType : std::uint32_t {
14  vertex = GL_VERTEX_SHADER,
15  tess_eval = GL_TESS_EVALUATION_SHADER,
16  tess_ctrl = GL_TESS_CONTROL_SHADER,
17  geometry = GL_GEOMETRY_SHADER,
18  fragment = GL_FRAGMENT_SHADER,
19  compute = GL_COMPUTE_SHADER
20 };
21 
23 {
24 public:
25  using ProgramData = std::map<ShaderType, std::string>;
26  struct SelectedProgram {
27  bool was_selection_changed = false;
28  GLuint const* program = nullptr;
29  char const* name = nullptr;
30  };
32  void CreateAndRegisterProgram(char const* const program_name, ProgramData const& program_data, GLuint& program);
33  void CreateAndRegisterComputeProgram(char const* const program_name, std::string const& filename, GLuint& program);
34  bool ReloadAllPrograms();
35  SelectedProgram SelectProgram(std::string const& label, std::int32_t& program_index);
36 
37 private:
38  void ProcessProgram(std::size_t program_index);
39  using ProgramEntry = std::pair<GLuint&, ProgramData>;
40  std::vector<ProgramEntry> program_entries;
41  std::vector<char const*> program_names;
42 };
ShaderType
Definition: ShaderProgramManager.hpp:13
Definition: ShaderProgramManager.hpp:23
std::vector< ProgramEntry > program_entries
Definition: ShaderProgramManager.hpp:40
SelectedProgram SelectProgram(std::string const &label, std::int32_t &program_index)
Definition: ShaderProgramManager.cpp:68
~ShaderProgramManager()
Definition: ShaderProgramManager.cpp:13
std::vector< char const * > program_names
Definition: ShaderProgramManager.hpp:41
void CreateAndRegisterComputeProgram(char const *const program_name, std::string const &filename, GLuint &program)
Definition: ShaderProgramManager.cpp:40
std::pair< GLuint &, ProgramData > ProgramEntry
Definition: ShaderProgramManager.hpp:39
void CreateAndRegisterProgram(char const *const program_name, ProgramData const &program_data, GLuint &program)
Definition: ShaderProgramManager.cpp:23
bool ReloadAllPrograms()
Definition: ShaderProgramManager.cpp:53
void ProcessProgram(std::size_t program_index)
Definition: ShaderProgramManager.cpp:82
std::map< ShaderType, std::string > ProgramData
Definition: ShaderProgramManager.hpp:25
Definition: ShaderProgramManager.hpp:26
GLuint const * program
Definition: ShaderProgramManager.hpp:28
char const * name
Definition: ShaderProgramManager.hpp:29
bool was_selection_changed
Definition: ShaderProgramManager.hpp:27