From 50a64a7fdf44bc9f380968fe4cfd13e4055fab95 Mon Sep 17 00:00:00 2001 From: Hugo Amnov Date: Mon, 1 Oct 2018 21:46:49 +0200 Subject: [PATCH] Fix webgl2 instancing bug (#1512) --- src/renderer_gl.cpp | 14 ++++++++++++++ src/renderer_gl.h | 1 + 2 files changed, 15 insertions(+) diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index c8164115a..a1b8ba285 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -4528,6 +4528,15 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); } } + void ProgramGL::unbindInstanceData() const + { + for(uint32_t ii = 0; 0xffff != m_instanceData[ii]; ++ii) + { + GLint loc = m_instanceData[ii]; + GL_CHECK(glDisableVertexAttribArray(loc)); + } + } + void IndexBufferGL::destroy() { GL_CHECK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0) ); @@ -7311,6 +7320,11 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); m_occlusionQuery.end(); } + if(isValid(draw.m_instanceDataBuffer)) + { + program.unbindInstanceData(); + } + statsNumPrimsSubmitted[primIndex] += numPrimsSubmitted; statsNumPrimsRendered[primIndex] += numPrimsRendered; statsNumInstances[primIndex] += numInstances; diff --git a/src/renderer_gl.h b/src/renderer_gl.h index 0c7849e72..b99cc2b81 100644 --- a/src/renderer_gl.h +++ b/src/renderer_gl.h @@ -1329,6 +1329,7 @@ namespace bgfx { namespace gl void destroy(); void init(); void bindInstanceData(uint32_t _stride, uint32_t _baseVertex = 0) const; + void unbindInstanceData() const; void bindAttributesBegin() {