globjects  1.0.0.000000000000
Strict OpenGL objects wrapper.
Loading...
Searching...
No Matches
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
15
16#include <globjects/Object.h>
17
18
19namespace globjects
20{
21
22
23class AbstractStringSource;
24
40class GLOBJECTS_API Shader : public Object, protected ChangeListener, public Changeable
41{
42 friend class Program;
43
44public:
45 using IncludePaths = std::vector<std::string>;
46
47public:
49 {
50 ShadingLanguageIncludeARB
51 , Fallback
52 };
53
55
56public:
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);
63
64public:
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
73 void setSource(const std::string & source);
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
95protected:
96 virtual ~Shader();
97
98 virtual void notifyChanged(const Changeable * changeable) override;
99
100protected:
101 std::string shaderString() const;
102
103protected:
104 gl::GLenum m_type;
107
108 mutable bool m_compiled;
110
111 static std::map<std::string, std::string> s_globalReplacements;
112};
113
114
115} // namespace globjects
Superclass for all types of static and dynamic strings, e.g. for the use as Shader code.
Definition AbstractStringSource.h:26
Allows listening to any Changeable.
Definition ChangeListener.h:23
Superclass of all objects that want others to signal that they have changed.
Definition Changeable.h:23
Superclass of all wrapped OpenGL objects.
Definition Object.h:27
Implements a Visitor Pattern to iterate over all tracked globjects objects.
Definition ObjectVisitor.h:30
Wraps an OpenGL program.
Definition Program.h:79
Encapsulates OpenGL shaders.
Definition Shader.h:41
bool m_compiled
Definition Shader.h:108
static std::string typeString(gl::GLenum type)
const AbstractStringSource * source() const
std::string getSource() const
static void clearGlobalReplacements()
void setSource(AbstractStringSource *source)
std::string typeString() const
bool checkCompileStatus() const
gl::GLenum type() const
virtual gl::GLenum objectType() const override
IncludePaths m_includePaths
Definition Shader.h:106
bool m_compilationFailed
Definition Shader.h:109
static std::map< std::string, std::string > s_globalReplacements
Definition Shader.h:111
virtual void accept(ObjectVisitor &visitor) override
void setSource(const std::string &source)
static void globalReplace(const std::string &search, int i)
ref_ptr< AbstractStringSource > m_source
Definition Shader.h:105
bool compile() const
static void globalReplace(const std::string &search, const std::string &replacement)
Shader(const gl::GLenum type)
const IncludePaths & includePaths() const
virtual void notifyChanged(const Changeable *changeable) override
bool isCompiled() const
std::string infoLog() const
static void hintIncludeImplementation(IncludeImplementation impl)
gl::GLint get(gl::GLenum pname) const
gl::GLenum m_type
Definition Shader.h:104
std::vector< std::string > IncludePaths
Definition Shader.h:45
static Shader * fromFile(const gl::GLenum type, const std::string &filename, const IncludePaths &includePaths=IncludePaths())
std::string shaderString() const
Shader(const gl::GLenum type, AbstractStringSource *source, const IncludePaths &includePaths=IncludePaths())
void setIncludePaths(const IncludePaths &includePaths)
IncludeImplementation
Definition Shader.h:49
static Shader * fromString(const gl::GLenum type, const std::string &sourceString, const IncludePaths &includePaths=IncludePaths())
The ref_ptr class provides the interface for a reference pointer.
Definition ref_ptr.h:33
Contains all the classes that wrap OpenGL functionality.