namespace Msp {
namespace GL {
-ProgramData::ProgramData():
+ProgramData::ProgramData(const Program *p):
+ tied_program(p),
last_block(0),
buffer(0),
dirty(0)
// Blocks are intentionally left uncopied
ProgramData::ProgramData(const ProgramData &other):
+ tied_program(0),
uniform_slots(other.uniform_slots),
uniforms(other.uniforms),
last_block(0),
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());
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())
uniform(name, new UniformArray<UniformMatrix4x4f>(n, v));
}
+void ProgramData::remove_uniform(const string &name)
+{
+ SlotMap::iterator i = uniform_slots.find(name);
+ if(i!=uniform_slots.end())
+ {
+ vector<Uniform *>::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;