]> git.tdb.fi Git - libs/gl.git/commitdiff
Refactor ProgramData buffer (re)creation into a function
authorMikko Rasa <tdb@tdb.fi>
Sun, 19 Dec 2021 12:10:12 +0000 (14:10 +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 f6ad56aee13b6dc0ed740180c24e1a4b32dc57e8..0aebdcd9a5747aa9f823ceb2a5116e3e45182560 100644 (file)
@@ -502,6 +502,21 @@ vector<ProgramData::ProgramBlock>::iterator ProgramData::get_program(const Progr
        return programs.begin()+index;
 }
 
        return programs.begin()+index;
 }
 
+void ProgramData::recreate_buffer() const
+{
+       Buffer *old_buffer = buffer;
+       // Create the new buffer first to ensure it has a different address
+       buffer = new Buffer;
+       delete old_buffer;
+       if(last_buffer_block)
+               last_buffer_block->change_buffer(buffer);
+
+#ifdef DEBUG
+       if(!debug_name.empty())
+               buffer->set_debug_name(debug_name);
+#endif
+}
+
 void ProgramData::update_block_uniform_indices(SharedBlock &block, const ReflectData::UniformBlockInfo &info) const
 {
        uint8_t *indices = block.indices.values;
 void ProgramData::update_block_uniform_indices(SharedBlock &block, const ReflectData::UniformBlockInfo &info) const
 {
        uint8_t *indices = block.indices.values;
@@ -551,14 +566,7 @@ void ProgramData::update_block_uniform_indices(SharedBlock &block, const Reflect
                if(info.bind_point>=0)
                {
                        if(!buffer)
                if(info.bind_point>=0)
                {
                        if(!buffer)
-                       {
-                               buffer = new Buffer();
-
-#ifdef DEBUG
-                               if(!debug_name.empty())
-                                       buffer->set_debug_name(debug_name);
-#endif
-                       }
+                               recreate_buffer();
 
                        block.block->use_buffer(buffer, last_buffer_block);
                        last_buffer_block = block.block;
 
                        block.block->use_buffer(buffer, last_buffer_block);
                        last_buffer_block = block.block;
@@ -645,16 +653,7 @@ vector<ProgramData::ProgramBlock>::const_iterator ProgramData::prepare_program(c
                        if(last_buffer_block->get_required_buffer_size()>buffer->get_size())
                        {
                                if(buffer->get_size()>0)
                        if(last_buffer_block->get_required_buffer_size()>buffer->get_size())
                        {
                                if(buffer->get_size()>0)
-                               {
-                                       delete buffer;
-                                       buffer = new Buffer();
-                                       last_buffer_block->change_buffer(buffer);
-
-#ifdef DEBUG
-                                       if(!debug_name.empty())
-                                               buffer->set_debug_name(debug_name);
-#endif
-                               }
+                                       recreate_buffer();
 
                                buffer->storage(required_size, STREAMING);
                        }
 
                                buffer->storage(required_size, STREAMING);
                        }
index 5d674a38a2504f8360d338f5ac74b85f3545689e..ac7a36ac8166eeeb7f3f7edea0a7f2c009ec8a50 100644 (file)
@@ -251,6 +251,7 @@ public:
 private:
        int find_uniform_index(Tag) const;
        std::vector<ProgramBlock>::iterator get_program(const Program &) const;
 private:
        int find_uniform_index(Tag) const;
        std::vector<ProgramBlock>::iterator get_program(const Program &) const;
+       void recreate_buffer() const;
        void update_block_uniform_indices(SharedBlock &, const ReflectData::UniformBlockInfo &) const;
        void update_block(SharedBlock &, const ReflectData::UniformBlockInfo &) const;
 
        void update_block_uniform_indices(SharedBlock &, const ReflectData::UniformBlockInfo &) const;
        void update_block(SharedBlock &, const ReflectData::UniformBlockInfo &) const;