]> git.tdb.fi Git - libs/gl.git/blobdiff - source/bufferable.h
Add a class to negotiate the storage of multiple objects in a buffer
[libs/gl.git] / source / bufferable.h
diff --git a/source/bufferable.h b/source/bufferable.h
new file mode 100644 (file)
index 0000000..dd7cff8
--- /dev/null
@@ -0,0 +1,37 @@
+#ifndef MSP_GL_BUFFERABLE_H_
+#define MSP_GL_BUFFERABLE_H_
+
+namespace Msp {
+namespace GL {
+
+class Buffer;
+
+class Bufferable
+{
+protected:
+       Buffer *buffer;
+       unsigned buffer_offset;
+       Bufferable *next_in_buffer;
+       Bufferable *prev_in_buffer;
+       mutable bool dirty;
+
+       Bufferable();
+public:
+       virtual ~Bufferable();
+
+       void use_buffer(Buffer *, Bufferable * = 0);
+private:
+       void unlink_from_buffer();
+
+protected:
+       virtual unsigned get_data_size() const = 0;
+       virtual const void *get_data() const = 0;
+
+       void update_buffer_offsets();
+       void update_buffer_data() const;
+};
+
+} // namespace GL
+} // namespace Msp
+
+#endif