X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fmesh.cpp;h=413986f463d60180d50f8b0d37982256e7c43ac5;hp=c9819ae91c0e60dcec38f18febe5ffeb1747f94f;hb=8b99547d099c96bd8cc6037e2026db123b2523c1;hpb=1d24ddbc35f9e0480d30c66d47b7ea3834c15fbf diff --git a/source/mesh.cpp b/source/mesh.cpp index c9819ae9..413986f4 100644 --- a/source/mesh.cpp +++ b/source/mesh.cpp @@ -80,16 +80,18 @@ void Mesh::refresh() const { if(dirty&1) { - unbind(); for(list::const_iterator i=batches.begin(); i!=batches.end(); ++i) i->refresh(); } if(dirty&2) { - glBindVertexArray(vao_id); Bind bind_vbuf(vbuf, ARRAY_BUFFER); + bool bind_here = !current(); + if(bind_here) + glBindVertexArray(vao_id); + const VertexFormat &fmt = vertices.get_format(); unsigned stride = get_stride(fmt)*sizeof(float); float *ptr = 0; @@ -107,7 +109,9 @@ void Mesh::refresh() const ptr += sz; } glBindBuffer(ELEMENT_ARRAY_BUFFER, ibuf->get_id()); - glBindVertexArray(0); + + if(bind_here) + glBindVertexArray(0); } dirty = 0; @@ -184,16 +188,8 @@ void Mesh::bind() const called. Thus unbind won't try to call a null function either. */ if(!vao_id) unbind(); - else - { - if(Buffer::current(ELEMENT_ARRAY_BUFFER)) - { - unbind(); - Buffer::unbind_from(ELEMENT_ARRAY_BUFFER); - } - if(set_current(this)) - glBindVertexArray(vao_id); - } + else if(set_current(this)) + glBindVertexArray(vao_id); } void Mesh::unbind()