From: Mikko Rasa Date: Sat, 10 Apr 2021 20:07:19 +0000 (+0300) Subject: Use a vector for storage in DefaultUniformBlock X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=3af09f06e9f69532e5adfe6bcd9a7b2d1aea6d5b;p=libs%2Fgl.git Use a vector for storage in DefaultUniformBlock Uniform locations are normally spaced no more than 4 apart, so even with a few empty spots a vector is going to be more efficient than a map. --- diff --git a/source/core/uniformblock.cpp b/source/core/uniformblock.cpp index 25511d25..f114ea58 100644 --- a/source/core/uniformblock.cpp +++ b/source/core/uniformblock.cpp @@ -24,11 +24,16 @@ void DefaultUniformBlock::attach(const Program::UniformInfo &info, const Uniform if(info.block->bind_point>=0) throw invalid_argument("DefaultUniformBlock::attach"); - uniforms[info.location] = &uni; + attach(info.location, uni); } void DefaultUniformBlock::attach(int index, const Uniform &uni) { + if(index<0) + return; + + if(static_cast(index)>=uniforms.size()) + uniforms.resize(index+1, 0); uniforms[index] = &uni; } @@ -37,8 +42,9 @@ void DefaultUniformBlock::apply(int index) const if(index>=0) throw invalid_argument("DefaultUniformBlock::apply"); - for(map::const_iterator i=uniforms.begin(); i!=uniforms.end(); ++i) - i->second->apply(i->first); + for(unsigned i=0; iapply(i); } diff --git a/source/core/uniformblock.h b/source/core/uniformblock.h index 5a037edb..bc0b933b 100644 --- a/source/core/uniformblock.h +++ b/source/core/uniformblock.h @@ -35,7 +35,7 @@ with locations, as returned by Program::get_uniform_location. */ class DefaultUniformBlock: public UniformBlock { private: - std::map uniforms; + std::vector uniforms; public: DefaultUniformBlock();