X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fprogramdata.cpp;h=b69d7b062dd61af65164f94b65fc6fc41cceb90b;hp=01927063377b693b72c9ede4cabdb050ecd91067;hb=cfd4d36c2b6b6095ada3aef8082e5d409a233a21;hpb=08e19bc2b4eba572bc7699378cf55cd8772ac67e diff --git a/source/programdata.cpp b/source/programdata.cpp index 01927063..b69d7b06 100644 --- a/source/programdata.cpp +++ b/source/programdata.cpp @@ -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::const_iterator i=other.uniforms.begin(); i!=other.uniforms.end(); ++i) uniforms.push_back((*i)->clone()); @@ -64,8 +68,18 @@ ProgramData::~ProgramData() void ProgramData::uniform(const string &name, Uniform *uni) { - if(name[name.size()-1]==']') - throw invalid_argument("ProgramData::uniform"); + 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; + } SlotMap::iterator i = uniform_slots.find(name); if(i!=uniform_slots.end()) @@ -256,6 +270,25 @@ void ProgramData::uniform_matrix4_array(const string &name, unsigned n, const fl uniform(name, new UniformArray(n, v)); } +void ProgramData::remove_uniform(const string &name) +{ + SlotMap::iterator i = uniform_slots.find(name); + if(i!=uniform_slots.end()) + { + vector::iterator j = uniforms.begin()+i->second; + delete *j; + uniforms.erase(j); + + for(SlotMap::iterator k=uniform_slots.begin(); k!=uniform_slots.end(); ++k) + if(k->second>i->second) + --k->second; + + uniform_slots.erase(i); + + dirty = ALL_ONES; + } +} + unsigned ProgramData::compute_slot_mask(const Program::UniformBlockInfo &block) const { unsigned mask = 0;