X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fbufferable.cpp;fp=source%2Fbufferable.cpp;h=4660e9c31b32f787bfc553326078da669063b0a5;hp=5c7cb9e0891a74a753987dd32735a128228c6def;hb=f6e51c2f771726eec73b07824ebde2cf8bd522f0;hpb=73fd6d13b8e68b2aeec8e5c85227cf361fdb467e diff --git a/source/bufferable.cpp b/source/bufferable.cpp index 5c7cb9e0..4660e9c3 100644 --- a/source/bufferable.cpp +++ b/source/bufferable.cpp @@ -36,7 +36,7 @@ void Bufferable::use_buffer(Buffer *buf, Bufferable *prev) prev_in_buffer->next_in_buffer = this; } - update_buffer_offsets(); + update_buffer_offset(); } void Bufferable::unlink_from_buffer() @@ -46,13 +46,13 @@ void Bufferable::unlink_from_buffer() if(next_in_buffer) { next_in_buffer->prev_in_buffer = prev_in_buffer; - next_in_buffer->update_buffer_offsets(); + next_in_buffer->update_buffer_offset(); } prev_in_buffer = 0; next_in_buffer = 0; } -void Bufferable::update_buffer_offsets() +void Bufferable::update_buffer_offset() { unsigned offset = 0; if(prev_in_buffer) @@ -62,10 +62,14 @@ void Bufferable::update_buffer_offsets() { buffer_offset = offset; dirty = true; + offset_changed(); } if(next_in_buffer) - next_in_buffer->update_buffer_offsets(); + next_in_buffer->update_buffer_offset(); + + /* Do not resize the buffer here, as the offsets may change multiple times + before the buffer is actually used */ } void Bufferable::update_buffer_data() const @@ -77,12 +81,16 @@ void Bufferable::update_buffer_data() const for(const Bufferable *b=first; b; b=b->next_in_buffer) total_size += b->get_data_size(); - buffer->data(total_size, 0); - for(const Bufferable *b=first; b; b=b->next_in_buffer) + if(total_size!=buffer->get_size()) { - buffer->sub_data(b->buffer_offset, b->get_data_size(), b->get_data()); - b->dirty = false; + buffer->data(total_size, 0); + // Resizing the buffer invalidates its contents. + for(const Bufferable *b=first; b; b=b->next_in_buffer) + b->dirty = true; } + + upload_data(); + dirty = false; } } // namespace GL