1 #include <msp/core/algorithm.h>
2 #include <msp/gl/extensions/msp_clipping.h>
14 unsigned Clipping::get_n_attach_points()
16 static Require _req(MSP_clipping);
17 static int count = get_i(GL_MAX_CLIP_PLANES);
21 void Clipping::attach(const ClipPlane &p)
23 if(find_member(planes, &p, &AttachedPlane::plane)!=planes.end())
25 if(planes.size()>=get_n_attach_points())
26 throw invalid_operation("Clipping::attach");
30 glEnable(GL_CLIP_PLANE0+planes.size()-1);
33 void Clipping::detach(const ClipPlane &p)
35 vector<AttachedPlane>::iterator i = find_member(planes, &p, &AttachedPlane::plane);
40 disable(GL_CLIP_PLANE0+planes.size());
45 void Clipping::detach(unsigned i)
48 detach(*planes[i].plane);
51 const ProgramData &Clipping::get_shader_data() const
53 for(unsigned i=0; i<planes.size(); ++i)
54 if(planes[i].plane->get_generation()!=planes[i].generation)
56 planes[i].plane->update_shader_data(shdata, i);
57 planes[i].generation = planes[i].plane->get_generation();
63 void Clipping::bind() const
65 static Require _req(MSP_clipping);
67 const Clipping *old = current();
68 if(!set_current(this))
71 for(unsigned i=0; i<planes.size(); ++i)
72 enable(GL_CLIP_PLANE0+i);
76 for(unsigned i=planes.size(); i<old->planes.size(); ++i)
77 disable(GL_CLIP_PLANE0+i);
81 void Clipping::unbind()
83 const Clipping *old = current();
87 for(unsigned i=0; i<old->planes.size(); ++i)
88 disable(GL_CLIP_PLANE0+i);