]> git.tdb.fi Git - libs/gl.git/blob - source/materials/lighting.h
Remove collection-less constructor overloads from most loaders
[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 Encapsulates global lighting parameters and any number of individual light
16 sources.
17 */
18 class Lighting
19 {
20 public:
21         class Loader: public DataFile::CollectionObjectLoader<Lighting>
22         {
23         private:
24                 static ActionMap shared_actions;
25
26         public:
27                 Loader(Lighting &, Collection &);
28
29         private:
30                 virtual void init_actions();
31
32                 void ambient(float, float, float);
33                 void fog_color(float, float, float);
34                 void fog_density(float);
35                 void fog_half_distance(float);
36                 void light(const std::string &);
37                 void light_inline();
38         };
39
40 private:
41         struct AttachedLight
42         {
43                 const Light *light;
44                 mutable unsigned generation;
45
46                 AttachedLight(const Light *l): light(l), generation(0) { }
47         };
48
49         Color ambient;
50         Color fog_color;
51         float fog_density;
52         std::vector<AttachedLight> lights;
53         mutable ProgramData shdata;
54
55 public:
56         Lighting();
57
58         /** Sets the ambient lighting color.  Affects all surfaces in the scene. */
59         void set_ambient(const Color &);
60
61         const Color &get_ambient() const { return ambient; }
62
63         /** Sets the fog color, which is blended into distant surfaces. */
64         void set_fog_color(const Color &);
65
66         /** Sets the density of the fog.  Zero means no fog. */
67         void set_fog_density(float);
68
69         /** Sets the density of the fog so that the blending factor at the given
70         distance is 50%. */
71         void set_fog_half_distance(float);
72
73         /** Attaches a light source.  If the light was already attached, does
74         nothing. */
75         void attach(const Light &);
76
77         /** Detaches a light source.  If the light was not attached, does nothing. */
78         void detach(const Light &);
79
80         int find_light_index(const Light &) const;
81
82         const ProgramData &get_shader_data() const;
83
84         void set_debug_name(const std::string &);
85 };
86
87 } // namespace GL
88 } // namespace Msp
89
90 #endif