From: Mikko Rasa Date: Sat, 8 May 2021 13:40:23 +0000 (+0300) Subject: Change Clipping to use index-less attaching X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=a77629d781eeb789870470c5ebdbd4b691e1b138;p=libs%2Fgl.git Change Clipping to use index-less attaching --- 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;