X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fbuffer.cpp;fp=source%2Fbuffer.cpp;h=9fa03c1242024184585618ff841b71d802fc1a46;hp=61670cf9d378245f9a96ddead7f0fcea32ffb584;hb=8b99547d099c96bd8cc6037e2026db123b2523c1;hpb=1d24ddbc35f9e0480d30c66d47b7ea3834c15fbf diff --git a/source/buffer.cpp b/source/buffer.cpp index 61670cf9..9fa03c12 100644 --- a/source/buffer.cpp +++ b/source/buffer.cpp @@ -65,13 +65,26 @@ void Buffer::bind_to(BufferType t) const { if(t!=type) require_buffer_type(t); - // Don't change the binding in a mesh's vertex array object - if(t==ELEMENT_ARRAY_BUFFER && Mesh::current()) - throw invalid_operation("Buffer::bind_to(ELEMENT_ARRAY_BUFFER)"); + if(t==ELEMENT_ARRAY_BUFFER) + if(const Mesh *m = Mesh::current()) + { + // Don't change the binding in a mesh's vertex array object + if(this==m->get_index_buffer()) + return; + throw invalid_operation("Buffer::bind_to(ELEMENT_ARRAY_BUFFER)"); + } if(set_current(t, this)) glBindBuffer(t, id); } +const Buffer *Buffer::current(BufferType t) +{ + if(t==ELEMENT_ARRAY_BUFFER) + if(const Mesh *m = Mesh::current()) + return m->get_index_buffer(); + return binding(t); +} + void Buffer::unbind_from(BufferType type) { if(type==ELEMENT_ARRAY_BUFFER && Mesh::current())