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