]> git.tdb.fi Git - libs/gl.git/commitdiff
Enforce unbinding as well as binding buffers
authorMikko Rasa <tdb@tdb.fi>
Sat, 21 Dec 2013 16:51:47 +0000 (18:51 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sat, 21 Dec 2013 16:51:47 +0000 (18:51 +0200)
source/batch.cpp
source/mesh.cpp
source/vertexarray.cpp

index 7f9adff7aad42ca8a9cb8e3bd4758ff2048acb75..7100653ea17800cf9ebd6364e6d5fba41443948b 100644 (file)
@@ -246,10 +246,10 @@ void Batch::draw() const
                restart_index = 0;
        }
 
-       if(Buffer *ibuf = get_buffer())
+       Buffer *ibuf = get_buffer();
+       BindRestore _bind_ibuf(ibuf, ELEMENT_ARRAY_BUFFER);
+       if(ibuf)
        {
-               BindRestore _bind_ibuf(ibuf, ELEMENT_ARRAY_BUFFER);
-
                if(dirty)
                        update_buffer();
 
index 413986f463d60180d50f8b0d37982256e7c43ac5..91dadeab00af09b584aaf1abad7b54333bbc7812 100644 (file)
@@ -155,19 +155,12 @@ void Mesh::draw() const
        refresh();
 
        if(!current())
-       {
                vertices.apply();
-               if(ibuf)
-                       ibuf->bind_to(ELEMENT_ARRAY_BUFFER);
-       }
-
+       Bind bind_ibuf(ibuf, ELEMENT_ARRAY_BUFFER);
        Bind bind_winding(winding);
 
        for(list<Batch>::const_iterator i=batches.begin(); i!=batches.end(); ++i)
                i->draw();
-
-       if(!current() && ibuf)
-               Buffer::unbind_from(ELEMENT_ARRAY_BUFFER);
 }
 
 void Mesh::draw(Renderer &renderer) const
index e8fa36a030bf5991a89bf4ed8f79944543ced413..72fd8a48ecddc802ec6a1bd0aa2cb985e3c9328a 100644 (file)
@@ -125,19 +125,13 @@ void VertexArray::apply() const
                return;
 
        Buffer *vbuf = get_buffer();
-       if(vbuf)
-       {
-               vbuf->bind_to(ARRAY_BUFFER);
-               if(dirty)
-                       update_buffer();
-       }
+       Bind _bind_vbuf(vbuf, ARRAY_BUFFER);
+       if(vbuf && dirty)
+               update_buffer();
 
        const float *base = (vbuf ? reinterpret_cast<float *>(get_offset()) : &data[0]);
        unsigned stride_bytes = stride*sizeof(float);
        apply_arrays(&arrays, (old ? &old->arrays : 0), base, stride_bytes);
-
-       if(vbuf)
-               Buffer::unbind_from(ARRAY_BUFFER);
 }
 
 void VertexArray::apply_arrays(const vector<Array> *arrays, const vector<Array> *old_arrays, const float *base, unsigned stride_bytes)