X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fimmediate.cpp;h=cf1be08ed7204209d0d572b851ce76b7c58469ff;hp=f341397492a7a2b92d5673685ccb790e9cbeb44c;hb=8bc776f177c7cf9d0c6fd9590273f086d38c23ca;hpb=85facfb688035b5bbc9a3a87d080582fbf34930b diff --git a/source/immediate.cpp b/source/immediate.cpp index f3413974..cf1be08e 100644 --- a/source/immediate.cpp +++ b/source/immediate.cpp @@ -1,51 +1,41 @@ -/* $Id$ - -This file is part of libmspgl -Copyright © 2007 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - +#include "batch.h" +#include "error.h" #include "immediate.h" namespace Msp { namespace GL { Immediate::Immediate(VertexFormat f): - array(f), - in_batch(false), - n_vertices(0) -{ } - -void Immediate::begin(PrimitiveType t) + PrimitiveBuilder(array), + array(f) { - type=t; - in_batch=true; - n_vertices=0; - builder=array.modify(); + array.use_buffer(0); } -void Immediate::end() +void Immediate::reset() { - builder=0; - - array.apply(); - glDrawArrays(type, 0, n_vertices); + if(in_batch) + throw invalid_operation("Immediate::reset"); array.clear(); - in_batch=false; } -void Immediate::vertex_(float x, float y, float z, float w) +void Immediate::begin_() { - if(!in_batch) - throw InvalidState("Vertex specification not between begin and end"); + indices.clear(); +} - builder->texcoord(ts, tt, tr,tq); - builder->color(cr, cg, cb, ca); - builder->normal(nx, ny, nz); - builder->vertex(x, y, z, w); +void Immediate::end_() +{ + Batch batch(type); + batch.append(indices); + array.apply(); + batch.draw(); +} - ++n_vertices; +void Immediate::element_(unsigned i) +{ + indices.push_back(i); } } // namespace GL