From: Mikko Rasa Date: Thu, 30 Aug 2012 21:45:21 +0000 (+0300) Subject: Shuffle the members of VertexArray into a sensible order X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=b392a49f4079cd3db859f9eaa51f651115a09c1d;p=libs%2Fgl.git Shuffle the members of VertexArray into a sensible order --- diff --git a/source/vertexarray.cpp b/source/vertexarray.cpp index 13816a13..6e39930e 100644 --- a/source/vertexarray.cpp +++ b/source/vertexarray.cpp @@ -22,6 +22,27 @@ VertexArray::VertexArray(const VertexFormat &f): VertexArray::~VertexArray() { } +void VertexArray::reset(const VertexFormat &f) +{ + clear(); + format = f; + stride = get_stride(format); + + bool has_multitex = false; + bool has_gen_attrs = false; + for(const unsigned char *c=format.begin(); c!=format.end(); ++c) + { + if(*c>=TEXCOORD1+4 && *c=ATTRIB1) + has_gen_attrs = true; + } + if(has_multitex) + static Require _req(ARB_multitexture); + if(has_gen_attrs) + static Require _req(ARB_vertex_shader); +} + void VertexArray::use_vertex_buffer() { if(vbuf) @@ -40,35 +61,37 @@ void VertexArray::use_vertex_buffer(Buffer *b) dirty = true; } +void VertexArray::clear() +{ + data.clear(); +} + void VertexArray::reserve(unsigned n) { data.reserve(n*stride); } -void VertexArray::clear() +float *VertexArray::append() { - data.clear(); + data.insert(data.end(), stride, 0.0f); + set_dirty(); + return &*(data.end()-stride); } -void VertexArray::reset(const VertexFormat &f) +float *VertexArray::modify(unsigned i) { - clear(); - format = f; - stride = get_stride(format); + set_dirty(); + return &data[0]+i*stride; +} - bool has_multitex = false; - bool has_gen_attrs = false; - for(const unsigned char *c=format.begin(); c!=format.end(); ++c) +void VertexArray::set_dirty() +{ + dirty = true; + if(defer_vbuf) { - if(*c>=TEXCOORD1+4 && *c=ATTRIB1) - has_gen_attrs = true; + vbuf = new Buffer(ARRAY_BUFFER); + defer_vbuf = false; } - if(has_multitex) - static Require _req(ARB_multitexture); - if(has_gen_attrs) - static Require _req(ARB_vertex_shader); } void VertexArray::apply() const @@ -169,29 +192,6 @@ void VertexArray::apply() const Buffer::unbind_from(ARRAY_BUFFER); } -float *VertexArray::append() -{ - data.insert(data.end(), stride, 0.0f); - set_dirty(); - return &*(data.end()-stride); -} - -float *VertexArray::modify(unsigned i) -{ - set_dirty(); - return &data[0]+i*stride; -} - -void VertexArray::set_dirty() -{ - dirty = true; - if(defer_vbuf) - { - vbuf = new Buffer(ARRAY_BUFFER); - defer_vbuf = false; - } -} - VertexArray::ArrayMask::ArrayMask() { diff --git a/source/vertexarray.h b/source/vertexarray.h index 6be5616e..d8484d83 100644 --- a/source/vertexarray.h +++ b/source/vertexarray.h @@ -56,21 +56,25 @@ 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 reserve(unsigned); float *append(); float *modify(unsigned); - const float *operator[](unsigned i) const { return &data[0]+i*stride; } - 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; } + + void apply() const; }; } // namespace GL