+{
+ if(current()==this)
+ {
+ /* We must deactivate arrays here, or apply() would try to access deleted
+ data on the next invocation. */
+ set_current(0);
+ apply_arrays(0, &arrays, 0, 0);
+ }
+}
+
+void VertexArray::reset(const VertexFormat &f)
+{
+ clear();
+ format = f;
+ stride = get_stride(format);
+
+ arrays.clear();
+
+ unsigned offset = 0;
+ for(const unsigned char *c=format.begin(); c!=format.end(); ++c)
+ {
+ unsigned slot = get_array_slot(*c);
+ if(slot>=arrays.size())
+ arrays.resize(slot+1);
+
+ Array &arr = arrays[slot];
+ arr.component = *c;
+ arr.offset = offset;
+
+ offset += get_component_size(*c);
+ }
+}
+
+unsigned VertexArray::get_array_slot(unsigned char comp)
+{
+ unsigned t = get_component_type(comp);
+ if(t==get_component_type(VERTEX3))
+ return 0;
+ else if(t==get_component_type(NORMAL3))
+ return 1;
+ else if(t==get_component_type(COLOR4_FLOAT))
+ return 2;
+ else if(comp>=TEXCOORD1 && comp<=TEXCOORD4+12)
+ {
+ t -= get_component_type(TEXCOORD1);
+ if(t>0)
+ static Require _req(ARB_multitexture);
+ return 3+t;
+ }
+ else
+ {
+ static Require _req(ARB_vertex_shader);
+ if(comp>=ATTRIB1)
+ t -= get_component_type(ATTRIB1);
+ return 7+t;
+ }
+}