]> git.tdb.fi Git - libs/gl.git/blob - source/materials/lighting.h
Check the flat qualifier from the correct member
[libs/gl.git] / source / materials / lighting.h
1 #ifndef MSP_GL_LIGHTING_H_
2 #define MSP_GL_LIGHTING_H_
3
4 #include <vector>
5 #include <msp/geometry/angle.h>
6 #include "color.h"
7 #include "programdata.h"
8
9 namespace Msp {
10 namespace GL {
11
12 class Light;
13
14 /**
15 Combines multiple light sources with global lighting parameters.
16
17 This class also stores ProgramData for using the lights in shaders.
18 */
19 class Lighting
20 {
21 public:
22         class Loader: public DataFile::CollectionObjectLoader<Lighting>
23         {
24         private:
25                 static ActionMap shared_actions;
26
27         public:
28                 Loader(Lighting &, Collection &);
29
30         private:
31                 virtual void init_actions();
32
33                 void ambient(float, float, float);
34                 void fog_color(float, float, float);
35                 void fog_density(float);
36                 void fog_half_distance(float);
37                 void light(const std::string &);
38                 void light_inline();
39         };
40
41 private:
42         struct AttachedLight
43         {
44                 const Light *light;
45                 mutable unsigned generation;
46
47                 AttachedLight(const Light *l): light(l), generation(0) { }
48         };
49
50         Color ambient;
51         Color fog_color;
52         float fog_density;
53         std::vector<AttachedLight> lights;
54         mutable ProgramData shdata;
55
56 public:
57         Lighting();
58
59         /** Sets the ambient lighting color.  Affects all surfaces in an equal
60         amount. */
61         void set_ambient(const Color &);
62
63         const Color &get_ambient() const { return ambient; }
64
65         /** Sets the fog color, which is blended into distant surfaces. */
66         void set_fog_color(const Color &);
67
68         /** Sets the density of the fog.  Zero means no fog. */
69         void set_fog_density(float);
70
71         /** Sets the density of the fog so that the blending factor at the given
72         distance is 50%. */
73         void set_fog_half_distance(float);
74
75         /** Attaches a light source.  If the light was already attached, does
76         nothing. */
77         void attach(const Light &);
78
79         /** Detaches a light source.  If the light was not attached, does nothing. */
80         void detach(const Light &);
81
82         int find_light_index(const Light &) const;
83
84         const ProgramData &get_shader_data() const;
85
86         void set_debug_name(const std::string &);
87 };
88
89 } // namespace GL
90 } // namespace Msp
91
92 #endif