]> git.tdb.fi Git - libs/gl.git/blob - source/materials/lighting.h
Remove deprecated interfaces from material and lighting code
[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 &);
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 the scene. */
60         void set_ambient(const Color &);
61
62         const Color &get_ambient() const { return ambient; }
63
64         /** Sets the fog color, which is blended into distant surfaces. */
65         void set_fog_color(const Color &);
66
67         /** Sets the density of the fog.  Zero means no fog. */
68         void set_fog_density(float);
69
70         /** Sets the density of the fog so that the blending factor at the given
71         distance is 50%. */
72         void set_fog_half_distance(float);
73
74         /** Attaches a light source.  If the light was already attached, does
75         nothing. */
76         void attach(const Light &);
77
78         /** Detaches a light source.  If the light was not attached, does nothing. */
79         void detach(const Light &);
80
81         const ProgramData &get_shader_data() const;
82
83         void set_debug_name(const std::string &);
84 };
85
86 } // namespace GL
87 } // namespace Msp
88
89 #endif