]> git.tdb.fi Git - libs/gl.git/blob - source/light.h
Better state tracking for bound objects
[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 Light
12 {
13 private:
14         enum ParameterMask
15         {
16                 DIFFUSE = 1,
17                 SPECULAR = 2,
18                 POSITION = 4,
19                 SPOT_DIR = 8,
20                 SPOT_EXP = 16,
21                 SPOT_CUTOFF = 32,
22                 ATTENUATION = 64
23         };
24
25         Color diffuse;
26         Color specular;
27         Vector4 position;
28         Vector3 spot_dir;
29         float spot_exp;
30         float spot_cutoff;
31         float attenuation[3];
32
33 public:
34         Light();
35
36 private:
37         void update_parameter(int, int = -1) const;
38
39 public:
40         void set_diffuse(const Color &c);
41         void set_specular(const Color &c);
42         const Color &get_diffuse() const { return diffuse; }
43         const Color &get_specular() const { return specular; }
44
45         void set_position(const Vector4 &);
46         const Vector4 &get_position() const { return position; }
47         void set_spot_direction(const Vector3 &);
48         void set_spot_exponent(float);
49         void set_spot_cutoff(float);
50         const Vector3 &get_spot_direction() const { return spot_dir; }
51         float get_spot_exponent() const { return spot_exp; }
52         float get_spot_cutoff() const { return spot_cutoff; }
53         void set_attenuation(float, float, float);
54         const float *get_attenuation() const { return attenuation; }
55
56         void bind() const { return bind_to(0); }
57         void bind_to(unsigned) const;
58
59         static const Light *current(unsigned = 0);
60         static void unbind() { return unbind_from(0); }
61         static void unbind_from(unsigned);
62 };
63
64 } // namespace GL
65 } // namespace Msp
66
67 #endif