From: Mikko Rasa Date: Sun, 22 Apr 2018 08:43:08 +0000 (+0300) Subject: Add a function to remove uniforms from ProgramData X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=653b618e65b291a344abb1ee9d08dc5d1fde1094;p=libs%2Fgl.git Add a function to remove uniforms from ProgramData It may be beneficial to revert to a Technique's default value and its associated buffers instead of explicitly setting the same value in an ObjectInstance's private ProgramData. --- diff --git a/source/programdata.cpp b/source/programdata.cpp index 8a10f59c..f47fed76 100644 --- a/source/programdata.cpp +++ b/source/programdata.cpp @@ -259,6 +259,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; diff --git a/source/programdata.h b/source/programdata.h index e045c6fd..78f72926 100644 --- a/source/programdata.h +++ b/source/programdata.h @@ -172,6 +172,7 @@ public: void uniform4_array(const std::string &, unsigned, const int *); void uniform4_array(const std::string &, unsigned, const float *); void uniform_matrix4_array(const std::string &, unsigned, const float *); + void remove_uniform(const std::string &); private: unsigned compute_slot_mask(const Program::UniformBlockInfo &) const;