+void Mesh::draw_instanced(Renderer &renderer, const VertexSetup &vs, unsigned count) const
+{
+ if(vs.get_vertex_array()!=&vertices)
+ throw invalid_argument("Mesh::draw_instanced");
+
+ if(manager)
+ {
+ manager->resource_used(*this);
+ if(disallow_rendering)
+ return;
+ }
+
+ renderer.set_vertex_setup(&vs);
+ renderer.set_winding_test(winding);
+
+ for(vector<Batch>::const_iterator i=batches.begin(); i!=batches.end(); ++i)
+ renderer.draw_instanced(*i, count);
+}
+
+void Mesh::bind() const
+{
+ /* If VAOs are not supported, vtx_setup is zero and set_current won't get
+ called. Thus unbind won't try to call a null function either. */
+ if(!vtx_setup)
+ {
+ unbind();
+ vertices.apply(false);
+ }
+ else if(set_current(this))
+ {
+ vtx_setup->bind();
+ vertices.refresh();
+ }
+}
+
+void Mesh::unbind()
+{
+ if(set_current(0))
+ VertexSetup::unbind();
+}
+
+Resource::AsyncLoader *Mesh::load(IO::Seekable &io, const Resources *)
+{
+ return new AsyncLoader(*this, io);
+}
+
+UInt64 Mesh::get_data_size() const
+{
+ UInt64 size = 0;
+ if(vbuf)
+ size += vbuf->get_size();
+ if(ibuf)
+ size += ibuf->get_size();
+ return size;
+}
+
+void Mesh::unload()
+{
+ vertices.clear();
+ vertices.use_buffer(0);
+ batches.clear();
+ delete vbuf;
+ delete ibuf;
+ defer_buffers = (vbuf || ibuf);
+ vbuf = 0;
+ ibuf = 0;
+}
+