From: Mikko Rasa Date: Sun, 28 Sep 2014 16:45:01 +0000 (+0300) Subject: Tighten checks in UniformBlock X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=b1c863c9e053f2250327a743cee92b98c39e1268;p=libs%2Fgl.git Tighten checks in UniformBlock A single UniformBlock can only be a default block or a named block, not any strange mixture of the two. --- diff --git a/source/uniformblock.cpp b/source/uniformblock.cpp index 09060eb7..be30ce5b 100644 --- a/source/uniformblock.cpp +++ b/source/uniformblock.cpp @@ -15,6 +15,7 @@ namespace Msp { namespace GL { UniformBlock::UniformBlock(): + size(0), buf_range(0) { static Require _req(ARB_shader_objects); @@ -22,10 +23,13 @@ UniformBlock::UniformBlock(): UniformBlock::UniformBlock(unsigned s): size(s), - data(size), buf_range(0) { static Require _req(ARB_uniform_buffer_object); + + if(!size) + throw invalid_argument("UniformBlock::UniformBlock"); + data.resize(size); } UniformBlock::~UniformBlock() @@ -57,26 +61,33 @@ void UniformBlock::upload_data(char *target) const void UniformBlock::attach(int index, const Uniform &uni) { + if(size) + throw invalid_operation("UniformBlock::attach"); + uniforms[index] = &uni; } void UniformBlock::attach(const Program::UniformInfo &info, const Uniform &uni) { - uniforms[info.location] = &uni; - if(get_buffer()) + if(size) { uni.store(info, &data[info.location]); dirty = true; } + else + uniforms[info.location] = &uni; } void UniformBlock::apply(int index) const { - if((index>=0) != (get_buffer()!=0)) + if((index>=0) != (size>0)) throw invalid_operation("UniformBlock::apply"); - if(get_buffer()) + if(size) { + if(!get_buffer()) + throw invalid_operation("UniformBlock::apply"); + if(dirty) update_buffer(); buf_range->bind_to(UNIFORM_BUFFER, index);