]> git.tdb.fi Git - libs/gl.git/commitdiff
Tighten checks in UniformBlock
authorMikko Rasa <tdb@tdb.fi>
Sun, 28 Sep 2014 16:45:01 +0000 (19:45 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 28 Sep 2014 16:45:01 +0000 (19:45 +0300)
A single UniformBlock can only be a default block or a named block, not
any strange mixture of the two.

source/uniformblock.cpp

index 09060eb7622ce36d9ddf158339411d89e9445d86..be30ce5b101420364b5bcba45722f00842e16099 100644 (file)
@@ -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);