X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fvertexarray.cpp;h=81a2acd5182a413777c39f0ebe944fe617b79b22;hb=b8b06a0ff96763ba7e188d9fcacbd8c0e3dcd515;hp=38d490c05e8758511da2d0a92a2fc7ef5ca0e29d;hpb=d1800d7ea80290f4913d0203241cef1409656522;p=libs%2Fgl.git diff --git a/source/vertexarray.cpp b/source/vertexarray.cpp index 38d490c0..81a2acd5 100644 --- a/source/vertexarray.cpp +++ b/source/vertexarray.cpp @@ -33,18 +33,22 @@ VertexArray::~VertexArray() void VertexArray::use_vertex_buffer() { - if(vbuf) return; + if(vbuf && own_vbuf) + return; vbuf=new VertexBuffer(); own_vbuf=true; + update_data(); } void VertexArray::use_vertex_buffer(VertexBuffer *b) { - if(vbuf) return; - + if(own_vbuf) + delete vbuf; vbuf=b; + own_vbuf=false; + update_data(); } @@ -69,7 +73,7 @@ void VertexArray::reset(VertexFormat f) RefPtr VertexArray::modify() { - return new VertexArrayBuilder(*this, data); + return new VertexArrayBuilder(*this); } void VertexArray::apply() const @@ -114,7 +118,8 @@ void VertexArray::apply() const set_array(GL_TEXTURE_COORD_ARRAY, found&4, 4); set_array(GL_COLOR_ARRAY, found&8, 8); - VertexBuffer::unbind(); + if(vbuf) + VertexBuffer::unbind(); } /** @@ -123,7 +128,10 @@ Updates the VertexArray data to the VertexBuffer tied to the array, if any. void VertexArray::update_data() { if(vbuf) + { vbuf->data(data.size()*sizeof(float), &data[0]); + VertexBuffer::unbind(); + } } void VertexArray::set_array(unsigned array, unsigned bit, unsigned mask) const @@ -144,7 +152,7 @@ unsigned VertexArray::enabled_arrays=0; VertexArray::Loader::Loader(VertexArray &a): - VertexArrayBuilder(a, a.data) + VertexArrayBuilder(a) { add("vertex2", static_cast(&Loader::vertex)); add("vertex3", static_cast(&Loader::vertex));