]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/bufferable.cpp
Multiplex streaming buffer contents on Vulkan
[libs/gl.git] / source / core / bufferable.cpp
index 502c270c8f6bad09861841847e1dc71d70d006c7..69588dddef301d72f0eda7128209a5fba632cc63 100644 (file)
@@ -128,14 +128,20 @@ void Bufferable::update_offset()
 
 void Bufferable::mark_dirty()
 {
-       dirty = true;
+       dirty = 0xFF;
 }
 
-void Bufferable::upload_data(char *target) const
+void Bufferable::upload_data(unsigned frame, char *target) const
 {
        if(!buffer)
                throw invalid_operation("Bufferable::upload_data");
 
+       unsigned multi_buf = buffer->get_multiplicity();
+       frame %= multi_buf;
+       uint8_t mask = 1<<frame;
+       if(!(dirty&mask))
+               return;
+
        size_t data_size = get_data_size();
        if(location_dirty)
        {
@@ -149,8 +155,17 @@ void Bufferable::upload_data(char *target) const
                copy(source, source+data_size, target);
        }
        else
-               buffer->sub_data(offset, data_size, get_data_pointer());
-       dirty = false;
+               buffer->sub_data(frame*buffer->get_size()+offset, data_size, get_data_pointer());
+       dirty &= ~mask;
+       if(!(dirty&((1<<multi_buf)-1)))
+               dirty = 0;
+}
+
+Bufferable::AsyncUpdater *Bufferable::create_async_updater() const
+{
+       if(!buffer || buffer->get_multiplicity()>1)
+               throw invalid_operation("Bufferable::create_async_updater");
+       return new AsyncUpdater(*this);
 }
 
 
@@ -168,14 +183,14 @@ Bufferable::AsyncUpdater::~AsyncUpdater()
 
 void Bufferable::AsyncUpdater::upload_data()
 {
-       bufferable.upload_data(mapped_address+bufferable.offset);
+       bufferable.upload_data(0, mapped_address+bufferable.offset);
        // 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)
-                       b->upload_data(mapped_address+b->offset);
+                       b->upload_data(0, mapped_address+b->offset);
        for(const Bufferable *b=bufferable.next_in_buffer; b; b=b->next_in_buffer)
                if(b->dirty)
-                       b->upload_data(mapped_address+b->offset);
+                       b->upload_data(0, mapped_address+b->offset);
 }
 
 } // namespace GL