]> git.tdb.fi Git - libs/gl.git/blobdiff - source/programdata.cpp
Make setting a nonexistent uniform only a warning in debug builds
[libs/gl.git] / source / programdata.cpp
index e279635f876116d1e40fce3064423e05c1e597c3..f454fe5145f595ed1cd6c62488c5b433aaba9a83 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"
@@ -34,6 +36,23 @@ ProgramData::ProgramData(const ProgramData &other):
                i->value = i->value->clone();
 }
 
+ProgramData::ProgramData(const ProgramData &other, const Program *p):
+       tied_program(p),
+       last_block(0),
+       buffer(0),
+       dirty(0)
+{
+       if(tied_program)
+       {
+               for(vector<NamedUniform>::const_iterator i=other.uniforms.begin(); i!=other.uniforms.end(); ++i)
+                       tied_program->get_uniform_info(i->name);
+       }
+
+       uniforms = other.uniforms;
+       for(vector<NamedUniform>::iterator i=uniforms.begin(); i!=uniforms.end(); ++i)
+               i->value = i->value->clone();
+}
+
 ProgramData &ProgramData::operator=(const ProgramData &other)
 {
        tied_program = other.tied_program;
@@ -75,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);
@@ -404,6 +428,12 @@ const Uniform &ProgramData::get_uniform(const string &name) const
        return *uniforms[i].value;
 }
 
+const Uniform *ProgramData::find_uniform(const string &name) const
+{
+       int i = find_uniform_index(name);
+       return (i>=0 ? uniforms[i].value : 0);
+}
+
 bool ProgramData::uniform_name_compare(const NamedUniform &nu, const string &name)
 {
        return nu.name<name;