void Bufferable::mark_dirty()
{
- dirty = true;
+ dirty = 0xFF;
}
-void Bufferable::upload_data(char *target) const
+void Bufferable::upload_data(unsigned frame, char *target) const
{
if(!buffer)
throw invalid_operation("Bufferable::upload_data");
+ unsigned multi_buf = buffer->get_multiplicity();
+ frame %= multi_buf;
+ uint8_t mask = 1<<frame;
+ if(!(dirty&mask))
+ return;
+
size_t data_size = get_data_size();
if(location_dirty)
{
copy(source, source+data_size, target);
}
else
- buffer->sub_data(offset, data_size, get_data_pointer());
- dirty = false;
+ buffer->sub_data(frame*buffer->get_size()+offset, data_size, get_data_pointer());
+ dirty &= ~mask;
+ if(!(dirty&((1<<multi_buf)-1)))
+ dirty = 0;
+}
+
+Bufferable::AsyncUpdater *Bufferable::create_async_updater() const
+{
+ if(!buffer || buffer->get_multiplicity()>1)
+ throw invalid_operation("Bufferable::create_async_updater");
+ return new AsyncUpdater(*this);
}
void Bufferable::AsyncUpdater::upload_data()
{
- bufferable.upload_data(mapped_address+bufferable.offset);
+ bufferable.upload_data(0, mapped_address+bufferable.offset);
// Update all bufferables in the same buffer at once
for(const Bufferable *b=bufferable.prev_in_buffer; b; b=b->prev_in_buffer)
if(b->dirty)
- b->upload_data(mapped_address+b->offset);
+ b->upload_data(0, mapped_address+b->offset);
for(const Bufferable *b=bufferable.next_in_buffer; b; b=b->next_in_buffer)
if(b->dirty)
- b->upload_data(mapped_address+b->offset);
+ b->upload_data(0, mapped_address+b->offset);
}
} // namespace GL