X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fvertexarray.h;h=af1817b18461893591bc72c001db80c1dd72c0ce;hb=99b3477d16295c9b90daa0a397bfc375dd3aac4d;hp=281996d457da92894c6a4eb58111564c81c0ef43;hpb=76e338af116120d93d082ad247591ec9adad9233;p=libs%2Fgl.git diff --git a/source/vertexarray.h b/source/vertexarray.h index 281996d4..af1817b1 100644 --- a/source/vertexarray.h +++ b/source/vertexarray.h @@ -1,18 +1,13 @@ -/* $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" @@ -21,7 +16,7 @@ namespace GL { class Buffer; -class VertexArray +class VertexArray: public Bindable { public: class Loader: public DataFile::Loader, public VertexArrayBuilder @@ -31,11 +26,20 @@ public: }; private: + struct Array + { + unsigned char component; + unsigned char offset; + + Array(); + }; + VertexFormat format; std::vector data; - uint stride; - Buffer *vbuf; - bool own_vbuf; + unsigned stride; + std::vector arrays; + Buffer *vbuf; + mutable bool dirty; VertexArray(const VertexArray &); VertexArray &operator=(const VertexArray &); @@ -43,41 +47,30 @@ public: VertexArray(const VertexFormat &); ~VertexArray(); + void reset(const VertexFormat &); const VertexFormat &get_format() const { return format; } - const std::vector &get_data() const { return data; } - void use_vertex_buffer(); - void use_vertex_buffer(Buffer *); - void reserve(unsigned); - unsigned size() const { return data.size()/stride; } - void clear(); - void reset(const VertexFormat &); - void apply() const; - void update_data(); - float *append(); - float *operator[](unsigned i) { return &data[0]+i*stride; } - const float *operator[](unsigned i) const { return &data[0]+i*stride; } private: - void set_array(unsigned, bool, unsigned) const; - - static unsigned enabled_arrays; -}; - -void array_element(int); -void draw_arrays(PrimitiveType, int, sizei); -void draw_elements(PrimitiveType, sizei, DataType, const void *); -void draw_range_elements(PrimitiveType, uint, uint, sizei, DataType, const void *); + static unsigned get_array_slot(unsigned char); -inline void draw_elements(PrimitiveType mode, sizei count, const unsigned *indices) -{ draw_elements(mode, count, UNSIGNED_INT, indices); } +public: + void use_vertex_buffer(Buffer *); -inline void draw_elements(PrimitiveType mode, sizei count, const unsigned short *indices) -{ draw_elements(mode, count, UNSIGNED_SHORT, indices); } + void clear(); + void reserve(unsigned); + float *append(); + float *modify(unsigned); +private: + void set_dirty(); -inline void draw_range_elements(PrimitiveType mode, uint low, uint high, sizei count, const unsigned short *indices) -{ draw_range_elements(mode, low, high, count, UNSIGNED_SHORT, indices); } +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; } -inline void draw_range_elements(PrimitiveType mode, uint low, uint high, sizei count, const unsigned *indices) -{ draw_range_elements(mode, low, high, count, UNSIGNED_INT, indices); } + void apply() const; +private: + static void apply_arrays(const std::vector *, const std::vector *, const float *, unsigned); +}; } // namespace GL } // namespace Msp