]> git.tdb.fi Git - libs/gl.git/blob - source/core/clipping.cpp
Remove public binding APIs from Renderbuffer and Clipping
[libs/gl.git] / source / core / clipping.cpp
1 #include <msp/core/algorithm.h>
2 #include "clipping.h"
3 #include "clipplane.h"
4 #include "deviceinfo.h"
5 #include "error.h"
6 #include "matrix.h"
7
8 using namespace std;
9
10 namespace Msp {
11 namespace GL {
12
13 unsigned Clipping::get_n_attach_points()
14 {
15         return Limits::get_global().max_clip_planes;
16 }
17
18 void Clipping::attach(const ClipPlane &p)
19 {
20         if(find_member(planes, &p, &AttachedPlane::plane)!=planes.end())
21                 return;
22         if(planes.size()>=Limits::get_global().max_clip_planes)
23                 throw invalid_operation("Clipping::attach");
24
25         planes.push_back(&p);
26 }
27
28 void Clipping::detach(const ClipPlane &p)
29 {
30         vector<AttachedPlane>::iterator i = find_member(planes, &p, &AttachedPlane::plane);
31         if(i!=planes.end())
32                 planes.erase(i);
33 }
34
35 void Clipping::detach(unsigned i)
36 {
37         if(i<planes.size())
38                 detach(*planes[i].plane);
39 }
40
41 const ProgramData &Clipping::get_shader_data() const
42 {
43         for(unsigned i=0; i<planes.size(); ++i)
44                 if(planes[i].plane->get_generation()!=planes[i].generation)
45                 {
46                         planes[i].plane->update_shader_data(shdata, i);
47                         planes[i].generation = planes[i].plane->get_generation();
48                 }
49
50         return shdata;
51 }
52
53 } // namespace GL
54 } // namespace Msp