]> git.tdb.fi Git - libs/gl.git/commitdiff
Add a function to remove uniforms from ProgramData
authorMikko Rasa <tdb@tdb.fi>
Sun, 22 Apr 2018 08:43:08 +0000 (11:43 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 22 Apr 2018 08:47:50 +0000 (11:47 +0300)
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
source/programdata.h

index 8a10f59c0c73beb5d5406816b0d63987fb087558..f47fed76b156de63ee77a2121f8695091c618452 100644 (file)
@@ -259,6 +259,25 @@ void ProgramData::uniform_matrix4_array(const string &name, unsigned n, const fl
        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;
+       }
+}
+
 unsigned ProgramData::compute_slot_mask(const Program::UniformBlockInfo &block) const
 {
        unsigned mask = 0;
index e045c6fd10def72e59adfc92dc4586373a915361..78f7292647a97436fed9e4b28ed0bfa17280f4f0 100644 (file)
@@ -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;