]> git.tdb.fi Git - libs/gl.git/blobdiff - source/bufferable.cpp
Refactor the internal interface of Bufferable a bit
[libs/gl.git] / source / bufferable.cpp
index eb3f1c006e925244f1c58ff671e4d28237378f4a..04793fb793905ebfae448899195873879d6ff542 100644 (file)
@@ -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