Radium Engine  1.5.0
ShaderConfiguration.hpp
1 #pragma once
2 
3 #include <Engine/RaEngine.hpp>
4 
5 #include <array>
6 #include <list>
7 #include <set>
8 #include <string>
9 #include <vector>
10 
11 namespace Ra {
12 namespace Engine {
13 namespace Data {
14 
18 enum ShaderType : uint {
19  ShaderType_VERTEX = 0,
20  ShaderType_FRAGMENT,
21  ShaderType_GEOMETRY,
22  ShaderType_TESS_CONTROL,
23  ShaderType_TESS_EVALUATION,
24  ShaderType_COMPUTE,
25  ShaderType_COUNT
26 };
27 
61 class RA_ENGINE_API ShaderConfiguration final
62 {
63  friend class ShaderProgram;
64 
65  public:
66  ShaderConfiguration() = default;
72  explicit ShaderConfiguration( const std::string& name );
73 
78  ShaderConfiguration( const std::string& name,
79  const std::string& vertexShader,
80  const std::string& fragmentShader );
81 
87  void addShader( ShaderType type, const std::string& name );
88 
96  void addShaderSource( ShaderType type, const std::string& source );
97 
101  void addProperty( const std::string& prop );
102  void addProperties( const std::list<std::string>& props );
103  void removeProperty( const std::string& prop );
104 
108  void addInclude( const std::string& incl, ShaderType type = ShaderType_FRAGMENT );
109  void addIncludes( const std::list<std::string>& incls, ShaderType type = ShaderType_FRAGMENT );
110  void removeInclude( const std::string& incl, ShaderType type = ShaderType_FRAGMENT );
111 
113  void addNamedString( const std::string& includepath, const std::string& realfile );
114 
118  bool isComplete() const;
119 
120  bool operator<( const ShaderConfiguration& other ) const;
121 
122  std::set<std::string> getProperties() const;
123 
124  const std::vector<std::pair<std::string, ShaderType>>& getIncludes() const;
125 
126  const std::vector<std::pair<std::string, std::string>>& getNamedStrings() const;
127 
128  // get default shader configuration
129  static ShaderConfiguration getDefaultShaderConfig() { return m_defaultShaderConfig; }
130 
131  void setVersion( const std::string& version ) { m_version = version; }
132  void setName( const std::string& name ) { m_name = name; }
133 
134  const std::string& getName() const { return m_name; }
135  const std::string& getVersion() const { return m_version; }
136  friend std::ostream& operator<<( std::ostream& stream, const ShaderConfiguration& config );
137 
138  private:
139  std::string m_name {};
140  std::string m_version {};
141 
144  std::array<std::pair<std::string, bool>, ShaderType_COUNT> m_shaders;
145 
146  std::set<std::string> m_properties;
147 
148  std::vector<std::pair<std::string, ShaderType>> m_includes;
149 
150  std::vector<std::pair<std::string, std::string>> m_named_strings;
151 
152  static ShaderConfiguration m_defaultShaderConfig;
153 
154  static std::string s_glslVersion;
155 
156  public:
161  static void setOpenGLVersion( const glbinding::Version& version );
162 
167  static std::string getGLSLVersion();
168 };
169 
170 } // namespace Data
171 } // namespace Engine
172 } // namespace Ra
Definition: Cage.cpp:3