]> git.tdb.fi Git - libs/gl.git/blob - source/materials/lighting.h
Add inline data items to the collection
[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 "gl.h"
8 #include "programdata.h"
9
10 namespace Msp {
11 namespace GL {
12
13 class Light;
14
15 /**
16 Encapsulates global lighting parameters and any number of individual light
17 sources.
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 &);
29                 Loader(Lighting &, Collection &);
30
31         private:
32                 virtual void init_actions();
33
34                 void ambient(float, float, float);
35                 void fog_color(float, float, float);
36                 void fog_density(float);
37                 void fog_half_distance(float);
38                 void horizon_angle(float);
39                 void light(const std::string &);
40                 void light_inline();
41                 void light_inline_index(unsigned);
42                 void sky_color(float, float, float);
43                 void zenith_direction(float, float, float);
44         };
45
46 private:
47         struct AttachedLight
48         {
49                 const Light *light;
50                 mutable unsigned generation;
51
52                 AttachedLight(const Light *l): light(l), generation(0) { }
53         };
54
55         Color ambient;
56         Color sky_color;
57         Vector3 zenith_direction;
58         Geometry::Angle<float> horizon_angle;
59         Color fog_color;
60         float fog_density;
61         std::vector<AttachedLight> lights;
62         mutable ProgramData shdata;
63
64 public:
65         Lighting();
66
67         /** Sets the ambient lighting color.  Affects all surfaces in the scene. */
68         void set_ambient(const Color &);
69
70         const Color &get_ambient() const { return ambient; }
71
72         /** Sets the color of the sky at zenith.  Has no effect without shaders. */
73         DEPRECATED void set_sky_color(const Color &);
74
75         /** Sets the direction of the zenith.  Defaults to positive Z axis.  Has no
76         effect without shaders. */
77         DEPRECATED void set_zenith_direction(const Vector3 &);
78
79         /** Sets the angle where skylight cuts off, counted from the true horizon.
80         Has no effect without shaders. */
81         DEPRECATED void set_horizon_angle(const Geometry::Angle<float> &);
82
83         /** Sets the fog color, which is blended into distant surfaces. */
84         void set_fog_color(const Color &);
85
86         /** Sets the density of the fog.  Zero means no fog. */
87         void set_fog_density(float);
88
89         /** Sets the density of the fog so that the blending factor at the given
90         distance is 50%. */
91         void set_fog_half_distance(float);
92
93         /** Attaches a light source.  If the light was already attached, does
94         nothing. */
95         void attach(const Light &);
96
97         /** Detaches a light source.  If the light was not attached, does nothing. */
98         void detach(const Light &);
99
100         DEPRECATED void attach(unsigned, const Light &l) { attach(l); }
101         DEPRECATED void detach(unsigned);
102
103         /** Returns an attached light.  If no light is attached at that index, null
104         is returned. */
105         DEPRECATED const Light *get_attached_light(unsigned) const;
106
107         /** Updates a ProgramData object with the uniforms for the Lighting,
108         including all attached light sources.  A view matrix must be passed in. */
109         DEPRECATED void update_shader_data(ProgramData &, const Matrix &) const;
110
111         const ProgramData &get_shader_data() const;
112
113         void set_debug_name(const std::string &);
114 };
115
116 } // namespace GL
117 } // namespace Msp
118
119 #endif