X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fbufferable.cpp;fp=source%2Fbufferable.cpp;h=04793fb793905ebfae448899195873879d6ff542;hp=eb3f1c006e925244f1c58ff671e4d28237378f4a;hb=98cc25ffe956bc162c053c96df659ba40dfe2d6e;hpb=753198a93aff1b535806042ef10567331170fb9e diff --git a/source/bufferable.cpp b/source/bufferable.cpp index eb3f1c00..04793fb7 100644 --- a/source/bufferable.cpp +++ b/source/bufferable.cpp @@ -80,9 +80,8 @@ void Bufferable::update_offset() the buffer is actually used. */ } -void Bufferable::update_buffer() const +bool Bufferable::resize_buffer() const { - BindRestore bind(buffer, buffer->get_type()); if(offset+get_data_size()>=buffer->get_size()) { const Bufferable *last = this; @@ -93,17 +92,36 @@ void Bufferable::update_buffer() const 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(); + return true; } } + return false; +} + +void Bufferable::update_buffer() const +{ + BindRestore bind(buffer, buffer->get_type()); + if(resize_buffer()) + { + /* Resizing the buffer invalidates its contents. Non-dirty data may + be in use, so reupload it. */ + for(const Bufferable *b=prev_in_buffer; b; b=b->prev_in_buffer) + if(!b->dirty) + b->upload_data(); + for(const Bufferable *b=next_in_buffer; b; b=b->next_in_buffer) + if(!b->dirty) + b->upload_data(); + } + upload_data(); dirty = false; } +void Bufferable::upload_data() const +{ + buffer->sub_data(offset, get_data_size(), get_data_pointer()); +} + } // namespace GL } // namespace Msp