X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fvertexarray.cpp;h=a4dffbb7bae4876af7c9535a1f965e8431b64f7b;hp=a2d3936c35f9532b3cc73087b24f9a5e19fe8a55;hb=HEAD;hpb=f71aee8c20ff85e4857e4dfad0c20ce606ea3717 diff --git a/source/vertexarray.cpp b/source/vertexarray.cpp deleted file mode 100644 index a2d3936c..00000000 --- a/source/vertexarray.cpp +++ /dev/null @@ -1,156 +0,0 @@ -/* $Id$ - -This file is part of libmspgl -Copyright © 2007 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - -#include -#include "vertexarray.h" -#include "vertexbuffer.h" - -using namespace std; - -namespace Msp { -namespace GL { - -VertexArray::VertexArray(VertexFormat f): - format(NODATA), - stride(get_stride(f)), - vbuf(0), - own_vbuf(false) -{ - // Reverse the format so the first item is in lowest bits. This makes handling in bind() easier. - for(uint fmt=f; fmt; fmt>>=4) - format=(format, static_cast(fmt&15)); -} - -VertexArray::~VertexArray() -{ - if(own_vbuf) - delete vbuf; -} - -void VertexArray::use_vertex_buffer() -{ - if(vbuf) return; - - vbuf=new VertexBuffer(); - own_vbuf=true; - update_data(); -} - -void VertexArray::use_vertex_buffer(VertexBuffer *b) -{ - if(vbuf) return; - - vbuf=b; - update_data(); -} - -void VertexArray::clear() -{ - data.clear(); -} - -void VertexArray::reset(VertexFormat f) -{ - clear(); - format=NODATA; - for(uint fmt=f; fmt; fmt>>=4) - format=(format, static_cast(fmt&15)); - stride=get_stride(format); -} - -RefPtr VertexArray::modify() -{ - return new VertexArrayBuilder(*this, data); -} - -void VertexArray::apply() const -{ - if(format==NODATA) - throw InvalidState("Trying to apply a vertex apply of format NODATA"); - - if(vbuf) - vbuf->bind(); - - const float *base=vbuf?0:&data[0]; - uint offset=0; - uint found=0; - for(uint fmt=format; fmt; fmt>>=4) - { - uint size=(fmt&3)+1; - switch(fmt&12) - { - case 0: - glVertexPointer(size, GL_FLOAT, stride, base+offset); - break; - case 4: - glNormalPointer(GL_FLOAT, stride, base+offset); - break; - case 8: - glTexCoordPointer(size, GL_FLOAT, stride, base+offset); - break; - case 12: - if(size==1) - glColorPointer(4, GL_UNSIGNED_BYTE, stride, base+offset); - else - glColorPointer(size, GL_FLOAT, stride, base+offset); - break; - } - found|=1<<((fmt&12)>>2); - offset+=size; - } - - set_array(GL_VERTEX_ARRAY, found&1, 1); - set_array(GL_NORMAL_ARRAY, found&2, 2); - set_array(GL_TEXTURE_COORD_ARRAY, found&4, 4); - set_array(GL_COLOR_ARRAY, found&8, 8); - - VertexBuffer::unbind(); -} - -/** -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]); -} - -void VertexArray::set_array(unsigned array, unsigned bit, unsigned mask) const -{ - if((enabled_arrays&mask) && !bit) - { - glDisableClientState(array); - enabled_arrays&=~mask; - } - else if(!(enabled_arrays&mask) && bit) - { - glEnableClientState(array); - enabled_arrays|=mask; - } -} - -unsigned VertexArray::enabled_arrays=0; - - -VertexArray::Loader::Loader(VertexArray &a): - VertexArrayBuilder(a, a.data) -{ - add("vertex2", static_cast(&Loader::vertex)); - add("vertex3", static_cast(&Loader::vertex)); - add("vertex4", static_cast(&Loader::vertex)); - add("normal3", static_cast(&Loader::normal)); - add("texcoord1", static_cast(&Loader::texcoord)); - add("texcoord2", static_cast(&Loader::texcoord)); - add("texcoord3", static_cast(&Loader::texcoord)); - add("texcoord4", static_cast(&Loader::texcoord)); - add("color3", static_cast(&Loader::color)); - add("color4", static_cast(&Loader::color)); -} - -} // namespace GL -} // namespace Msp