]> git.localhorst.tv Git - blank.git/blob - src/shader.hpp
limit chunks allocated/freed per frame
[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 SetM(const glm::mat4 &m);
73         void SetProjection(const glm::mat4 &p);
74         void SetView(const glm::mat4 &v);
75         void SetVP(const glm::mat4 &v, const glm::mat4 &p);
76         void SetMVP(const glm::mat4 &m, const glm::mat4 &v, const glm::mat4 &p);
77
78         const glm::mat4 &Projection() const { return projection; }
79         const glm::mat4 &View() const { return view; }
80         const glm::mat4 &GetVP() const { return vp; }
81
82 private:
83         Program program;
84
85         glm::vec3 light_direction;
86         glm::vec3 light_color;
87
88         glm::mat4 projection;
89         glm::mat4 view;
90         glm::mat4 vp;
91
92         GLuint m_handle;
93         GLuint mvp_handle;
94         GLuint light_direction_handle;
95         GLuint light_color_handle;
96
97 };
98
99 }
100
101 #endif