]> git.tdb.fi Git - libs/gl.git/blobdiff - source/mesh.cpp
Final touches of OS X support
[libs/gl.git] / source / mesh.cpp
index 67f9698cfa36468d5fb6955f49b5ce5774b95e0f..572ac6195502afc97259a45857d94998c666fa4d 100644 (file)
@@ -1,12 +1,4 @@
-/* $Id$
-
-This file is part of libmspgl
-Copyright © 2007-2011  Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
 #include "buffer.h"
-#include "extension.h"
 #include "mesh.h"
 #include "renderer.h"
 
@@ -70,29 +62,20 @@ float *Mesh::modify_vertex(unsigned i)
 
 void Mesh::add_batch(const Batch &b)
 {
-       bool can_append = false;
-       if(!batches.empty())
-       {
-               PrimitiveType type = b.get_type();
-               can_append = (type==batches.back().get_type() &&
-                       type!=LINE_STRIP && type!=LINE_LOOP && type!=POLYGON &&
-                       (type!=TRIANGLE_FAN || is_supported("GL_NV_primitive_restart")));
-       }
-
        if(defer_ibuf)
        {
                ibuf = new Buffer(ELEMENT_ARRAY_BUFFER);
                defer_ibuf = false;
        }
 
-       if(can_append)
+       if(!batches.empty() && batches.back().can_append(b.get_type()))
                batches.back().append(b);
        else
        {
                Batch *prev = (batches.empty() ? 0 : &batches.back());
                batches.push_back(b);
                if(ibuf)
-                       batches.back().use_index_buffer(ibuf, prev);
+                       batches.back().use_buffer(ibuf, prev);
        }
 }
 
@@ -124,6 +107,8 @@ void Mesh::draw(Renderer &renderer) const
 
        for(list<Batch>::const_iterator i=batches.begin(); i!=batches.end(); ++i)
                renderer.draw(*i);
+
+       renderer.set_winding_test(0);
 }
 
 
@@ -135,9 +120,15 @@ Mesh::Loader::Loader(Mesh &m):
        add("winding",  &Loader::winding);
 }
 
-void Mesh::Loader::vertices(VertexFormat f)
+void Mesh::Loader::vertices(const vector<VertexComponent> &c)
 {
-       obj.vertices.reset(f);
+       if(c.empty())
+               throw invalid_argument("No vertex components");
+
+       VertexFormat fmt;
+       for(vector<VertexComponent>::const_iterator i=c.begin(); i!=c.end(); ++i)
+               fmt = (fmt, *i);
+       obj.vertices.reset(fmt);
        load_sub(obj.vertices);
 }