]> git.tdb.fi Git - libs/gl.git/blobdiff - source/vertexarray.cpp
Shuffle the members of VertexArray into a sensible order
[libs/gl.git] / source / vertexarray.cpp
index 13816a13fc04caf572559d592cd91ad2fe3ccdd0..6e39930ea8db95792b0d9a5ae865d94d91c377a1 100644 (file)
@@ -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_multitex = true;
+               if(*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_multitex = true;
-               if(*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()
 {