From: Mikko Rasa Date: Sun, 26 Aug 2012 10:09:44 +0000 (+0300) Subject: Get all blocks for the program before applying them X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=ab83db6f1e31d44ced585119a57fd10896e469cb;p=libs%2Fgl.git 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. --- 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);