globjects  1.0.0.000000000000
Strict OpenGL objects wrapper.
Shader.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include <string>
5 #include <vector>
6 #include <map>
7 
8 #include <glbinding/gl/types.h>
9 
10 #include <globjects/globjects_api.h>
11 
14 #include <globjects/base/ref_ptr.h>
15 
16 #include <globjects/Object.h>
17 
18 
19 namespace globjects
20 {
21 
22 
23 class AbstractStringSource;
24 
40 class GLOBJECTS_API Shader : public Object, protected ChangeListener, public Changeable
41 {
42  friend class Program;
43 
44 public:
45  using IncludePaths = std::vector<std::string>;
46 
47 public:
49  {
50  ShadingLanguageIncludeARB
51  , Fallback
52  };
53 
54  static void hintIncludeImplementation(IncludeImplementation impl);
55 
56 public:
57  static Shader * fromString(const gl::GLenum type, const std::string & sourceString, const IncludePaths & includePaths = IncludePaths());
58  static Shader * fromFile(const gl::GLenum type, const std::string & filename, const IncludePaths & includePaths = IncludePaths());
59 
60  static void globalReplace(const std::string & search, const std::string & replacement);
61  static void globalReplace(const std::string & search, int i);
62  static void clearGlobalReplacements();
63 
64 public:
65  Shader(const gl::GLenum type);
66  Shader(const gl::GLenum type, AbstractStringSource * source, const IncludePaths & includePaths = IncludePaths());
67 
68  virtual void accept(ObjectVisitor& visitor) override;
69 
70  gl::GLenum type() const;
71 
72  void setSource(AbstractStringSource * source);
73  void setSource(const std::string & source);
74  const AbstractStringSource* source() const;
75  void updateSource();
76 
77  const IncludePaths & includePaths() const;
78  void setIncludePaths(const IncludePaths & includePaths);
79 
80  bool compile() const;
81  bool isCompiled() const;
82  void invalidate();
83 
84  gl::GLint get(gl::GLenum pname) const;
85  std::string getSource() const;
86  bool checkCompileStatus() const;
87  std::string infoLog() const;
88 
89  std::string typeString() const;
90 
91  virtual gl::GLenum objectType() const override;
92 
93  static std::string typeString(gl::GLenum type);
94 
95 protected:
96  virtual ~Shader();
97 
98  virtual void notifyChanged(const Changeable * changeable) override;
99 
100 protected:
101  std::string shaderString() const;
102 
103 protected:
104  gl::GLenum m_type;
107 
108  mutable bool m_compiled;
109  mutable bool m_compilationFailed;
110 
111  static std::map<std::string, std::string> s_globalReplacements;
112 };
113 
114 
115 } // namespace globjects
Encapsulates OpenGL shaders.
Definition: Shader.h:40
The ref_ptr class provides the interface for a reference pointer.
Definition: LogMessageBuilder.h:20
bool m_compilationFailed
Definition: Shader.h:109
Wraps an OpenGL program.
Definition: Program.h:78
static std::map< std::string, std::string > s_globalReplacements
Definition: Shader.h:111
ref_ptr< AbstractStringSource > m_source
Definition: Shader.h:105
Contains all the classes that wrap OpenGL functionality.
Allows listening to any Changeable.
Definition: ChangeListener.h:22
Superclass of all wrapped OpenGL objects.
Definition: Object.h:26
gl::GLenum m_type
Definition: Shader.h:104
bool m_compiled
Definition: Shader.h:108
IncludePaths m_includePaths
Definition: Shader.h:106
Superclass for all types of static and dynamic strings, e.g. for the use as Shader code.
Definition: AbstractStringSource.h:25
IncludeImplementation
Definition: Shader.h:48
Superclass of all objects that want others to signal that they have changed.
Definition: Changeable.h:22
Implements a Visitor Pattern to iterate over all tracked globjects objects.
Definition: ObjectVisitor.h:29
std::vector< std::string > IncludePaths
Definition: Shader.h:45