]> git.tdb.fi Git - libs/gl.git/commitdiff
Add a flag to obtain an aligned size requirement from Bufferable
authorMikko Rasa <tdb@tdb.fi>
Sun, 19 Dec 2021 10:53:48 +0000 (12:53 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sun, 19 Dec 2021 11:40:04 +0000 (13:40 +0200)
source/core/bufferable.cpp
source/core/bufferable.h

index fcedc5becd666efb16ef780a73c4bc8fa24fe5c5..502c270c8f6bad09861841847e1dc71d70d006c7 100644 (file)
@@ -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()
index b430b726277c657fac569fb334bf5c69f624409e..f11d51fa0671b716f7897fdd1f2ed947892f8da9 100644 (file)
@@ -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); }