]> git.tdb.fi Git - libs/gl.git/blob - source/lighting.h
Refresh lighting and culling uniforms if the camera changes in pop_state
[libs/gl.git] / source / 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 "bindable.h"
7 #include "color.h"
8 #include "gl.h"
9 #include "programdata.h"
10
11 namespace Msp {
12 namespace GL {
13
14 class Light;
15
16 /**
17 Encapsulates global lighting parameters and any number of individual light
18 sources.
19 */
20 class Lighting: public Bindable<Lighting>
21 {
22 private:
23         Color ambient;
24         Color sky_color;
25         Vector3 sky_direction;
26         Geometry::Angle<float> horizon_angle;
27         Color fog_color;
28         float fog_density;
29         std::vector<const Light *> lights;
30
31 public:
32         Lighting();
33
34         /** Sets the ambient lighting color.  Affects all surfaces in the scene. */
35         void set_ambient(const Color &);
36
37         const Color &get_ambient() const { return ambient; }
38
39         /** Sets the color of the sky at zenith.  Has no effect without shaders. */
40         void set_sky_color(const Color &);
41
42         /** Sets the direction of the sky.  Defaults to positive Z axis.  Has no
43         effect without shaders. */
44         void set_sky_direction(const Vector3 &);
45
46         /** Sets the angle where skylight cuts off, counted from the true horizon.
47         Has no effect without shaders. */
48         void set_horizon_angle(const Geometry::Angle<float> &);
49
50         /** Sets the fog color, which is blended into distant surfaces. */
51         void set_fog_color(const Color &);
52
53         /** Sets the density of the fog.  Zero means no fog. */
54         void set_fog_density(float);
55
56         /** Sets the density of the fog so that the blending factor at the given
57         distance is 50%. */
58         void set_fog_half_distance(float);
59
60         /** Attaches a light source.  If the attachment index is greater than
61         LightUnit::get_n_units, the Lighting can't be bound for legacy mode. */
62         void attach(unsigned, const Light &);
63
64         /** Detaches a light source. */
65         void detach(unsigned);
66
67         /** Returns an attached light.  If no light is attached at that index, null
68         is returned. */
69         const Light *get_attached_light(unsigned) const;
70
71         /** Updates a ProgramData object with the uniforms for the Lighting,
72         including all attached light sources.  A view matrix must be passed in. */
73         void update_shader_data(ProgramData &, const Matrix &) const;
74
75         void bind() const;
76
77         static void unbind();
78 };
79
80 } // namespace GL
81 } // namespace Msp
82
83 #endif