Nymph Game Engine
Chaiscript based Game Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
shader_manager.h
Go to the documentation of this file.
1 #ifndef SHADER_MANAGER_H
2 #define SHADER_MANAGER_H
3 #include <map>
4 #include <memory>
5 #include <string>
6 #include <chaiscript/chaiscript.hpp>
7 #include "graphics/shader.h"
8 #include "graphics/uniform.h"
9 //= SCRIPTABLE
10 
11 namespace Graphics {
15  class ShaderManager {
16  private:
17  std::map<std::string, std::shared_ptr<Shader>> shaders_to_names;
18  std::string shader_directory;
19  bool checkCompilation(const unsigned int& shader_object);
20  void logShaderInfoLog(const unsigned int& shader_object);
21  public:
25  static char const* VERTEX_EXTENSION;
29  static char const* FRAGMENT_EXTENSION;
33  static char const* GEOMETRY_EXTENSION;
34  ShaderManager() = delete;
35 
39  ShaderManager(const std::string& shader_directory);
44  //= BEGIN SCRIPTABLE
45 
54  bool loadShader(const std::string& name, const bool geometry_shader = false);
65  bool loadShader(const std::string& name, const std::string& vertex_filename, const std::string& fragment_filename, const std::string& geometry_filename);
66 
74  std::shared_ptr<Shader> operator[](const std::string& name) const;
82  std::shared_ptr<Shader> getShader(const std::string& name) const;
83 
89  void setUniformForAllPrograms(const Uniform& u);
90  //= END SCRIPTABLE
91 
100  template<class T>
101  void setUniformForAllPrograms(const std::string& name, const T& data);
102 
103  };
104 
105  template<class T>
106  void ShaderManager::setUniformForAllPrograms(const std::string& name, const T& data) {
107  for(auto& i : shaders_to_names) {
108  i.second->setUniform(name, data);
109  }
110  }
111 }
112 
113 #endif
static char const * GEOMETRY_EXTENSION
Definition: shader_manager.h:33
Class for shader uniform.
Definition: uniform.h:10
static char const * FRAGMENT_EXTENSION
Definition: shader_manager.h:29
Class for shader manager.
Definition: shader_manager.h:15
static char const * VERTEX_EXTENSION
Definition: shader_manager.h:25
std::shared_ptr< Shader > operator[](const std::string &name) const
looks up shader by name
Definition: shader_manager.cpp:141
bool loadShader(const std::string &name, const bool geometry_shader=false)
Loads a shader.
Definition: shader_manager.cpp:28
std::shared_ptr< Shader > getShader(const std::string &name) const
Gets the shader.
Definition: shader_manager.cpp:145
void setUniformForAllPrograms(const Uniform &u)
Sets the uniform for all programs.
Definition: shader_manager.cpp:152
~ShaderManager()
Destroys the object.
Definition: shader_manager.cpp:24