]> git.tdb.fi Git - libs/gl.git/commitdiff
Get all blocks for the program before applying them
authorMikko Rasa <tdb@tdb.fi>
Sun, 26 Aug 2012 10:09:44 +0000 (13:09 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 26 Aug 2012 10:22:53 +0000 (13:22 +0300)
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

index 3e3f18db0040d1b75423985a4c8ad064dc41696c..e1b4212e9d89588f78a42baf2d3e45d5a5a321db 100644 (file)
@@ -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<const UniformBlock *, unsigned> ApplyBlock;
+               list<ApplyBlock> 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<ApplyBlock>::const_iterator i=apply_blocks.begin(); i!=apply_blocks.end(); ++i)
+                       i->first->apply(i->second);
        }
 
        const UniformBlock &block = get_block(*prog, 0);