]> git.localhorst.tv Git - blank.git/blob - src/shader.hpp
minor optimizations in chunk
[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 &&) noexcept;
19         Shader &operator =(Shader &&) noexcept;
20
21         Shader(const Shader &) = delete;
22         Shader &operator =(const Shader &) = delete;
23
24         void Source(const GLchar *src) noexcept;
25         void Compile() noexcept;
26         bool Compiled() const noexcept;
27         void Log(std::ostream &) const;
28
29         void AttachToProgram(GLuint id) const noexcept;
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 &) noexcept;
48         void Link() noexcept;
49         bool Linked() const noexcept;
50         void Log(std::ostream &) const;
51
52         GLint AttributeLocation(const GLchar *name) const noexcept;
53         GLint UniformLocation(const GLchar *name) const noexcept;
54
55         void Use() const noexcept { 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() noexcept;
70
71         void SetLightDirection(const glm::vec3 &) noexcept;
72
73         void SetFogDensity(float) noexcept;
74
75         void SetM(const glm::mat4 &m) noexcept;
76         void SetProjection(const glm::mat4 &p) noexcept;
77         void SetView(const glm::mat4 &v) noexcept;
78         void SetVP(const glm::mat4 &v, const glm::mat4 &p) noexcept;
79         void SetMVP(const glm::mat4 &m, const glm::mat4 &v, const glm::mat4 &p) noexcept;
80
81         const glm::mat4 &Projection() const noexcept { return projection; }
82         const glm::mat4 &View() const noexcept { return view; }
83         const glm::mat4 &GetVP() const noexcept { 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() noexcept;
112
113         void SetFogDensity(float) noexcept;
114
115         void SetM(const glm::mat4 &m) noexcept;
116         void SetProjection(const glm::mat4 &p) noexcept;
117         void SetView(const glm::mat4 &v) noexcept;
118         void SetVP(const glm::mat4 &v, const glm::mat4 &p) noexcept;
119         void SetMVP(const glm::mat4 &m, const glm::mat4 &v, const glm::mat4 &p) noexcept;
120
121         const glm::mat4 &Projection() const noexcept { return projection; }
122         const glm::mat4 &View() const noexcept { return view; }
123         const glm::mat4 &GetVP() const noexcept { 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