]> git.tdb.fi Git - libs/gl.git/blobdiff - source/immediate.cpp
Move VertexFormat and VertexArrayBuilder to their own files
[libs/gl.git] / source / immediate.cpp
diff --git a/source/immediate.cpp b/source/immediate.cpp
new file mode 100644 (file)
index 0000000..f341397
--- /dev/null
@@ -0,0 +1,52 @@
+/* $Id$
+
+This file is part of libmspgl
+Copyright © 2007  Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
+#include "immediate.h"
+
+namespace Msp {
+namespace GL {
+
+Immediate::Immediate(VertexFormat f):
+       array(f),
+       in_batch(false),
+       n_vertices(0)
+{ }
+
+void Immediate::begin(PrimitiveType t)
+{
+       type=t;
+       in_batch=true;
+       n_vertices=0;
+       builder=array.modify();
+}
+
+void Immediate::end()
+{
+       builder=0;
+
+       array.apply();
+       glDrawArrays(type, 0, n_vertices);
+
+       array.clear();
+       in_batch=false;
+}
+
+void Immediate::vertex_(float x, float y, float z, float w)
+{
+       if(!in_batch)
+               throw InvalidState("Vertex specification not between begin and end");
+
+       builder->texcoord(ts, tt, tr,tq);
+       builder->color(cr, cg, cb, ca);
+       builder->normal(nx, ny, nz);
+       builder->vertex(x, y, z, w);
+
+       ++n_vertices;
+}
+
+} // namespace GL
+} // namespace Msp