]> git.tdb.fi Git - libs/gl.git/blob - source/materials/light.h
Check the flat qualifier from the correct member
[libs/gl.git] / source / materials / light.h
1 #ifndef MSP_GL_LIGHT_H_
2 #define MSP_GL_LIGHT_H_
3
4 #include <string>
5 #include <msp/datafile/dynamicobjectloader.h>
6 #include <msp/datafile/objectloader.h>
7 #include "color.h"
8 #include "placeable.h"
9
10 namespace Msp {
11 namespace GL {
12
13 class ProgramData;
14
15 /**
16 Base class for light sources.  The DirectionalLight and PointLight classes
17 implement different types of lights.
18
19 Lights are usually grouped with a Lighting object, which can be used in a
20 Sequence::Step.
21
22 Shadows can be added to lights by using the ShadowMap effect.
23 */
24 class Light: public Placeable
25 {
26 protected:
27         class Loader: public DataFile::ObjectLoader<Light>
28         {
29         protected:
30                 Loader(Light &);
31
32                 virtual void init_actions();
33
34         private:
35                 void color(float, float, float);
36         };
37
38 public:
39         class GenericLoader: public DataFile::DynamicObjectLoader<Light>
40         {
41                 friend class Light;
42
43         public:
44                 GenericLoader(Collection &c): DynamicObjectLoader<Light>(&c) { }
45
46         protected:
47                 virtual const TypeRegistry &get_type_registry() const { return Light::get_light_registry(); }
48         };
49
50 protected:
51         Color color = { 1.0f };
52         unsigned generation = 0;
53
54         Light() = default;
55 public:
56         virtual ~Light() = default;
57
58         /** Sets the color of the light. */
59         void set_color(const Color &);
60
61         const Color &get_color() const { return color; }
62
63         unsigned get_generation() const { return generation; }
64
65         /** Updates a ProgramData object with the uniform values for the light.  A
66         light source index must be passed in. */
67         void update_shader_data(ProgramData &, unsigned) const;
68
69 protected:
70         virtual void update_shader_data(ProgramData &, const std::string &) const = 0;
71
72 private:
73         static GenericLoader::TypeRegistry &get_light_registry();
74 };
75
76 } // namespace GL
77 } // namespace Msp
78
79 #endif