]> git.tdb.fi Git - libs/gl.git/blobdiff - source/bindable.h
Deal with nontrivial image configurations
[libs/gl.git] / source / bindable.h
index 76c2fb528b7967839fa606a6c8a076ce190ee525..bde5e85a11752b3a95a07de5187ad174b3c4a50a 100644 (file)
@@ -33,6 +33,36 @@ template<typename T>
 const T *Bindable<T>::cur_obj;
 
 
+/**
+A helper class for Bindables that revert to a default object on unbind.
+*/
+template<typename T>
+class BindableWithDefault: protected Bindable<T>
+{
+protected:
+       BindableWithDefault() { }
+
+public:
+       static const T *current()
+       {
+               if(!Bindable<T>::cur_obj)
+                       Bindable<T>::cur_obj = &default_object();
+               return Bindable<T>::cur_obj;
+       }
+
+       static void unbind()
+       {
+               default_object().bind();
+       }
+
+       static const T &default_object()
+       {
+               static T obj;
+               return obj;
+       }
+};
+
+
 /**
 RAII class for binding things.  Binds the thing upon construction and unbinds
 it upon destruction.  If a null pointer is given, unbinds upon construction and