Skip to content

Commit

Permalink
Clear VAO binding before binding index buffer.
Browse files Browse the repository at this point in the history
Fixes issue #5620.
  • Loading branch information
ChrisLoer committed Nov 8, 2017
1 parent 3f419f3 commit df1b00b
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/gl/index_buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,7 @@ class IndexBuffer {
this.buffer = gl.createBuffer();
this.dynamicDraw = Boolean(dynamicDraw);

// The bound index buffer is part of vertex array object state. We don't want to
// modify whatever VAO happens to be currently bound, so make sure the default
// vertex array provided by the context is bound instead.
if (gl.extVertexArrayObject === undefined) {
(gl: any).extVertexArrayObject = gl.getExtension("OES_vertex_array_object");
}
if (gl.extVertexArrayObject) {
(gl: any).extVertexArrayObject.bindVertexArrayOES(null);
}
this.unbindVAO();

gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.buffer);
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, array.arrayBuffer, this.dynamicDraw ? gl.DYNAMIC_DRAW : gl.STATIC_DRAW);
Expand All @@ -33,12 +25,27 @@ class IndexBuffer {
}
}

unbindVAO() {
// The bound index buffer is part of vertex array object state. We don't want to
// modify whatever VAO happens to be currently bound, so make sure the default
// vertex array provided by the context is bound instead.
if (this.gl.extVertexArrayObject === undefined) {
(this.gl: any).extVertexArrayObject = this.gl.getExtension("OES_vertex_array_object");
}
if (this.gl.extVertexArrayObject) {
(this.gl: any).extVertexArrayObject.bindVertexArrayOES(null);
}
}

bind() {
this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER, this.buffer);
}

updateData(array: SerializedStructArray) {
assert(this.dynamicDraw);
// The right VAO will get this buffer re-bound later in VertexArrayObject#bind
// See https://github.com/mapbox/mapbox-gl-js/issues/5620
this.unbindVAO();
this.bind();
this.gl.bufferSubData(this.gl.ELEMENT_ARRAY_BUFFER, 0, array.arrayBuffer);
}
Expand Down

0 comments on commit df1b00b

Please sign in to comment.