]> git.tdb.fi Git - libs/gl.git/blobdiff - source/bufferable.cpp
Clear the dirty flag of Bufferable in upload_data
[libs/gl.git] / source / bufferable.cpp
index 569ffb2f08a252cb1d153e591df420a1108dcf5a..6b770a8f68f2c447bb18fe608930cba4bf9e6ab7 100644 (file)
@@ -1,4 +1,6 @@
 #include <stdexcept>
+#include <msp/core/raii.h>
+#include <msp/gl/extensions/arb_direct_state_access.h>
 #include "bindable.h"
 #include "buffer.h"
 #include "bufferable.h"
@@ -40,6 +42,7 @@ void Bufferable::use_buffer(Buffer *buf, Bufferable *prev)
                }
        }
 
+       dirty = true;
        update_offset();
 }
 
@@ -106,7 +109,8 @@ bool Bufferable::resize_buffer() const
 
 void Bufferable::update_buffer() const
 {
-       BindRestore bind(buffer, buffer->get_type());
+       Conditional<BindRestore> _bind(!ARB_direct_state_access, buffer, buffer->get_type());
+
        if(resize_buffer())
        {
                /* Resizing the buffer invalidates its contents.  Non-dirty data may
@@ -120,7 +124,6 @@ void Bufferable::update_buffer() const
        }
 
        upload_data(0);
-       dirty = false;
 }
 
 void Bufferable::upload_data(char *target) const
@@ -132,6 +135,7 @@ void Bufferable::upload_data(char *target) const
        }
        else
                buffer->sub_data(offset, get_data_size(), get_data_pointer());
+       dirty = false;
 }
 
 
@@ -153,16 +157,10 @@ void Bufferable::AsyncUpdater::upload_data()
        // 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 || buffer_resized)
-               {
                        b->upload_data(mapped_address+b->offset);
-                       b->dirty = false;
-               }
        for(const Bufferable *b=bufferable.next_in_buffer; b; b=b->next_in_buffer)
                if(b->dirty || buffer_resized)
-               {
                        b->upload_data(mapped_address+b->offset);
-                       b->dirty = false;
-               }
 }
 
 } // namespace GL