From ab83db6f1e31d44ced585119a57fd10896e469cb Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 26 Aug 2012 13:09:44 +0300 Subject: [PATCH] Get all blocks for the program before applying them This way, the correct size for the buffer can be determined right away, rather than each block resizing it in turn. Binding the buffer before applying the blocks also avoids some thrashing. --- source/programdata.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/source/programdata.cpp b/source/programdata.cpp index 3e3f18db..e1b4212e 100644 --- a/source/programdata.cpp +++ b/source/programdata.cpp @@ -221,10 +221,21 @@ void ProgramData::apply() const throw invalid_operation("ProgramData::apply"); const Program::UniformBlockMap &prog_blocks = prog->get_uniform_blocks(); - for(Program::UniformBlockMap::const_iterator i=prog_blocks.begin(); i!=prog_blocks.end(); ++i) + if(!prog_blocks.empty()) { - const UniformBlock &block = get_block(*prog, &i->second); - block.apply(i->second.bind_point); + typedef pair ApplyBlock; + list apply_blocks; + for(Program::UniformBlockMap::const_iterator i=prog_blocks.begin(); i!=prog_blocks.end(); ++i) + { + const UniformBlock &block = get_block(*prog, &i->second); + apply_blocks.push_back(make_pair(&block, i->second.bind_point)); + } + + if(buffer) + buffer->bind(); + + for(list::const_iterator i=apply_blocks.begin(); i!=apply_blocks.end(); ++i) + i->first->apply(i->second); } const UniformBlock &block = get_block(*prog, 0); -- 2.43.0