From a77629d781eeb789870470c5ebdbd4b691e1b138 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 8 May 2021 16:40:23 +0300 Subject: [PATCH] Change Clipping to use index-less attaching --- source/core/clipping.cpp | 50 +++++++++++++++++++++------------------- source/core/clipping.h | 8 +++++-- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/source/core/clipping.cpp b/source/core/clipping.cpp index 3bdeee3c..c286b7e5 100644 --- a/source/core/clipping.cpp +++ b/source/core/clipping.cpp @@ -1,6 +1,8 @@ +#include #include #include "clipping.h" #include "clipplane.h" +#include "error.h" #include "matrix.h" #include "misc.h" @@ -16,35 +18,41 @@ unsigned Clipping::get_n_attach_points() 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::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(iupdate_shader_data(shdata, view_inverse, i); + planes[i]->update_shader_data(shdata, view_inverse, i); } void Clipping::bind() const @@ -56,12 +64,7 @@ void Clipping::bind() const return; for(unsigned i=0; iplanes.size(); ++i) - if(old->planes[i]) - disable(GL_CLIP_PLANE0+i); + disable(GL_CLIP_PLANE0+i); } } // namespace GL diff --git a/source/core/clipping.h b/source/core/clipping.h index e42c28e6..319a8d98 100644 --- a/source/core/clipping.h +++ b/source/core/clipping.h @@ -2,6 +2,7 @@ #define MSP_GL_CLIPPING_H_ #include +#include #include "bindable.h" namespace Msp { @@ -19,8 +20,11 @@ private: 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; -- 2.43.0