]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/vertexsetup.cpp
Clear VertexSetup state when a Mesh is unloaded
[libs/gl.git] / source / core / vertexsetup.cpp
index 4b2e2a5f0e5b8d3ccfb1bb435772f58557c15efb..d9e9d0959ce907d804f9695cdefea6e29828c810 100644 (file)
@@ -210,6 +210,36 @@ void VertexSetup::unbind()
                glBindVertexArray(0);
 }
 
+void VertexSetup::unload()
+{
+       if(ARB_direct_state_access)
+       {
+               glVertexArrayVertexBuffer(id, 0, 0, 0, 0);
+               glVertexArrayVertexBuffer(id, 1, 0, 0, 0);
+               glVertexArrayElementBuffer(id, 0);
+       }
+       else
+       {
+               BindRestore _bind(*this);
+               Buffer::unbind_from(ARRAY_BUFFER);
+
+               unsigned mask = get_attribs(vertex_format)|get_attribs(inst_format);
+               for(unsigned i=0; mask; ++i, mask>>=1)
+                       if(mask&1)
+                       {
+                               glDisableVertexAttribArray(i);
+                               glVertexAttribPointer(i, 1, GL_FLOAT, false, 0, 0);
+                       }
+               glBindBuffer(ELEMENT_ARRAY_BUFFER, 0);
+       }
+
+       vertex_array = 0;
+       vertex_format = VertexFormat();
+       inst_array = 0;
+       inst_format = VertexFormat();
+       index_buffer = 0;
+}
+
 void VertexSetup::set_debug_name(const string &name)
 {
 #ifdef DEBUG