+#include <msp/core/algorithm.h>
#include <msp/gl/extensions/msp_clipping.h>
#include "clipping.h"
#include "clipplane.h"
+#include "error.h"
#include "matrix.h"
#include "misc.h"
return count;
}
-void Clipping::attach(unsigned i, const ClipPlane &p)
+void Clipping::attach(const ClipPlane &p)
{
- if(i>=get_n_attach_points())
- throw out_of_range("Clipping::attach");
-
- if(i>=planes.size())
- planes.resize(i+1);
+ if(find(planes, &p)!=planes.end())
+ return;
+ if(planes.size()>=get_n_attach_points())
+ throw invalid_operation("Clipping::attach");
- planes[i] = &p;
+ planes.push_back(&p);
if(current()==this)
- glEnable(GL_CLIP_PLANE0+i);
+ glEnable(GL_CLIP_PLANE0+planes.size()-1);
}
-void Clipping::detach(unsigned i)
+void Clipping::detach(const ClipPlane &p)
{
- if(i>=planes.size())
- return;
+ vector<const ClipPlane *>::iterator i = find(planes, &p);
+ if(i!=planes.end())
+ {
+ planes.erase(i);
+ if(current()==this)
+ disable(GL_CLIP_PLANE0+planes.size());
- planes[i] = 0;
- if(current()==this)
- disable(GL_CLIP_PLANE0+i);
+ }
+}
+
+void Clipping::detach(unsigned i)
+{
+ if(i<planes.size())
+ detach(*planes[i]);
}
void Clipping::update_shader_data(ProgramData &shdata, const Matrix &view_matrix) const
{
Matrix view_inverse = invert(view_matrix);
for(unsigned i=0; i<planes.size(); ++i)
- if(planes[i])
- planes[i]->update_shader_data(shdata, view_inverse, i);
+ planes[i]->update_shader_data(shdata, view_inverse, i);
}
void Clipping::bind() const
return;
for(unsigned i=0; i<planes.size(); ++i)
- {
- if(planes[i])
- enable(GL_CLIP_PLANE0+i);
- else
- disable(GL_CLIP_PLANE0+i);
- }
+ enable(GL_CLIP_PLANE0+i);
if(old)
{
return;
for(unsigned i=0; i<old->planes.size(); ++i)
- if(old->planes[i])
- disable(GL_CLIP_PLANE0+i);
+ disable(GL_CLIP_PLANE0+i);
}
} // namespace GL
#define MSP_GL_CLIPPING_H_
#include <vector>
+#include <msp/core/attributes.h>
#include "bindable.h"
namespace Msp {
public:
static unsigned get_n_attach_points();
- void attach(unsigned, const ClipPlane &);
- void detach(unsigned);
+ void attach(const ClipPlane &);
+ void detach(const ClipPlane &);
+
+ DEPRECATED void attach(unsigned, const ClipPlane &p) { attach(p); }
+ DEPRECATED void detach(unsigned);
void update_shader_data(ProgramData &, const Matrix &) const;