X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fmisc.h;h=7aa8aaf9e7fb6d41c3d4acc893b464d581675b51;hp=e9ed91bfa672b300214a69afe06c680b12993bae;hb=76e338af116120d93d082ad247591ec9adad9233;hpb=e17243fb2421977cb781361828b77718e2cf8d48 diff --git a/source/misc.h b/source/misc.h index e9ed91bf..7aa8aaf9 100644 --- a/source/misc.h +++ b/source/misc.h @@ -20,6 +20,31 @@ void set(GLenum, bool); void get(GLenum, int &); int get_i(GLenum); +class Bind +{ +private: + struct Base + { + virtual ~Base() { } + }; + + template + struct Binder: Base + { + const T &obj; + + Binder(const T &o): obj(o) { obj.bind(); } + ~Binder() { obj.unbind(); } + }; + + Base *binder; + +public: + template + Bind(const T &o): binder(new Binder(o)) { } + ~Bind() { delete binder; } +}; + } // namespace GL } // namespace Msp