| 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
12 #include <globjects/base/Changeable.h>
13 #include <globjects/base/ChangeListener.h>
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:
48 enum class IncludeImplementation
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;
105 ref_ptr<AbstractStringSource> m_source;
106 IncludePaths m_includePaths;
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
globjects::Shader::m_includePaths
IncludePaths m_includePaths
Definition: Shader.h:106
ChangeListener.h
globjects::Shader::m_compilationFailed
bool m_compilationFailed
Definition: Shader.h:109
globjects::ref_ptr
The ref_ptr class provides the interface for a reference pointer.
Definition: LogMessageBuilder.h:20
globjects
Contains all the classes that wrap OpenGL functionality.
globjects::Object
Superclass of all wrapped OpenGL objects.
Definition: Object.h:26
globjects::Program
Wraps an OpenGL program.
Definition: Program.h:78
ref_ptr.h
Changeable.h
globjects::Changeable
Superclass of all objects that want others to signal that they have changed.
Definition: Changeable.h:22
globjects::ObjectVisitor
Implements a Visitor Pattern to iterate over all tracked globjects objects.
Definition: ObjectVisitor.h:29
globjects::Shader::s_globalReplacements
static std::map< std::string, std::string > s_globalReplacements
Definition: Shader.h:111
Object.h
globjects::Shader::m_source
ref_ptr< AbstractStringSource > m_source
Definition: Shader.h:105
globjects::Shader::IncludeImplementation
IncludeImplementation
Definition: Shader.h:48
globjects::Shader::IncludePaths
std::vector< std::string > IncludePaths
Definition: Shader.h:45
globjects::Shader::m_type
gl::GLenum m_type
Definition: Shader.h:104
globjects::Shader::m_compiled
bool m_compiled
Definition: Shader.h:108
globjects::ChangeListener
Allows listening to any Changeable.
Definition: ChangeListener.h:22
globjects::Shader
Encapsulates OpenGL shaders.
Definition: Shader.h:40
globjects::AbstractStringSource
Superclass for all types of static and dynamic strings, e.g. for the use as Shader code...
Definition: AbstractStringSource.h:25