]> git.tdb.fi Git - libs/gl.git/blobdiff - source/vertexformat.cpp
Add a tool to convert a mesh into C code
[libs/gl.git] / source / vertexformat.cpp
index 91084bcc273e0bff6524746b22372a10d7b88eee..457cffad2724548cc31577fc0267e2c368ec421b 100644 (file)
@@ -1,7 +1,7 @@
 /* $Id$
 
 This file is part of libmspgl
-Copyright © 2007-2009  Mikko Rasa, Mikkosoft Productions
+Copyright © 2007-2010  Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
 
@@ -10,6 +10,8 @@ Distributed under the LGPL
 #include "except.h"
 #include "vertexformat.h"
 
+using namespace std;
+
 namespace Msp {
 namespace GL {
 
@@ -53,6 +55,14 @@ VertexFormat::~VertexFormat()
        delete[] data;
 }
 
+unsigned VertexFormat::stride() const
+{
+       uint s=0;
+       for(const unsigned char *i=begin(); i!=end(); ++i)
+               s+=(*i&3)+1;
+       return s;
+}
+
 VertexFormat operator,(const VertexFormat &f, VertexComponent c)
 {
        VertexFormat r=f;
@@ -94,24 +104,16 @@ VertexFormat operator,(const VertexFormat &f, unsigned i)
        return r;
 }
 
-uint get_stride(const VertexFormat &f)
-{
-       uint stride=0;
-       for(const unsigned char *i=f.begin(); i!=f.end(); ++i)
-               stride+=(*i&3)+1;
-       return stride;
-}
-
-std::istream &operator>>(std::istream &in, VertexFormat &f)
+istream &operator>>(istream &in, VertexFormat &f)
 {
-       std::string str;
+       string str;
        in>>str;
 
        unsigned start=0;
 
        while(1)
        {
-               unsigned underscore=str.find('_', start);
+               string::size_type underscore=str.find('_', start);
                bool fail=false;
                if(!str.compare(start, underscore-start, "VERTEX2"))
                        f=(f,VERTEX2);
@@ -162,11 +164,11 @@ std::istream &operator>>(std::istream &in, VertexFormat &f)
 
                if(fail)
                {
-                       in.setstate(std::ios_base::failbit);
+                       in.setstate(ios_base::failbit);
                        break;
                }
 
-               if(underscore==std::string::npos)
+               if(underscore==string::npos)
                        break;
                start=underscore+1;
        }