From: Mikko Rasa Date: Sun, 26 Aug 2012 09:42:14 +0000 (+0300) Subject: Pass the UniformBlockInfo to get_block to avoid an unnecessary lookup X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=8ff00c9663371684f69059a548f8a0addca10d5c;p=libs%2Fgl.git Pass the UniformBlockInfo to get_block to avoid an unnecessary lookup --- diff --git a/source/programdata.cpp b/source/programdata.cpp index 04fdd6b8..3e3f18db 100644 --- a/source/programdata.cpp +++ b/source/programdata.cpp @@ -150,7 +150,7 @@ void ProgramData::uniform_matrix4_array(const string &name, unsigned n, const fl uniform(name, new UniformArray(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::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); } diff --git a/source/programdata.h b/source/programdata.h index 885804f0..4d80bb77 100644 --- a/source/programdata.h +++ b/source/programdata.h @@ -3,6 +3,7 @@ #include #include +#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;