]> git.tdb.fi Git - libs/gl.git/blob - source/materials/light.cpp
24bd8fa9c443483f581a8ed72b59a5df6e00445d
[libs/gl.git] / source / materials / light.cpp
1 #include <stdexcept>
2 #include <msp/strings/format.h>
3 #include "directionallight.h"
4 #include "light.h"
5 #include "pointlight.h"
6
7 using namespace std;
8
9 namespace Msp {
10 namespace GL {
11
12 Light::Light():
13         color(1.0f),
14         generation(0)
15 { }
16
17 void Light::set_color(const Color &c)
18 {
19         color = c;
20         ++generation;
21 }
22
23 void Light::update_shader_data(ProgramData &shdata, unsigned i) const
24 {
25         update_shader_data(shdata, format("light_sources[%d]", i));
26 }
27
28 Light::GenericLoader::TypeRegistry &Light::get_light_registry()
29 {
30         static GenericLoader::TypeRegistry registry;
31         static bool initialized = false;
32         if(!initialized)
33         {
34                 initialized = true;
35                 registry.register_type<DirectionalLight>("directional");
36                 registry.register_type<PointLight>("point");
37         }
38         return registry;
39 }
40
41
42 Light::Loader::Loader(Light &l):
43         DataFile::ObjectLoader<Light>(l)
44 { }
45
46 void Light::Loader::init_actions()
47 {
48         add("color", &Loader::color);
49 }
50
51 void Light::Loader::color(float r, float g, float b)
52 {
53         obj.set_color(Color(r, g, b));
54 }
55
56 } // namespace GL
57 } // namespace Msp