1 #include <msp/core/algorithm.h>
2 #include <msp/gl/extensions/msp_clipping.h>
5 #include "deviceinfo.h"
15 unsigned Clipping::get_n_attach_points()
17 return Limits::get_global().max_clip_planes;
20 void Clipping::attach(const ClipPlane &p)
22 if(find_member(planes, &p, &AttachedPlane::plane)!=planes.end())
24 if(planes.size()>=Limits::get_global().max_clip_planes)
25 throw invalid_operation("Clipping::attach");
29 glEnable(GL_CLIP_PLANE0+planes.size()-1);
32 void Clipping::detach(const ClipPlane &p)
34 vector<AttachedPlane>::iterator i = find_member(planes, &p, &AttachedPlane::plane);
39 disable(GL_CLIP_PLANE0+planes.size());
44 void Clipping::detach(unsigned i)
47 detach(*planes[i].plane);
50 const ProgramData &Clipping::get_shader_data() const
52 for(unsigned i=0; i<planes.size(); ++i)
53 if(planes[i].plane->get_generation()!=planes[i].generation)
55 planes[i].plane->update_shader_data(shdata, i);
56 planes[i].generation = planes[i].plane->get_generation();
62 void Clipping::bind() const
64 static Require _req(MSP_clipping);
66 const Clipping *old = current();
67 if(!set_current(this))
70 for(unsigned i=0; i<planes.size(); ++i)
71 enable(GL_CLIP_PLANE0+i);
75 for(unsigned i=planes.size(); i<old->planes.size(); ++i)
76 disable(GL_CLIP_PLANE0+i);
80 void Clipping::unbind()
82 const Clipping *old = current();
86 for(unsigned i=0; i<old->planes.size(); ++i)
87 disable(GL_CLIP_PLANE0+i);