]> 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 f6f0f58b65397cabdba6f9cbdc42bf027503689d..d9e9d0959ce907d804f9695cdefea6e29828c810 100644 (file)
@@ -5,6 +5,7 @@
 #include <msp/gl/extensions/arb_vertex_attrib_binding.h>
 #include <msp/gl/extensions/arb_vertex_buffer_object.h>
 #include <msp/gl/extensions/arb_vertex_shader.h>
+#include <msp/gl/extensions/khr_debug.h>
 #include "buffer.h"
 #include "error.h"
 #include "gl.h"
@@ -209,5 +210,45 @@ 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
+       if(KHR_debug)
+               glObjectLabel(GL_VERTEX_ARRAY, id, name.size(), name.c_str());
+#else
+       (void)name;
+#endif
+}
+
 } // namespace GL
 } // namespace Msp