From: Mikko Rasa Date: Sat, 21 Dec 2013 16:51:47 +0000 (+0200) Subject: Enforce unbinding as well as binding buffers X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=commitdiff_plain;h=61ff840cd211f10d45dca8c4dad2cca5f68aaa42 Enforce unbinding as well as binding buffers --- diff --git a/source/batch.cpp b/source/batch.cpp index 7f9adff7..7100653e 100644 --- a/source/batch.cpp +++ b/source/batch.cpp @@ -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(); diff --git a/source/mesh.cpp b/source/mesh.cpp index 413986f4..91dadeab 100644 --- a/source/mesh.cpp +++ b/source/mesh.cpp @@ -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::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 diff --git a/source/vertexarray.cpp b/source/vertexarray.cpp index e8fa36a0..72fd8a48 100644 --- a/source/vertexarray.cpp +++ b/source/vertexarray.cpp @@ -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(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 *arrays, const vector *old_arrays, const float *base, unsigned stride_bytes)