]> git.tdb.fi Git - libs/gl.git/blob - source/lightunit.cpp
Use a renderer in the viewer
[libs/gl.git] / source / lightunit.cpp
1 #include <stdexcept>
2 #include "gl.h"
3 #include "misc.h"
4 #include "lightunit.h"
5
6 using namespace std;
7
8 namespace Msp {
9 namespace GL {
10
11 vector<LightUnit> LightUnit::units;
12 LightUnit *LightUnit::cur_unit = 0;
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 = get_i(GL_MAX_LIGHTS);
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