X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fvertexarray.cpp;h=3848109973c9dca9c8c49c830ebfa10e0285c6e9;hb=e720536d5feacf6136b5621c98b72d206e44f64c;hp=e453a3f12a569a70f7868288647dee37c6f45b33;hpb=cfd7b5bc0c69d0b8cc7c8b3ec81a1a9462d04abb;p=libs%2Fgl.git diff --git a/source/vertexarray.cpp b/source/vertexarray.cpp index e453a3f1..38481099 100644 --- a/source/vertexarray.cpp +++ b/source/vertexarray.cpp @@ -3,6 +3,7 @@ #include "buffer.h" #include "error.h" #include "gl.h" +#include "mesh.h" #include "vertexarray.h" using namespace std; @@ -10,8 +11,7 @@ using namespace std; namespace Msp { namespace GL { -VertexArray::VertexArray(const VertexFormat &f): - dirty(false) +VertexArray::VertexArray(const VertexFormat &f) { reset(f); } @@ -103,15 +103,13 @@ unsigned VertexArray::get_data_size() const return data.size()*sizeof(float); } -void VertexArray::upload_data() const -{ - get_buffer()->sub_data(get_offset(), get_data_size(), &data[0]); -} - void VertexArray::apply() const { if(format.empty()) throw invalid_operation("VertexArray::apply"); + // Don't mess up the vertex array object of a mesh + if(Mesh::current()) + throw invalid_operation("VertexArray::apply"); const VertexArray *old = current(); /* If the array has been modified, apply it even if it was the last one to @@ -122,19 +120,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)