X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fprogramdata.cpp;h=cd12c2ca47fbff99cdbfe2578d30ebbd0468d997;hp=f47fed76b156de63ee77a2121f8695091c618452;hb=56beca9d8b4f7b4edac81411d31e24df88e84ac3;hpb=653b618e65b291a344abb1ee9d08dc5d1fde1094 diff --git a/source/programdata.cpp b/source/programdata.cpp index f47fed76..cd12c2ca 100644 --- a/source/programdata.cpp +++ b/source/programdata.cpp @@ -1,3 +1,4 @@ +#include #include #include "buffer.h" #include "color.h" @@ -14,7 +15,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 +24,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 +41,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,10 +69,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); @@ -93,6 +105,11 @@ void ProgramData::uniform(const string &name, Uniform *uni) } } +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)); @@ -254,6 +271,16 @@ void ProgramData::uniform4_array(const string &name, unsigned n, const float *v) uniform(name, new UniformArray(n, v)); } +void ProgramData::uniform_matrix2_array(const string &name, unsigned n, const float *v) +{ + uniform(name, new UniformArray(n, v)); +} + +void ProgramData::uniform_matrix3_array(const string &name, unsigned n, const float *v) +{ + uniform(name, new UniformArray(n, v)); +} + void ProgramData::uniform_matrix4_array(const string &name, unsigned n, const float *v) { uniform(name, new UniformArray(n, v)); @@ -278,12 +305,27 @@ void ProgramData::remove_uniform(const string &name) } } +vector ProgramData::get_uniform_names() const +{ + vector 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_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->secondsecond; } @@ -423,7 +465,7 @@ ProgramData::ProgramBlock::ProgramBlock(): ProgramData::ProgramBlock::ProgramBlock(int p, SharedBlock *b): bind_point(p), - block(b ? b->block : 0), + block((b && b->used) ? b->block : 0), shared(b) { }