]> git.tdb.fi Git - libs/gl.git/commitdiff
Pass the UniformBlockInfo to get_block to avoid an unnecessary lookup
authorMikko Rasa <tdb@tdb.fi>
Sun, 26 Aug 2012 09:42:14 +0000 (12:42 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 26 Aug 2012 09:42:14 +0000 (12:42 +0300)
source/programdata.cpp
source/programdata.h

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);
 }
 
index 885804f010e16d868e7ab551caccb1b144824395..4d80bb775afc92f20c05714c998399909a2299a7 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <map>
 #include <msp/datafile/objectloader.h>
+#include "program.h"
 
 namespace Msp {
 namespace GL {
@@ -10,7 +11,6 @@ namespace GL {
 class Buffer;
 class Color;
 class Matrix;
-class Program;
 class Uniform;
 class UniformBlock;
 class Vector3;
@@ -81,6 +81,9 @@ public:
        void uniform4_array(const std::string &, unsigned, const float *);
        void uniform_matrix4_array(const std::string &, unsigned, const float *);
 
+private:
+       const UniformBlock &get_block(const Program &, const Program::UniformBlockInfo *) const;
+public:
        const UniformBlock &get_block(const Program &, const std::string &) const;
 
        void apply() const;