forked from lemourin/SceneGraph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Shader.hpp
64 lines (49 loc) · 1.36 KB
/
Shader.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#ifndef SHADER_HPP
#define SHADER_HPP
#include <QOpenGLShaderProgram>
#include <memory>
#define GLSL(shader) #shader
namespace SceneGraph {
namespace Private {
template <class T>
class SingletonImpl {
private:
std::unique_ptr<T> m_data;
SingletonImpl() : m_data(std::make_unique<T>()) {}
public:
static SingletonImpl* instance() {
static SingletonImpl data;
return &data;
}
T* data() const { return m_data.get(); }
};
}
class Material;
class RenderState;
const int MAX_ATTRIBUTE_COUNT = 8;
class Shader {
private:
bool m_initialized;
QOpenGLShaderProgram m_program;
int m_attributeLocation[MAX_ATTRIBUTE_COUNT];
public:
Shader();
virtual ~Shader() {}
inline QOpenGLShaderProgram* program() { return &m_program; }
inline bool bind() { return program()->bind(); }
inline bool initialized() const { return m_initialized; }
virtual void initialize();
virtual void activate() = 0;
virtual void deactivate() = 0;
virtual const char* vertexShader() const = 0;
virtual const char* fragmentShader() const = 0;
virtual void updateState(const Material*, const RenderState&) = 0;
virtual std::vector<std::string> attribute() const = 0;
const int* attributeLocation() const { return m_attributeLocation; }
template <class T>
static T* get() {
return Private::SingletonImpl<T>::instance()->data();
}
};
}
#endif // SHADER_HPP