]> git.tdb.fi Git - libs/gl.git/commitdiff
Disallow direct access to uniform array elements
authorMikko Rasa <tdb@tdb.fi>
Tue, 21 Oct 2014 06:48:26 +0000 (09:48 +0300)
committerMikko Rasa <tdb@tdb.fi>
Tue, 21 Oct 2014 06:48:26 +0000 (09:48 +0300)
ProgramData can't track them correctly, and adding the support would be
too complex.  Uploading the entire array at once is more efficient anyway.

source/bloom.cpp
source/program.cpp
source/programdata.cpp

index 5ffa82f673010713fa89bed65c5a0d406a559245..a715749608d45247cc1660b73de37044f75b4795 100644 (file)
@@ -88,7 +88,7 @@ void Bloom::set_radius(float r)
        for(int i=0; i<=size*2; ++i)
                factors[i] /= sum;
 
-       blur_shdata_common.uniform1_array("factors[0]", size*2+1, &factors.front());
+       blur_shdata_common.uniform1_array("factors", size*2+1, &factors.front());
 }
 
 void Bloom::set_strength(float s)
index f56beec73260b58a4eff644aacf4f8d89f4329e0..30c73f33631373c7043a66f20509b7cc09369ea6 100644 (file)
@@ -284,25 +284,12 @@ const Program::UniformInfo &Program::get_uniform_info(const string &name) const
 
 int Program::get_uniform_location(const string &n) const
 {
+       if(n[n.size()-1]==']')
+               throw invalid_argument("Program::get_uniform_location");
+
        UniformMap::const_iterator i = uniforms.find(n);
        if(i==uniforms.end())
-       {
-               if(n[n.size()-1]==']')
-               {
-                       string::size_type open_bracket = n.rfind('[');
-                       if(open_bracket!=string::npos)
-                       {
-                               /* The requested name looks like an array.  glGetActiveUniform only
-                               gives us the first element of the array, so try to look that up and
-                               add an offset. */
-                               unsigned offset = lexical_cast<unsigned>(n.substr(open_bracket+1, n.size()-2-open_bracket));
-                               i = uniforms.find(n.substr(0, open_bracket));
-                               if(i!=uniforms.end() && i->second.block->bind_point<0 && offset<i->second.size)
-                                       return i->second.location+offset;
-                       }
-               }
                return -1;
-       }
 
        return i->second.block->bind_point<0 ? i->second.location : -1;
 }
index 7705fac9786420bf47b5fc02edf088cd54b64ec5..563ccfbbbdb6bb79e69978f0745778732765d59f 100644 (file)
@@ -61,6 +61,9 @@ ProgramData::~ProgramData()
 
 void ProgramData::uniform(const string &name, Uniform *uni)
 {
+       if(name[name.size()-1]==']')
+               throw invalid_argument("ProgramData::uniform");
+
        SlotMap::iterator i = uniform_slots.find(name);
        if(i!=uniform_slots.end())
        {