]> git.tdb.fi Git - libs/gl.git/commitdiff
Use a streaming buffer for ProgramData only when needed
authorMikko Rasa <tdb@tdb.fi>
Sun, 19 Dec 2021 23:26:15 +0000 (01:26 +0200)
committerMikko Rasa <tdb@tdb.fi>
Mon, 20 Dec 2021 00:14:45 +0000 (02:14 +0200)
source/render/programdata.cpp
source/render/programdata.h

index 0aebdcd9a5747aa9f823ceb2a5116e3e45182560..e7c171754aed006dab1ecbdcedd272ddd894a396 100644 (file)
@@ -116,7 +116,15 @@ bool ProgramData::validate_tag(Tag tag) const
 void ProgramData::mark_dirty(Mask bits)
 {
        if(!dirty)
+       {
+               if(generation && !streaming)
+               {
+                       streaming = true;
+                       if(buffer && buffer->get_size())
+                               recreate_buffer();
+               }
                ++generation;
+       }
        dirty |= bits;
 }
 
@@ -647,15 +655,15 @@ vector<ProgramData::ProgramBlock>::const_iterator ProgramData::prepare_program(c
 
                prog_begin->masks.dirty = 0;
 
-               if(last_buffer_block!=old_last_block)
+               if(last_buffer_block!=old_last_block || (buffer && !buffer->get_size()))
                {
-                       unsigned required_size = last_buffer_block->get_required_buffer_size();
+                       unsigned required_size = last_buffer_block->get_required_buffer_size(streaming);
                        if(last_buffer_block->get_required_buffer_size()>buffer->get_size())
                        {
                                if(buffer->get_size()>0)
                                        recreate_buffer();
 
-                               buffer->storage(required_size, STREAMING);
+                               buffer->storage(required_size, (streaming ? STREAMING : STATIC));
                        }
                }
        }
index ac7a36ac8166eeeb7f3f7edea0a7f2c009ec8a50..dbbf5f488d6173e2b9436df925d81bdce2db8f16 100644 (file)
@@ -158,6 +158,7 @@ private:
        mutable std::vector<ProgramBlock> programs;
        mutable UniformBlock *last_buffer_block = 0;
        mutable Buffer *buffer = 0;
+       bool streaming = false;
        mutable Mask dirty = 0;
        std::string debug_name;