3 This file is part of libmspgl
4 Copyright © 2010 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
8 #ifndef MSP_GL_BINDABLE_H_
9 #define MSP_GL_BINDABLE_H_
18 static const T *cur_obj;
22 static bool set_current(const T *obj)
32 const T *current() const { return cur_obj; }
36 const T *Bindable<T>::cur_obj;
40 RAII class for binding things. Binds the thing upon construction and unbinds
41 it upon destruction. If a null pointer is given, unbinds upon construction and
42 does nothing upon destruction.
57 Binder(const T &o): obj(o) { obj.bind(); }
58 ~Binder() { obj.unbind(); }
65 Bind(const T &o): binder(new Binder<T>(o)) { }
68 Bind(const T *o): binder(o ? new Binder<T>(*o) : 0) { if(!o) T::unbind(); }
72 Bind &operator=(const Bind &);
75 ~Bind() { delete binder; }