]> git.tdb.fi Git - libs/gl.git/blob - source/core/clipplane.cpp
fe784d256dbe5dfdf3c754fc3add92c458f96fd1
[libs/gl.git] / source / core / clipplane.cpp
1 #include <msp/strings/format.h>
2 #include "clipplane.h"
3 #include "programdata.h"
4
5 namespace Msp {
6 namespace GL {
7
8 ClipPlane::ClipPlane():
9         eq(0, 0, 0, 1),
10         generation(0)
11 { }
12
13 ClipPlane::ClipPlane(const Vector4 &e):
14         eq(e),
15         generation(0)
16 { }
17
18 ClipPlane::ClipPlane(const Vector3 &p, const Vector3 &d):
19         eq(compose(d, -dot(p, d))),
20         generation(0)
21 { }
22
23 void ClipPlane::set_equation(const Vector4 &e)
24 {
25         eq = e;
26         ++generation;
27 }
28
29 void ClipPlane::set_plane(const Vector3 &p, const Vector3 &d)
30 {
31         Vector3 nd = normalize(d);
32         set_equation(compose(nd, -dot(p, nd)));
33 }
34
35 void ClipPlane::update_shader_data(ProgramData &shdata, unsigned i) const
36 {
37         shdata.uniform(format("clip_planes[%d].equation", i), eq);
38 }
39
40 } // namespace GL
41 } // namespace Msp