1 #ifndef MSP_GL_BUFFERABLE_H_
2 #define MSP_GL_BUFFERABLE_H_
10 Base class for things that can store data in buffers. Supports buffer sharing.
11 A dirty flag is provided for derived classes. It should be set when the data
12 in the buffer is considered out of date, and is cleared by Bufferable after
13 uploading fresh data to the buffer.
20 Bufferable *next_in_buffer;
21 Bufferable *prev_in_buffer;
28 virtual ~Bufferable();
30 /** Sets the buffer to use. If prev is not null, it must use the same
31 buffer, and this object is inserted after it. */
32 void use_buffer(Buffer *buf, Bufferable *prev = 0);
34 /** Uploads new data into the buffer if necessary. */
35 void refresh() const { if(dirty) update_buffer(); }
38 void unlink_from_buffer();
41 /** Returns the buffer in which the data is stored. */
42 Buffer *get_buffer() const { return buffer; }
44 /** Returns the amount of data to be stored in the buffer, in bytes. */
45 virtual unsigned get_data_size() const = 0;
47 /** Returns the alignment required for the data, in bytes. The offset is
48 guaranteed to be a multiple of this. */
49 virtual unsigned get_alignment() const { return 1; }
51 /** Updates the offsets for the chain so that data from different objects
52 does not overlap. Should be called if either data size or alignment
56 /** Returns the offset where the data should be uploaded. */
57 unsigned get_offset() const { return offset; }
59 /** Called when the offset for the data has changed. */
60 virtual void offset_changed() { }
62 /** Resizes the buffer if necessary and calls upload_data(). */
63 void update_buffer() const;
65 /** Uploads data to the buffer. */
66 virtual void upload_data() const = 0;