]> git.tdb.fi Git - libs/gl.git/blob - source/lighting.h
Improve documentation for a number of classes
[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         std::vector<const Light *> lights;
28
29 public:
30         Lighting();
31
32         /** Sets the ambient lighting color.  Affects all surfaces in the scene. */
33         void set_ambient(const Color &);
34
35         const Color &get_ambient() const { return ambient; }
36
37         /** Sets the color of the sky at zenith.  Has no effect without shaders. */
38         void set_sky_color(const Color &);
39
40         /** Sets the direction of the sky.  Defaults to positive Z axis.  Has no
41         effect without shaders. */
42         void set_sky_direction(const Vector3 &);
43
44         /** Sets the angle where skylight cuts off, counted from the true horizon.
45         Has no effect without shaders. */
46         void set_horizon_angle(const Geometry::Angle<float> &);
47
48         /** Attaches a light source.  If the attachment index is greater than
49         LightUnit::get_n_units, the Lighting can't be bound for legacy mode. */
50         void attach(unsigned, const Light &);
51
52         /** Detaches a light source. */
53         void detach(unsigned);
54
55         /** Updates a ProgramData object with the uniforms for the Lighting,
56         including all attached light sources.  A view matrix must be passed in. */
57         void update_shader_data(ProgramData &, const Matrix &) const;
58
59         void bind() const;
60
61         static void unbind();
62 };
63
64 } // namespace GL
65 } // namespace Msp
66
67 #endif