]> git.tdb.fi Git - libs/gl.git/blob - source/materials/pointlight.cpp
Refactor the builtin occluder shader
[libs/gl.git] / source / materials / pointlight.cpp
1 #include "pointlight.h"
2 #include "programdata.h"
3
4 using namespace std;
5
6 namespace Msp {
7 namespace GL {
8
9 void PointLight::update_matrix()
10 {
11         matrix = Matrix::translation(position);
12 }
13
14 void PointLight::set_matrix(const Matrix &m)
15 {
16         Placeable::set_matrix(m);
17         position = matrix.column(3).slice<3>(0);
18         update_matrix();
19         ++generation;
20 }
21
22 void PointLight::set_position(const Vector3 &p)
23 {
24         position = p;
25         update_matrix();
26         ++generation;
27 }
28
29 void PointLight::set_attenuation(float c, float l, float q)
30 {
31         attenuation[0] = c;
32         attenuation[1] = l;
33         attenuation[2] = q;
34         ++generation;
35 }
36
37 void PointLight::update_shader_data(ProgramData &shdata, const string &base) const
38 {
39         shdata.uniform(base+".type", 2);
40         shdata.uniform(base+".position", position.x, position.y, position.z, 1.0f);
41         shdata.uniform(base+".color", color.r, color.g, color.b);
42         shdata.uniform3(base+".attenuation", attenuation);
43 }
44
45
46 DataFile::Loader::ActionMap PointLight::Loader::shared_actions;
47
48 PointLight::Loader::Loader(PointLight &l):
49         DerivedObjectLoader<PointLight, Light::Loader>(l)
50 {
51         set_actions(shared_actions);
52 }
53
54 void PointLight::Loader::init_actions()
55 {
56         Light::Loader::init_actions();
57         add("attenuation", &Loader::attenuation);
58         add("position", &Loader::position);
59 }
60
61 void PointLight::Loader::attenuation(float c, float l, float q)
62 {
63         obj.set_attenuation(c, l, q);
64 }
65
66 void PointLight::Loader::position(float x, float y, float z)
67 {
68         obj.set_position(Vector3(x, y, z));
69 }
70
71 } // namespace GL
72 } // namespace Msp