]> git.localhorst.tv Git - blank.git/blob - src/shader.hpp
simplified block face stuff
[blank.git] / src / shader.hpp
1 #ifndef BLANK_SHADER_HPP_
2 #define BLANK_SHADER_HPP_
3
4 #include <iosfwd>
5 #include <list>
6 #include <GL/glew.h>
7 #include <glm/glm.hpp>
8
9
10 namespace blank {
11
12 class Shader {
13
14 public:
15         explicit Shader(GLenum type);
16         ~Shader();
17
18         Shader(Shader &&);
19         Shader &operator =(Shader &&);
20
21         Shader(const Shader &) = delete;
22         Shader &operator =(const Shader &) = delete;
23
24         void Source(const GLchar *src);
25         void Compile();
26         bool Compiled() const;
27         void Log(std::ostream &) const;
28
29         void AttachToProgram(GLuint id) const;
30
31 private:
32         GLuint handle;
33
34 };
35
36
37 class Program {
38
39 public:
40         Program();
41         ~Program();
42
43         Program(const Program &) = delete;
44         Program &operator =(const Program &) = delete;
45
46         const Shader &LoadShader(GLenum type, const GLchar *src);
47         void Attach(Shader &);
48         void Link();
49         bool Linked() const;
50         void Log(std::ostream &) const;
51
52         GLint UniformLocation(const GLchar *name) const;
53
54         void Use() const { glUseProgram(handle); }
55
56 private:
57         GLuint handle;
58         std::list<Shader> shaders;
59
60 };
61
62
63 class DirectionalLighting {
64
65 public:
66         DirectionalLighting();
67
68         void Activate();
69
70         void SetLightDirection(const glm::vec3 &);
71
72         void SetFogDensity(float);
73
74         void SetM(const glm::mat4 &m);
75         void SetProjection(const glm::mat4 &p);
76         void SetView(const glm::mat4 &v);
77         void SetVP(const glm::mat4 &v, const glm::mat4 &p);
78         void SetMVP(const glm::mat4 &m, const glm::mat4 &v, const glm::mat4 &p);
79
80         const glm::mat4 &Projection() const { return projection; }
81         const glm::mat4 &View() const { return view; }
82         const glm::mat4 &GetVP() const { return vp; }
83
84 private:
85         Program program;
86
87         glm::vec3 light_direction;
88         glm::vec3 light_color;
89
90         float fog_density;
91
92         glm::mat4 projection;
93         glm::mat4 view;
94         glm::mat4 vp;
95
96         GLuint m_handle;
97         GLuint mv_handle;
98         GLuint mvp_handle;
99         GLuint light_direction_handle;
100         GLuint light_color_handle;
101         GLuint fog_density_handle;
102
103 };
104
105 class BlockLighting {
106
107 public:
108         BlockLighting();
109
110         void Activate();
111
112         void SetFogDensity(float);
113
114         void SetM(const glm::mat4 &m);
115         void SetProjection(const glm::mat4 &p);
116         void SetView(const glm::mat4 &v);
117         void SetVP(const glm::mat4 &v, const glm::mat4 &p);
118         void SetMVP(const glm::mat4 &m, const glm::mat4 &v, const glm::mat4 &p);
119
120         const glm::mat4 &Projection() const { return projection; }
121         const glm::mat4 &View() const { return view; }
122         const glm::mat4 &GetVP() const { return vp; }
123
124 private:
125         Program program;
126
127         float fog_density;
128
129         glm::mat4 projection;
130         glm::mat4 view;
131         glm::mat4 vp;
132
133         GLuint m_handle;
134         GLuint mv_handle;
135         GLuint mvp_handle;
136         GLuint light_direction_handle;
137         GLuint light_color_handle;
138         GLuint fog_density_handle;
139
140 };
141
142 }
143
144 #endif