]> git.tdb.fi Git - libs/gl.git/blobdiff - source/programdata.cpp
Make all forms of Batch::append return a reference to itself
[libs/gl.git] / source / programdata.cpp
index 615da767fedefca62eebd06b68fce816aa166ad2..f47fed76b156de63ee77a2121f8695091c618452 100644 (file)
@@ -1,3 +1,4 @@
+#include <msp/gl/extensions/arb_direct_state_access.h>
 #include "buffer.h"
 #include "color.h"
 #include "error.h"
@@ -64,7 +65,10 @@ ProgramData::~ProgramData()
 void ProgramData::uniform(const string &name, Uniform *uni)
 {
        if(name[name.size()-1]==']')
+       {
+               delete uni;
                throw invalid_argument("ProgramData::uniform");
+       }
 
        SlotMap::iterator i = uniform_slots.find(name);
        if(i!=uniform_slots.end())
@@ -255,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;
@@ -375,7 +398,7 @@ void ProgramData::apply() const
 
                /* If any blocks stored in the buffer were updated, bind the buffer here
                to avoid state thrashing. */
-               if(buffered_blocks_updated)
+               if(buffered_blocks_updated && !ARB_direct_state_access)
                        buffer->bind();
        }