]> git.tdb.fi Git - libs/gl.git/blobdiff - source/programdata.cpp
Allow tying ProgramData to a Program for name-checking purposes
[libs/gl.git] / source / programdata.cpp
index f47fed76b156de63ee77a2121f8695091c618452..b69d7b062dd61af65164f94b65fc6fc41cceb90b 100644 (file)
@@ -14,7 +14,8 @@ using namespace std;
 namespace Msp {
 namespace GL {
 
-ProgramData::ProgramData():
+ProgramData::ProgramData(const Program *p):
+       tied_program(p),
        last_block(0),
        buffer(0),
        dirty(0)
@@ -22,6 +23,7 @@ ProgramData::ProgramData():
 
 // Blocks are intentionally left uncopied
 ProgramData::ProgramData(const ProgramData &other):
+       tied_program(0),
        uniform_slots(other.uniform_slots),
        uniforms(other.uniforms),
        last_block(0),
@@ -38,6 +40,8 @@ ProgramData &ProgramData::operator=(const ProgramData &other)
                delete *i;
        uniforms.clear();
 
+       tied_program = other.tied_program;
+
        uniform_slots = other.uniform_slots;
        for(vector<Uniform *>::const_iterator i=other.uniforms.begin(); i!=other.uniforms.end(); ++i)
                uniforms.push_back((*i)->clone());
@@ -64,10 +68,17 @@ ProgramData::~ProgramData()
 
 void ProgramData::uniform(const string &name, Uniform *uni)
 {
-       if(name[name.size()-1]==']')
+       try
+       {
+               if(tied_program)
+                       tied_program->get_uniform_info(name);
+               else if(name[name.size()-1]==']')
+                       throw invalid_argument("ProgramData::uniform");
+       }
+       catch(...)
        {
                delete uni;
-               throw invalid_argument("ProgramData::uniform");
+               throw;
        }
 
        SlotMap::iterator i = uniform_slots.find(name);