1 #include <msp/gl/extensions/msp_clipping.h>
2 #include <msp/gl/extensions/msp_legacy_features.h>
3 #include <msp/strings/format.h>
9 #include "programdata.h"
14 ClipPlane::ClipPlane():
18 ClipPlane::ClipPlane(const Vector4 &e):
22 ClipPlane::ClipPlane(const Vector3 &p, const Vector3 &d):
23 eq(compose(d, -dot(p, d)))
26 void ClipPlane::update(unsigned index) const
29 for(unsigned i=0; i<4; ++i)
31 glClipPlane(GL_CLIP_PLANE0+index, deq);
34 void ClipPlane::set_equation(const Vector4 &e)
37 if(ClipUnit *unit = ClipUnit::find_unit(this))
38 update(unit->get_index());
41 void ClipPlane::set_plane(const Vector3 &p, const Vector3 &d)
43 Vector3 nd = normalize(d);
44 set_equation(compose(nd, -dot(p, nd)));
47 void ClipPlane::update_shader_data(ProgramData &shdata, const Matrix &view_inverse, unsigned i) const
49 shdata.uniform(format("clip_planes[%d].equation", i), eq*view_inverse);
52 void ClipPlane::bind_to(unsigned i) const
54 Require _req(MSP_clipping);
55 Require _req2(MSP_legacy_features);
57 ClipUnit &unit = ClipUnit::get_unit(i);
58 if(unit.set_plane(this))
60 enable(GL_CLIP_PLANE0+unit.get_index());
61 update(unit.get_index());
65 void ClipPlane::unbind_from(unsigned i)
67 ClipUnit &unit = ClipUnit::get_unit(i);
69 disable(GL_CLIP_PLANE0+unit.get_index());