1 #include <msp/gl/extensions/msp_clipping.h>
2 #include <msp/gl/extensions/msp_legacy_features.h>
14 bool Clipping::bound_with_legacy = false;
16 void Clipping::attach(unsigned i, const ClipPlane &p)
18 if(i>=ClipUnit::get_n_units())
19 throw out_of_range("Clipping::attach");
30 glEnable(GL_CLIP_PLANE0+i);
34 void Clipping::detach(unsigned i)
43 ClipPlane::unbind_from(i);
45 disable(GL_CLIP_PLANE0+i);
49 void Clipping::update_shader_data(ProgramData &shdata, const Matrix &view_matrix) const
51 Matrix view_inverse = invert(view_matrix);
52 for(unsigned i=0; i<planes.size(); ++i)
54 planes[i]->update_shader_data(shdata, view_inverse, i);
57 void Clipping::bind(bool legacy) const
59 static Require _req(MSP_clipping);
61 static Require _req2(MSP_legacy_features);
63 if(legacy!=bound_with_legacy)
66 const Clipping *old = current();
67 if(!set_current(this))
70 bound_with_legacy = legacy;
73 for(unsigned i=0; i<planes.size(); ++i)
76 planes[i]->bind_to(i);
78 ClipPlane::unbind_from(i);
83 for(unsigned i=planes.size(); i<old->planes.size(); ++i)
84 ClipPlane::unbind_from(i);
89 for(unsigned i=0; i<planes.size(); ++i)
92 enable(GL_CLIP_PLANE0+i);
94 disable(GL_CLIP_PLANE0+i);
99 for(unsigned i=planes.size(); i<old->planes.size(); ++i)
100 disable(GL_CLIP_PLANE0+i);
105 void Clipping::unbind()
107 const Clipping *old = current();
111 if(bound_with_legacy)
113 for(unsigned i=0; i<old->planes.size(); ++i)
115 ClipPlane::unbind_from(i);
119 for(unsigned i=0; i<old->planes.size(); ++i)
121 disable(GL_CLIP_PLANE0+i);