X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcore%2Fbufferable.cpp;h=69588dddef301d72f0eda7128209a5fba632cc63;hb=6d2e2a0bb28496a8c25b441009bdd2a1a1e72d81;hp=c312a4339a876f8436877842f44e689aa3f32b7a;hpb=be6ffe96ecb4707599fe1a6f620c348760213d46;p=libs%2Fgl.git
diff --git a/source/core/bufferable.cpp b/source/core/bufferable.cpp
index c312a433..69588ddd 100644
--- a/source/core/bufferable.cpp
+++ b/source/core/bufferable.cpp
@@ -8,6 +8,23 @@ using namespace std;
namespace Msp {
namespace GL {
+Bufferable::Bufferable(Bufferable &&other):
+ buffer(other.buffer),
+ offset(other.offset),
+ next_in_buffer(other.next_in_buffer),
+ prev_in_buffer(other.prev_in_buffer),
+ location_dirty(other.location_dirty),
+ dirty(other.dirty)
+{
+ other.buffer = 0;
+ other.next_in_buffer = 0;
+ other.prev_in_buffer = 0;
+ if(next_in_buffer)
+ next_in_buffer->prev_in_buffer = this;
+ if(prev_in_buffer)
+ prev_in_buffer->next_in_buffer = this;
+}
+
Bufferable::~Bufferable()
{
unlink_from_buffer();
@@ -33,7 +50,7 @@ void Bufferable::use_buffer(Buffer *buf, Bufferable *prev)
}
location_dirty = true;
- dirty = true;
+ mark_dirty();
update_offset();
}
@@ -43,21 +60,30 @@ void Bufferable::change_buffer(Buffer *buf)
{
b->buffer = buf;
b->location_dirty = true;
- b->dirty = true;
+ b->mark_dirty();
}
for(Bufferable *b=prev_in_buffer; b; b=b->prev_in_buffer)
{
b->buffer = buf;
b->location_dirty = true;
- b->dirty = true;
+ b->mark_dirty();
}
}
-size_t Bufferable::get_required_buffer_size() const
+size_t Bufferable::get_required_buffer_size(bool align) const
{
const Bufferable *last = this;
for(; last->next_in_buffer; last=last->next_in_buffer) ;
- return last->offset+last->get_data_size();
+ size_t size = last->offset+last->get_data_size();
+ if(align)
+ {
+ const Bufferable *first = this;
+ for(; first->prev_in_buffer; first=first->prev_in_buffer) ;
+ size_t alignment = first->get_alignment();
+ size += alignment-1;
+ size -= size%alignment;
+ }
+ return size;
}
void Bufferable::unlink_from_buffer()
@@ -88,7 +114,7 @@ void Bufferable::update_offset()
{
offset = new_offset;
location_dirty = true;
- dirty = true;
+ mark_dirty();
}
if(next_in_buffer)
@@ -96,15 +122,26 @@ void Bufferable::update_offset()
else if(buffer && offset+get_data_size()>buffer->get_size())
{
location_dirty = true;
- dirty = true;
+ mark_dirty();
}
}
-void Bufferable::upload_data(char *target) const
+void Bufferable::mark_dirty()
+{
+ dirty = 0xFF;
+}
+
+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<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<get_multiplicity()>1)
+ throw invalid_operation("Bufferable::create_async_updater");
+ return new AsyncUpdater(*this);
}
@@ -137,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