X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=sidebyside;f=source%2Fbufferable.cpp;fp=source%2Fbufferable.cpp;h=12e0aef7d345da45e948820606211926c1de9b49;hb=719578516a4d44a6f39eac3b074ce9f6180b5d53;hp=4660e9c31b32f787bfc553326078da669063b0a5;hpb=ab83db6f1e31d44ced585119a57fd10896e469cb;p=libs%2Fgl.git diff --git a/source/bufferable.cpp b/source/bufferable.cpp index 4660e9c3..12e0aef7 100644 --- a/source/bufferable.cpp +++ b/source/bufferable.cpp @@ -74,19 +74,22 @@ void Bufferable::update_buffer_offset() void Bufferable::update_buffer_data() const { - const Bufferable *first = this; - for(; first->prev_in_buffer; first=first->prev_in_buffer) ; - - unsigned total_size = 0; - for(const Bufferable *b=first; b; b=b->next_in_buffer) - total_size += b->get_data_size(); - - if(total_size!=buffer->get_size()) + if(buffer_offset+get_data_size()>=buffer->get_size()) { - 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; + const Bufferable *last = this; + for(; last->next_in_buffer; last=last->next_in_buffer) ; + + unsigned total_size = last->buffer_offset+last->get_data_size(); + + if(total_size>buffer->get_size()) + { + buffer->data(total_size, 0); + /* Resizing the buffer invalidates its contents. Non-dirty data may + be in use, so reupload it. */ + for(const Bufferable *b=last; b; b=b->prev_in_buffer) + if(!b->dirty) + b->upload_data(); + } } upload_data();