1 #include <msp/gl/extensions/msp_legacy_features.h>
13 bool Clipping::bound_with_legacy = false;
15 void Clipping::attach(unsigned i, const ClipPlane &p)
17 if(i>=ClipUnit::get_n_units())
18 throw out_of_range("Clipping::attach");
29 glEnable(GL_CLIP_PLANE0+i);
33 void Clipping::detach(unsigned i)
42 ClipPlane::unbind_from(i);
44 disable(GL_CLIP_PLANE0+i);
48 void Clipping::update_shader_data(ProgramData &shdata, const Matrix &view_matrix) const
50 Matrix view_inverse = invert(view_matrix);
51 for(unsigned i=0; i<planes.size(); ++i)
53 planes[i]->update_shader_data(shdata, view_inverse, i);
56 void Clipping::bind(bool legacy) const
59 static Require _req(MSP_legacy_features);
61 if(legacy!=bound_with_legacy)
64 const Clipping *old = current();
65 if(!set_current(this))
68 bound_with_legacy = legacy;
71 for(unsigned i=0; i<planes.size(); ++i)
74 planes[i]->bind_to(i);
76 ClipPlane::unbind_from(i);
81 for(unsigned i=planes.size(); i<old->planes.size(); ++i)
82 ClipPlane::unbind_from(i);
87 for(unsigned i=0; i<planes.size(); ++i)
90 enable(GL_CLIP_PLANE0+i);
92 disable(GL_CLIP_PLANE0+i);
97 for(unsigned i=planes.size(); i<old->planes.size(); ++i)
98 disable(GL_CLIP_PLANE0+i);
103 void Clipping::unbind()
105 const Clipping *old = current();
109 if(bound_with_legacy)
111 for(unsigned i=0; i<old->planes.size(); ++i)
113 ClipPlane::unbind_from(i);
117 for(unsigned i=0; i<old->planes.size(); ++i)
119 disable(GL_CLIP_PLANE0+i);