X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fmesh.cpp;h=91dadeab00af09b584aaf1abad7b54333bbc7812;hb=61ff840cd211f10d45dca8c4dad2cca5f68aaa42;hp=26d660446b6c8c264c4fba19781069343282bdb6;hpb=9d6c244eb728336c64ee23d5c55e45c6696aa65c;p=libs%2Fgl.git diff --git a/source/mesh.cpp b/source/mesh.cpp index 26d66044..91dadeab 100644 --- a/source/mesh.cpp +++ b/source/mesh.cpp @@ -80,16 +80,17 @@ 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); - BufferAlias vbuf_alias(*vbuf); - Bind bind_vbuf(vbuf_alias); + 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); @@ -108,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; @@ -152,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 @@ -185,16 +181,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()