]> git.tdb.fi Git - libs/gl.git/commitdiff
Use a vector for storage in DefaultUniformBlock
authorMikko Rasa <tdb@tdb.fi>
Sat, 10 Apr 2021 20:07:19 +0000 (23:07 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 10 Apr 2021 20:07:19 +0000 (23:07 +0300)
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.

source/core/uniformblock.cpp
source/core/uniformblock.h

index 25511d251e2361e56b67285b86b7e8add1f14585..f114ea584d04b7ff35ef550348febd4f9c38585d 100644 (file)
@@ -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<unsigned>(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<int, const Uniform *>::const_iterator i=uniforms.begin(); i!=uniforms.end(); ++i)
-               i->second->apply(i->first);
+       for(unsigned i=0; i<uniforms.size(); ++i)
+               if(uniforms[i])
+                       uniforms[i]->apply(i);
 }
 
 
index 5a037edb4b5e53323e32bddf7a1fbf44f4353581..bc0b933b01666f3a8e4df77fb1e179f1a8123652 100644 (file)
@@ -35,7 +35,7 @@ with locations, as returned by Program::get_uniform_location. */
 class DefaultUniformBlock: public UniformBlock
 {
 private:
-       std::map<int, const Uniform *> uniforms;
+       std::vector<const Uniform *> uniforms;
 
 public:
        DefaultUniformBlock();