From: Mikko Rasa Date: Thu, 13 May 2021 11:16:33 +0000 (+0300) Subject: Clear VertexSetup state when a Mesh is unloaded X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=a5a26e4e2eb2d0b05c3531b667411be657ac74f1;p=libs%2Fgl.git Clear VertexSetup state when a Mesh is unloaded --- diff --git a/source/core/mesh.cpp b/source/core/mesh.cpp index f8135dc8..f63b3293 100644 --- a/source/core/mesh.cpp +++ b/source/core/mesh.cpp @@ -216,6 +216,7 @@ void Mesh::unload() vertices.clear(); vertices.use_buffer(0); batches.clear(); + vtx_setup.unload(); delete vbuf; delete ibuf; vbuf = 0; diff --git a/source/core/vertexsetup.cpp b/source/core/vertexsetup.cpp index 4b2e2a5f..d9e9d095 100644 --- a/source/core/vertexsetup.cpp +++ b/source/core/vertexsetup.cpp @@ -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 diff --git a/source/core/vertexsetup.h b/source/core/vertexsetup.h index 06422a08..51183af5 100644 --- a/source/core/vertexsetup.h +++ b/source/core/vertexsetup.h @@ -56,6 +56,8 @@ public: void bind() const; static void unbind(); + void unload(); + void set_debug_name(const std::string &); };