X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fvertexarray.h;h=26204b312134e4bc1c5ebf2ebe845c19ff205304;hb=b35ae038dd9d7456a207ecb30eb8960a00bbe71d;hp=b1b5fdee58baa672a6a45080e9909cc3ab0696b2;hpb=d1800d7ea80290f4913d0203241cef1409656522;p=libs%2Fgl.git diff --git a/source/vertexarray.h b/source/vertexarray.h index b1b5fdee..26204b31 100644 --- a/source/vertexarray.h +++ b/source/vertexarray.h @@ -1,27 +1,22 @@ -/* $Id$ - -This file is part of libmspgl -Copyright © 2007 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - #ifndef MSP_GL_VERTEXARRAY_H_ #define MSP_GL_VERTEXARRAY_H_ +#include #include #include #include +#include "bindable.h" +#include "datatype.h" #include "primitivetype.h" -#include "types.h" #include "vertexarraybuilder.h" #include "vertexformat.h" namespace Msp { namespace GL { -class VertexBuffer; +class Buffer; -class VertexArray +class VertexArray: public Bindable { public: class Loader: public DataFile::Loader, public VertexArrayBuilder @@ -30,32 +25,43 @@ public: Loader(VertexArray &); }; - VertexArray(VertexFormat); - ~VertexArray(); - - VertexFormat get_format() const { return format; } - const std::vector &get_data() const { return data; } - void use_vertex_buffer(); - void use_vertex_buffer(VertexBuffer *); - void reserve(unsigned); - unsigned size() const { return data.size()/stride; } - void clear(); - void reset(VertexFormat); - RefPtr modify(); - void apply() const; - void update_data(); private: VertexFormat format; std::vector data; - uint stride; - VertexBuffer *vbuf; - bool own_vbuf; + unsigned stride; + std::vector arrays; + RefPtr vbuf; + bool defer_vbuf; + mutable bool dirty; VertexArray(const VertexArray &); VertexArray &operator=(const VertexArray &); - void set_array(unsigned, unsigned, unsigned) const; +public: + VertexArray(const VertexFormat &); + ~VertexArray(); + + void reset(const VertexFormat &); + const VertexFormat &get_format() const { return format; } +private: + static unsigned get_array_slot(unsigned char); + +public: + void use_vertex_buffer(); + void use_vertex_buffer(Buffer *); + + void clear(); + void reserve(unsigned); + float *append(); + float *modify(unsigned); +private: + void set_dirty(); + +public: + unsigned size() const { return data.size()/stride; } + const std::vector &get_data() const { return data; } + const float *operator[](unsigned i) const { return &data[0]+i*stride; } - static unsigned enabled_arrays; + void apply() const; }; } // namespace GL