1 #include <msp/gl/extensions/msp_clipping.h>
12 unsigned Clipping::get_n_attach_points()
14 static Require _req(MSP_clipping);
15 static int count = get_i(GL_MAX_CLIP_PLANES);
19 void Clipping::attach(unsigned i, const ClipPlane &p)
21 if(i>=get_n_attach_points())
22 throw out_of_range("Clipping::attach");
29 glEnable(GL_CLIP_PLANE0+i);
32 void Clipping::detach(unsigned i)
39 disable(GL_CLIP_PLANE0+i);
42 void Clipping::update_shader_data(ProgramData &shdata, const Matrix &view_matrix) const
44 Matrix view_inverse = invert(view_matrix);
45 for(unsigned i=0; i<planes.size(); ++i)
47 planes[i]->update_shader_data(shdata, view_inverse, i);
50 void Clipping::bind() const
52 static Require _req(MSP_clipping);
54 const Clipping *old = current();
55 if(!set_current(this))
58 for(unsigned i=0; i<planes.size(); ++i)
61 enable(GL_CLIP_PLANE0+i);
63 disable(GL_CLIP_PLANE0+i);
68 for(unsigned i=planes.size(); i<old->planes.size(); ++i)
69 disable(GL_CLIP_PLANE0+i);
73 void Clipping::unbind()
75 const Clipping *old = current();
79 for(unsigned i=0; i<old->planes.size(); ++i)
81 disable(GL_CLIP_PLANE0+i);