From 653b618e65b291a344abb1ee9d08dc5d1fde1094 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 22 Apr 2018 11:43:08 +0300 Subject: [PATCH] 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. --- source/programdata.cpp | 19 +++++++++++++++++++ source/programdata.h | 1 + 2 files changed, 20 insertions(+) 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; -- 2.43.0