]> git.tdb.fi Git - libs/gl.git/commitdiff
Clear VertexSetup state when a Mesh is unloaded
authorMikko Rasa <tdb@tdb.fi>
Thu, 13 May 2021 11:16:33 +0000 (14:16 +0300)
committerMikko Rasa <tdb@tdb.fi>
Thu, 13 May 2021 11:16:33 +0000 (14:16 +0300)
source/core/mesh.cpp
source/core/vertexsetup.cpp
source/core/vertexsetup.h

index f8135dc8c2ce5dcb7baee86238128aa3b78c8a34..f63b32933c64245f988004df8fbca9377d62541c 100644 (file)
@@ -216,6 +216,7 @@ void Mesh::unload()
        vertices.clear();
        vertices.use_buffer(0);
        batches.clear();
+       vtx_setup.unload();
        delete vbuf;
        delete ibuf;
        vbuf = 0;
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
index 06422a08c006b7953136a17ed4cbe218350d04ae..51183af52b64a1e3b9d521511a255215cb626955 100644 (file)
@@ -56,6 +56,8 @@ public:
        void bind() const;
        static void unbind();
 
+       void unload();
+
        void set_debug_name(const std::string &);
 };