From 1b45b45f7d543ea677183bab5aaa9ff90b6576cf Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 25 Apr 2018 13:23:56 +0300 Subject: [PATCH] Allow tying ProgramData to a Program for name-checking purposes --- source/programdata.cpp | 17 ++++++++++++++--- source/programdata.h | 3 ++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/source/programdata.cpp b/source/programdata.cpp index f47fed76..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,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); diff --git a/source/programdata.h b/source/programdata.h index 78f72926..fe907d5c 100644 --- a/source/programdata.h +++ b/source/programdata.h @@ -123,6 +123,7 @@ private: typedef std::map ProgramMap; // XXX All these mutables are a bit silly, but I'm out of better ideas + const Program *tied_program; SlotMap uniform_slots; std::vector uniforms; mutable BlockMap blocks; @@ -132,7 +133,7 @@ private: mutable unsigned dirty; public: - ProgramData(); + ProgramData(const Program * = 0); ProgramData(const ProgramData &); ProgramData &operator=(const ProgramData &); ~ProgramData(); -- 2.43.0