]> git.tdb.fi Git - libs/gl.git/blob - source/clipunit.cpp
Restore user clip planes in a form compatible with modern OpenGL
[libs/gl.git] / source / clipunit.cpp
1 #include <stdexcept>
2 #include "clipunit.h"
3 #include "gl.h"
4 #include "misc.h"
5
6 using namespace std;
7
8 namespace Msp {
9 namespace GL {
10
11 vector<ClipUnit> ClipUnit::units;
12
13 ClipUnit::ClipUnit():
14         index(0),
15         plane(0)
16 { }
17
18 bool ClipUnit::set_plane(const ClipPlane *p)
19 {
20         bool result = (p!=plane);
21         plane = p;
22         return result;
23 }
24
25 unsigned ClipUnit::get_n_units()
26 {
27         static int count = get_i(GL_MAX_CLIP_PLANES);
28         return count;
29 }
30
31 ClipUnit &ClipUnit::get_unit(unsigned i)
32 {
33         if(i>=get_n_units())
34                 throw out_of_range("ClipUnit::get_unit");
35
36         if(units.size()<=i)
37         {
38                 unsigned j = units.size();
39                 units.resize(i+1, ClipUnit());
40                 for(; j<units.size(); ++j)
41                         units[j].index = j;
42         }
43
44         return units[i];
45 }
46
47 ClipUnit *ClipUnit::find_unit(const ClipPlane *p)
48 {
49         for(vector<ClipUnit>::iterator i=units.begin(); i!=units.end(); ++i)
50                 if(i->plane==p)
51                         return &*i;
52         return 0;
53 }
54
55 } // namespace GL
56 } // namespace Msp