From b152e4f63170e8ccd6c9fb9397964c628fb6efeb Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Tue, 21 Oct 2014 09:48:26 +0300 Subject: [PATCH] Disallow direct access to uniform array elements 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 | 2 +- source/program.cpp | 19 +++---------------- source/programdata.cpp | 3 +++ 3 files changed, 7 insertions(+), 17 deletions(-) diff --git a/source/bloom.cpp b/source/bloom.cpp index 5ffa82f6..a7157496 100644 --- a/source/bloom.cpp +++ b/source/bloom.cpp @@ -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) diff --git a/source/program.cpp b/source/program.cpp index f56beec7..30c73f33 100644 --- a/source/program.cpp +++ b/source/program.cpp @@ -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(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 && offsetsecond.size) - return i->second.location+offset; - } - } return -1; - } return i->second.block->bind_point<0 ? i->second.location : -1; } diff --git a/source/programdata.cpp b/source/programdata.cpp index 7705fac9..563ccfbb 100644 --- a/source/programdata.cpp +++ b/source/programdata.cpp @@ -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()) { -- 2.43.0