From 5fa0901a84cdba32f491a4e3997916f2fbb30863 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 19 Dec 2021 12:53:48 +0200 Subject: [PATCH] Add a flag to obtain an aligned size requirement from Bufferable --- source/core/bufferable.cpp | 13 +++++++++++-- source/core/bufferable.h | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/source/core/bufferable.cpp b/source/core/bufferable.cpp index fcedc5be..502c270c 100644 --- a/source/core/bufferable.cpp +++ b/source/core/bufferable.cpp @@ -70,11 +70,20 @@ void Bufferable::change_buffer(Buffer *buf) } } -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() diff --git a/source/core/bufferable.h b/source/core/bufferable.h index b430b726..f11d51fa 100644 --- a/source/core/bufferable.h +++ b/source/core/bufferable.h @@ -60,7 +60,7 @@ public: /** Returns the total amount of storage required by this object and others in the same chain, including any padding required by object alignment. */ - std::size_t get_required_buffer_size() const; + std::size_t get_required_buffer_size(bool = false) const; /** Uploads new data into the buffer if necessary. */ void refresh() const { if(dirty) upload_data(0); } -- 2.45.2