]> git.tdb.fi Git - libs/gl.git/blobdiff - source/vertexarray.cpp
Check the flat qualifier from the correct member
[libs/gl.git] / source / vertexarray.cpp
diff --git a/source/vertexarray.cpp b/source/vertexarray.cpp
deleted file mode 100644 (file)
index c166e98..0000000
+++ /dev/null
@@ -1,171 +0,0 @@
-/* $Id$
-
-This file is part of libmspgl
-Copyright © 2007  Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
-#include "gl.h"
-#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<VertexFormat>(fmt&15));
-}
-
-VertexArray::~VertexArray()
-{
-       if(own_vbuf)
-               delete vbuf;
-}
-
-void VertexArray::use_vertex_buffer()
-{
-       if(vbuf && own_vbuf)
-               return;
-
-       vbuf=new VertexBuffer();
-       own_vbuf=true;
-
-       update_data();
-}
-
-void VertexArray::use_vertex_buffer(VertexBuffer *b)
-{
-       if(own_vbuf)
-               delete vbuf;
-       vbuf=b;
-       own_vbuf=false;
-
-       update_data();
-}
-
-void VertexArray::reserve(unsigned n)
-{
-       data.reserve(n*stride);
-}
-
-void VertexArray::clear()
-{
-       data.clear();
-}
-
-void VertexArray::reset(VertexFormat f)
-{
-       clear();
-       format=NODATA;
-       for(uint fmt=f; fmt; fmt>>=4)
-               format=(format, static_cast<VertexFormat>(fmt&15));
-       stride=get_stride(format);
-}
-
-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;
-       uint bpv=stride*sizeof(float);
-       for(uint fmt=format; fmt; fmt>>=4)
-       {
-               uint sz=(fmt&3)+1;
-               switch(fmt&12)
-               {
-               case 0:
-                       glVertexPointer(sz, GL_FLOAT, bpv, base+offset);
-                       break;
-               case 4:
-                       glNormalPointer(GL_FLOAT, bpv, base+offset);
-                       break;
-               case 8:
-                       glTexCoordPointer(sz, GL_FLOAT, bpv, base+offset);
-                       break;
-               case 12:
-                       if(sz==1)
-                               glColorPointer(4, GL_UNSIGNED_BYTE, bpv, base+offset);
-                       else
-                               glColorPointer(sz, GL_FLOAT, bpv, base+offset);
-                       break;
-               }
-               found|=1<<((fmt&12)>>2);
-               offset+=sz;
-       }
-
-       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);
-
-       if(vbuf)
-               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]);
-               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
-{
-       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)
-{
-       add("vertex2",   static_cast<void (Loader::*)(float, float)>(&Loader::vertex));
-       add("vertex3",   static_cast<void (Loader::*)(float, float, float)>(&Loader::vertex));
-       add("vertex4",   static_cast<void (Loader::*)(float, float, float, float)>(&Loader::vertex));
-       add("normal3",   static_cast<void (Loader::*)(float, float, float)>(&Loader::normal));
-       add("texcoord1", static_cast<void (Loader::*)(float)>(&Loader::texcoord));
-       add("texcoord2", static_cast<void (Loader::*)(float, float)>(&Loader::texcoord));
-       add("texcoord3", static_cast<void (Loader::*)(float, float, float)>(&Loader::texcoord));
-       add("texcoord4", static_cast<void (Loader::*)(float, float, float, float)>(&Loader::texcoord));
-       add("color3",    static_cast<void (Loader::*)(float, float, float)>(&Loader::color));
-       add("color4",    static_cast<void (Loader::*)(float, float, float, float)>(&Loader::color));
-}
-
-} // namespace GL
-} // namespace Msp