]> git.tdb.fi Git - libs/gl.git/blobdiff - source/clipunit.cpp
Restore user clip planes in a form compatible with modern OpenGL
[libs/gl.git] / source / clipunit.cpp
diff --git a/source/clipunit.cpp b/source/clipunit.cpp
new file mode 100644 (file)
index 0000000..83080bd
--- /dev/null
@@ -0,0 +1,56 @@
+#include <stdexcept>
+#include "clipunit.h"
+#include "gl.h"
+#include "misc.h"
+
+using namespace std;
+
+namespace Msp {
+namespace GL {
+
+vector<ClipUnit> ClipUnit::units;
+
+ClipUnit::ClipUnit():
+       index(0),
+       plane(0)
+{ }
+
+bool ClipUnit::set_plane(const ClipPlane *p)
+{
+       bool result = (p!=plane);
+       plane = p;
+       return result;
+}
+
+unsigned ClipUnit::get_n_units()
+{
+       static int count = get_i(GL_MAX_CLIP_PLANES);
+       return count;
+}
+
+ClipUnit &ClipUnit::get_unit(unsigned i)
+{
+       if(i>=get_n_units())
+               throw out_of_range("ClipUnit::get_unit");
+
+       if(units.size()<=i)
+       {
+               unsigned j = units.size();
+               units.resize(i+1, ClipUnit());
+               for(; j<units.size(); ++j)
+                       units[j].index = j;
+       }
+
+       return units[i];
+}
+
+ClipUnit *ClipUnit::find_unit(const ClipPlane *p)
+{
+       for(vector<ClipUnit>::iterator i=units.begin(); i!=units.end(); ++i)
+               if(i->plane==p)
+                       return &*i;
+       return 0;
+}
+
+} // namespace GL
+} // namespace Msp