]> git.tdb.fi Git - libs/gl.git/blobdiff - source/misc.h
Generalize VertexBuffer into Buffer with support for other types as well
[libs/gl.git] / source / misc.h
index e9ed91bfa672b300214a69afe06c680b12993bae..7aa8aaf9e7fb6d41c3d4acc893b464d581675b51 100644 (file)
@@ -20,6 +20,31 @@ void set(GLenum, bool);
 void get(GLenum, int &);
 int get_i(GLenum);
 
+class Bind
+{
+private:
+       struct Base
+       {
+               virtual ~Base() { }
+       };
+
+       template<typename T>
+       struct Binder: Base
+       {
+               const T &obj;
+
+               Binder(const T &o): obj(o) { obj.bind(); }
+               ~Binder() { obj.unbind(); }
+       };
+
+       Base *binder;
+
+public:
+       template<typename T>
+       Bind(const T &o): binder(new Binder<T>(o)) { }
+       ~Bind() { delete binder; }
+};
+
 } // namespace GL
 } // namespace Msp