]> git.tdb.fi Git - libs/gl.git/blob - source/lightunit.cpp
Support OpenGL ES on Android
[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 LightUnit *LightUnit::cur_unit = 0;
14
15 LightUnit::LightUnit():
16         light(0)
17 { }
18
19 bool LightUnit::set_light(const Light *l)
20 {
21         bool result = (l!=light);
22         light = l;
23         return result;
24 }
25
26 unsigned LightUnit::get_n_units()
27 {
28         static int count = (MSP_legacy_features ? get_i(GL_MAX_LIGHTS) : 0);
29         return count;
30 }
31
32 LightUnit &LightUnit::get_unit(unsigned n)
33 {
34         if(n>=get_n_units())
35                 throw out_of_range("LightUnit::get_unit");
36
37         if(units.size()<=n)
38         {
39                 unsigned i = units.size();
40                 units.resize(n+1, LightUnit());
41                 for(; i<units.size(); ++i)
42                         units[i].index = i;
43         }
44
45         return units[n];
46 }
47
48 LightUnit *LightUnit::find_unit(const Light *l)
49 {
50         for(vector<LightUnit>::iterator i=units.begin(); i!=units.end(); ++i)
51                 if(i->light==l)
52                         return &*i;
53         return 0;
54 }
55
56 } // namespace GL
57 } // namespace Msp