X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fvertexarray.cpp;h=3c17141cfb59a592264505c7c67956cc5a9fd355;hb=dc1d1159a61f378bda11e5989ad694a86b9a3c77;hp=c0ca8dca80f22b96f1efdfe8f9de6ccd9dc04ffd;hpb=e92458a4a0e6191bff549a8b316dbbbd7c56e90f;p=libs%2Fgl.git diff --git a/source/vertexarray.cpp b/source/vertexarray.cpp index c0ca8dca..3c17141c 100644 --- a/source/vertexarray.cpp +++ b/source/vertexarray.cpp @@ -5,7 +5,9 @@ Copyright © 2007 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ +#include "extension.h" #include "gl.h" +#include "version_1_2.h" #include "vertexarray.h" #include "vertexbuffer.h" @@ -33,18 +35,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(); } @@ -67,11 +73,6 @@ void VertexArray::reset(VertexFormat f) stride=get_stride(format); } -RefPtr VertexArray::modify() -{ - return new VertexArrayBuilder(*this); -} - void VertexArray::apply() const { if(format==NODATA) @@ -114,7 +115,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 +125,16 @@ 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(); + } +} + +float *VertexArray::append() +{ + data.insert(data.end(), stride, 0.0f); + return &*data.end()-stride; } void VertexArray::set_array(unsigned array, unsigned bit, unsigned mask) const @@ -158,5 +169,27 @@ VertexArray::Loader::Loader(VertexArray &a): add("color4", static_cast(&Loader::color)); } + +void array_element(int i) +{ + glArrayElement(i); +} + +void draw_arrays(PrimitiveType mode, int first, sizei count) +{ + glDrawArrays(mode, first, count); +} + +void draw_elements(PrimitiveType mode, sizei count, DataType type, const void *indices) +{ + glDrawElements(mode, count, type, indices); +} + +void draw_range_elements(PrimitiveType mode, uint low, uint high, sizei count, DataType type, const void *indices) +{ + static RequireVersion _ver(1, 2); + glDrawRangeElements(mode, low, high, count, type, indices); +} + } // namespace GL } // namespace Msp