]> git.tdb.fi Git - libs/gl.git/blob - source/core/clipping.cpp
Add support for integer vertex attributes
[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
7 using namespace std;
8
9 namespace Msp {
10 namespace GL {
11
12 unsigned Clipping::get_n_attach_points()
13 {
14         return Limits::get_global().max_clip_planes;
15 }
16
17 void Clipping::attach(const ClipPlane &p)
18 {
19         if(find_member(planes, &p, &AttachedPlane::plane)!=planes.end())
20                 return;
21         if(planes.size()>=Limits::get_global().max_clip_planes)
22                 throw invalid_operation("Clipping::attach");
23
24         planes.push_back(&p);
25 }
26
27 void Clipping::detach(const ClipPlane &p)
28 {
29         vector<AttachedPlane>::iterator i = find_member(planes, &p, &AttachedPlane::plane);
30         if(i!=planes.end())
31                 planes.erase(i);
32 }
33
34 void Clipping::detach(unsigned i)
35 {
36         if(i<planes.size())
37                 detach(*planes[i].plane);
38 }
39
40 const ProgramData &Clipping::get_shader_data() const
41 {
42         for(unsigned i=0; i<planes.size(); ++i)
43                 if(planes[i].plane->get_generation()!=planes[i].generation)
44                 {
45                         planes[i].plane->update_shader_data(shdata, i);
46                         planes[i].generation = planes[i].plane->get_generation();
47                 }
48
49         return shdata;
50 }
51
52 } // namespace GL
53 } // namespace Msp