From: Mikko Rasa Date: Sun, 19 Dec 2021 12:10:12 +0000 (+0200) Subject: Refactor ProgramData buffer (re)creation into a function X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=3d60c98715b1a93ae3c7b007c18557e0c2c99fc7;p=libs%2Fgl.git Refactor ProgramData buffer (re)creation into a function --- diff --git a/source/render/programdata.cpp b/source/render/programdata.cpp index f6ad56ae..0aebdcd9 100644 --- a/source/render/programdata.cpp +++ b/source/render/programdata.cpp @@ -502,6 +502,21 @@ vector::iterator ProgramData::get_program(const Progr 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; @@ -551,14 +566,7 @@ void ProgramData::update_block_uniform_indices(SharedBlock &block, const Reflect 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; @@ -645,16 +653,7 @@ vector::const_iterator ProgramData::prepare_program(c 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); } diff --git a/source/render/programdata.h b/source/render/programdata.h index 5d674a38..ac7a36ac 100644 --- a/source/render/programdata.h +++ b/source/render/programdata.h @@ -251,6 +251,7 @@ public: private: int find_uniform_index(Tag) const; std::vector::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;