]> git.tdb.fi Git - libs/gl.git/blob - source/lightunit.cpp
Reimplement Animation using splines
[libs/gl.git] / source / lightunit.cpp
1 #include <stdexcept>
2 #include <msp/gl/extensions/msp_legacy_features.h>
3 #include "gl.h"
4 #include "misc.h"
5 #include "lightunit.h"
6
7 using namespace std;
8
9 namespace Msp {
10 namespace GL {
11
12 vector<LightUnit> LightUnit::units;
13
14 LightUnit::LightUnit():
15         light(0)
16 { }
17
18 bool LightUnit::set_light(const Light *l)
19 {
20         bool result = (l!=light);
21         light = l;
22         return result;
23 }
24
25 unsigned LightUnit::get_n_units()
26 {
27         static int count = (MSP_legacy_features ? get_i(GL_MAX_LIGHTS) : 0);
28         return count;
29 }
30
31 LightUnit &LightUnit::get_unit(unsigned n)
32 {
33         if(n>=get_n_units())
34                 throw out_of_range("LightUnit::get_unit");
35
36         if(units.size()<=n)
37         {
38                 unsigned i = units.size();
39                 units.resize(n+1, LightUnit());
40                 for(; i<units.size(); ++i)
41                         units[i].index = i;
42         }
43
44         return units[n];
45 }
46
47 LightUnit *LightUnit::find_unit(const Light *l)
48 {
49         for(vector<LightUnit>::iterator i=units.begin(); i!=units.end(); ++i)
50                 if(i->light==l)
51                         return &*i;
52         return 0;
53 }
54
55 } // namespace GL
56 } // namespace Msp