]> git.localhorst.tv Git - blank.git/blob - src/shader.hpp
added ability to get seperate information about block face obstruction
[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 AttributeLocation(const GLchar *name) const;
53         GLint UniformLocation(const GLchar *name) const;
54
55         void Use() const { glUseProgram(handle); }
56
57 private:
58         GLuint handle;
59         std::list<Shader> shaders;
60
61 };
62
63
64 class DirectionalLighting {
65
66 public:
67         DirectionalLighting();
68
69         void Activate();
70
71         void SetLightDirection(const glm::vec3 &);
72
73         void SetFogDensity(float);
74
75         void SetM(const glm::mat4 &m);
76         void SetProjection(const glm::mat4 &p);
77         void SetView(const glm::mat4 &v);
78         void SetVP(const glm::mat4 &v, const glm::mat4 &p);
79         void SetMVP(const glm::mat4 &m, const glm::mat4 &v, const glm::mat4 &p);
80
81         const glm::mat4 &Projection() const { return projection; }
82         const glm::mat4 &View() const { return view; }
83         const glm::mat4 &GetVP() const { return vp; }
84
85 private:
86         Program program;
87
88         glm::vec3 light_direction;
89         glm::vec3 light_color;
90
91         float fog_density;
92
93         glm::mat4 projection;
94         glm::mat4 view;
95         glm::mat4 vp;
96
97         GLuint m_handle;
98         GLuint mv_handle;
99         GLuint mvp_handle;
100         GLuint light_direction_handle;
101         GLuint light_color_handle;
102         GLuint fog_density_handle;
103
104 };
105
106 class BlockLighting {
107
108 public:
109         BlockLighting();
110
111         void Activate();
112
113         void SetFogDensity(float);
114
115         void SetM(const glm::mat4 &m);
116         void SetProjection(const glm::mat4 &p);
117         void SetView(const glm::mat4 &v);
118         void SetVP(const glm::mat4 &v, const glm::mat4 &p);
119         void SetMVP(const glm::mat4 &m, const glm::mat4 &v, const glm::mat4 &p);
120
121         const glm::mat4 &Projection() const { return projection; }
122         const glm::mat4 &View() const { return view; }
123         const glm::mat4 &GetVP() const { return vp; }
124
125 private:
126         Program program;
127
128         float fog_density;
129
130         glm::mat4 projection;
131         glm::mat4 view;
132         glm::mat4 vp;
133
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