From 08cfa89c0b9448a27b408051d0aa5201d476b72a Mon Sep 17 00:00:00 2001 From: Germano Cavalcante Date: Fri, 17 Feb 2023 09:08:51 -0300 Subject: [PATCH] Fix #104347: Loop Cut Tool becomes impressive with GPU Subdivision When updating a mesh, GPU Subdivision code makes calls to `GPU_indexbuf_bind_as_ssbo()`. The problem occurs when the index buffer of the current VAO is changed due to `GPU_indexbuf_bind_as_ssbo()` calls. The solution is to unbind the VAO (by calling `glBindVertexArray(0)`) before creating the index buffer IBO. --- source/blender/gpu/opengl/gl_index_buffer.cc | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/source/blender/gpu/opengl/gl_index_buffer.cc b/source/blender/gpu/opengl/gl_index_buffer.cc index 2125583cd6b..ca6ac5c19c8 100644 --- a/source/blender/gpu/opengl/gl_index_buffer.cc +++ b/source/blender/gpu/opengl/gl_index_buffer.cc @@ -41,7 +41,18 @@ void GLIndexBuf::bind() void GLIndexBuf::bind_as_ssbo(uint binding) { - bind(); + if (ibo_id_ == 0 || data_ != nullptr) { + /* Calling `glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo_id_)` changes the index buffer + * of the currently bound VAO. + * + * In the OpenGL backend, the VAO state persists even after `GLVertArray::update_bindings` + * is called. + * + * NOTE: For safety, we could call `glBindVertexArray(0)` right after drawing a `GPUBatch`. + * However, for performance reasons, we have chosen not to do so. */ + glBindVertexArray(0); + bind(); + } BLI_assert(ibo_id_ != 0); glBindBufferBase(GL_SHADER_STORAGE_BUFFER, binding, ibo_id_); } -- 2.30.2