]> git.tdb.fi Git - libs/gl.git/blobdiff - source/programdata.cpp
Require all uniforms in a buffer-backed block to be present
[libs/gl.git] / source / programdata.cpp
index 68820c59cc9fd0fd829792ebf547190d23c0fe9f..912bc3c88a54c25a8c52199e8552a0d0a2b5eecc 100644 (file)
@@ -1,5 +1,7 @@
 #include <msp/core/maputils.h>
+#include <msp/debug/demangle.h>
 #include <msp/gl/extensions/arb_direct_state_access.h>
+#include <msp/io/print.h>
 #include "buffer.h"
 #include "color.h"
 #include "error.h"
@@ -92,10 +94,15 @@ void ProgramData::uniform(const string &name, Uniform *uni)
                else if(name[name.size()-1]==']')
                        throw invalid_argument("ProgramData::uniform");
        }
-       catch(...)
+       catch(const exception &e)
        {
                delete uni;
+#ifdef DEBUG
+               IO::print(IO::cerr, "Error while setting uniform %s: %s: %s\n", name, Debug::demangle(typeid(e).name()), e.what());
+               return;
+#else
                throw;
+#endif
        }
 
        int i = find_uniform_index(name);
@@ -482,12 +489,25 @@ ProgramData::SharedBlock *ProgramData::get_shared_block(const Program::UniformBl
        if(i==blocks.end())
        {
                bool any_found = false;
-               for(vector<const Program::UniformInfo *>::const_iterator j=info.uniforms.begin(); (!any_found && j!=info.uniforms.end()); ++j)
-                       any_found = (find_uniform_index((*j)->name)>=0);
+               bool all_found = true;
+               for(vector<const Program::UniformInfo *>::const_iterator j=info.uniforms.begin(); j!=info.uniforms.end(); ++j)
+               {
+                       if(find_uniform_index((*j)->name)>=0)
+                               any_found = true;
+                       else
+                               all_found = false;
+               }
 
-               // TODO throw if all uniforms for a buffer-backed block are not found
                if(!any_found)
                        return 0;
+               else if(!all_found && info.bind_point>=0)
+               {
+#ifdef DEBUG
+                       IO::print(IO::cerr, "Warning: not all uniforms for block %s are present\n", info.name);
+#else
+                       throw incomplete_uniform_block(info.name);
+#endif
+               }
 
                UniformBlock *block;
                if(info.bind_point>=0)