]> git.tdb.fi Git - libs/gl.git/blobdiff - source/programdata.cpp
Pass the UniformBlockInfo to get_block to avoid an unnecessary lookup
[libs/gl.git] / source / programdata.cpp
index 04fdd6b865053073435069696b968c5c90c48785..3e3f18db0040d1b75423985a4c8ad064dc41696c 100644 (file)
@@ -150,7 +150,7 @@ void ProgramData::uniform_matrix4_array(const string &name, unsigned n, const fl
        uniform(name, new UniformArray<UniformMatrix4x4f>(n, v));
 }
 
-const UniformBlock &ProgramData::get_block(const Program &prog, const string &name) const
+const UniformBlock &ProgramData::get_block(const Program &prog, const Program::UniformBlockInfo *info) const
 {
        if(modified)
        {
@@ -159,15 +159,7 @@ const UniformBlock &ProgramData::get_block(const Program &prog, const string &na
                modified = false;
        }
 
-       const Program::UniformBlockInfo *info = 0;
-       unsigned layout_hash;
-       if(!name.empty())
-       {
-               info = &prog.get_uniform_block_info(name);
-               layout_hash = info->layout_hash;
-       }
-       else
-               layout_hash = prog.get_uniform_layout_hash();
+       unsigned layout_hash = (info ? info->layout_hash : prog.get_uniform_layout_hash());
 
        map<unsigned, Block>::iterator i = blocks.find(layout_hash);
        if(i==blocks.end())
@@ -214,6 +206,14 @@ const UniformBlock &ProgramData::get_block(const Program &prog, const string &na
        return block;
 }
 
+const UniformBlock &ProgramData::get_block(const Program &prog, const string &name) const
+{
+       if(name.empty())
+               return get_block(prog, 0);
+       else
+               return get_block(prog, &prog.get_uniform_block_info(name));
+}
+
 void ProgramData::apply() const
 {
        const Program *prog = Program::current();
@@ -223,11 +223,11 @@ void ProgramData::apply() const
        const Program::UniformBlockMap &prog_blocks = prog->get_uniform_blocks();
        for(Program::UniformBlockMap::const_iterator i=prog_blocks.begin(); i!=prog_blocks.end(); ++i)
        {
-               const UniformBlock &block = get_block(*prog, i->second.name);
+               const UniformBlock &block = get_block(*prog, &i->second);
                block.apply(i->second.bind_point);
        }
 
-       const UniformBlock &block = get_block(*prog, string());
+       const UniformBlock &block = get_block(*prog, 0);
        block.apply(-1);
 }