+#include <msp/core/maputils.h>
+#include <msp/gl/extensions/arb_direct_state_access.h>
#include "buffer.h"
#include "color.h"
#include "error.h"
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())
}
}
+void ProgramData::uniform(const string &name, const Uniform &u)
+{
+ uniform(name, u.clone());
+}
+
void ProgramData::uniform(const string &name, int v)
{
uniform(name, new Uniform1i(v));
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;
+ }
+}
+
+vector<string> ProgramData::get_uniform_names() const
+{
+ vector<string> names;
+ for(SlotMap::const_iterator i=uniform_slots.begin(); i!=uniform_slots.end(); ++i)
+ names.push_back(i->first);
+ return names;
+}
+
+const Uniform &ProgramData::get_uniform(const string &name) const
+{
+ return *uniforms[get_item(uniform_slots, name)];
+}
+
unsigned ProgramData::compute_slot_mask(const Program::UniformBlockInfo &block) const
{
unsigned mask = 0;
for(vector<const Program::UniformInfo *>::const_iterator i=block.uniforms.begin(); i!=block.uniforms.end(); ++i)
{
SlotMap::const_iterator j = uniform_slots.find((*i)->name);
+ /* TODO issue a warning (or even error?) either here or in update_block
+ if all uniforms for a buffer-backed block are not found */
if(j!=uniform_slots.end() && j->second<MASK_BITS)
mask |= 1<<j->second;
}
/* If any blocks stored in the buffer were updated, bind the buffer here
to avoid state thrashing. */
- if(buffered_blocks_updated)
+ if(buffered_blocks_updated && !ARB_direct_state_access)
buffer->bind();
}
ProgramData::ProgramBlock::ProgramBlock(int p, SharedBlock *b):
bind_point(p),
- block(b ? b->block : 0),
+ block((b && b->used) ? b->block : 0),
shared(b)
{ }