From 8ff00c9663371684f69059a548f8a0addca10d5c Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 26 Aug 2012 12:42:14 +0300 Subject: [PATCH] Pass the UniformBlockInfo to get_block to avoid an unnecessary lookup --- source/programdata.cpp | 24 ++++++++++++------------ source/programdata.h | 5 ++++- 2 files changed, 16 insertions(+), 13 deletions(-) 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; -- 2.45.2