]> git.tdb.fi Git - libs/gl.git/blob - source/light.h
Unbind things if they are deleted while current
[libs/gl.git] / source / light.h
1 #ifndef MSP_GL_LIGHT_H_
2 #define MSP_GL_LIGHT_H_
3
4 #include <vector>
5 #include "color.h"
6 #include "vector.h"
7
8 namespace Msp {
9 namespace GL {
10
11 class Matrix;
12 class ProgramData;
13
14 class Light
15 {
16 private:
17         enum ParameterMask
18         {
19                 DIFFUSE = 1,
20                 SPECULAR = 2,
21                 POSITION = 4,
22                 SPOT_DIR = 8,
23                 SPOT_EXP = 16,
24                 SPOT_CUTOFF = 32,
25                 ATTENUATION = 64
26         };
27
28         Color diffuse;
29         Color specular;
30         Vector4 position;
31         Vector3 spot_dir;
32         float spot_exp;
33         float spot_cutoff;
34         float attenuation[3];
35
36 public:
37         Light();
38         ~Light();
39
40 private:
41         void update_parameter(int, int = -1) const;
42
43 public:
44         void set_diffuse(const Color &c);
45         void set_specular(const Color &c);
46         const Color &get_diffuse() const { return diffuse; }
47         const Color &get_specular() const { return specular; }
48
49         void set_position(const Vector4 &);
50         const Vector4 &get_position() const { return position; }
51         void set_spot_direction(const Vector3 &);
52         void set_spot_exponent(float);
53         void set_spot_cutoff(float);
54         const Vector3 &get_spot_direction() const { return spot_dir; }
55         float get_spot_exponent() const { return spot_exp; }
56         float get_spot_cutoff() const { return spot_cutoff; }
57         void set_attenuation(float, float, float);
58         const float *get_attenuation() const { return attenuation; }
59
60         void update_shader_data(ProgramData &, const Matrix &, unsigned) const;
61         void bind() const { return bind_to(0); }
62         void bind_to(unsigned) const;
63
64         static const Light *current(unsigned = 0);
65         static void unbind() { return unbind_from(0); }
66         static void unbind_from(unsigned);
67 };
68
69 } // namespace GL
70 } // namespace Msp
71
72 #endif