Skip to content

Commit

Permalink
fix(webgl): Bind index buffer before render.
Browse files Browse the repository at this point in the history
  • Loading branch information
donmccurdy committed Mar 13, 2024
1 parent c5c15fb commit dc275cc
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions modules/webgl/src/adapter/resources/webgl-vertex-array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ export class WEBGLVertexArray extends VertexArray {
/**
// Set (bind/unbind) an elements buffer, for indexed rendering.
// Must be a Buffer bound to GL.ELEMENT_ARRAY_BUFFER or null. Constants not supported
*
* @param elementBuffer
*
* @param elementBuffer
*/
setIndexBuffer(indexBuffer: Buffer | null): void {
const buffer = indexBuffer as WEBGLBuffer;
Expand Down Expand Up @@ -115,17 +115,10 @@ export class WEBGLVertexArray extends VertexArray {
this.attributes[location] = value;
}

init = false;

override bindBeforeRender(): void {
this.device.gl.bindVertexArray(this.handle);
// TODO - the initial bind does not seem to take effect.
if (!this.init) {
// log.log(1, `Binding vertex array ${this.id}`, this.indexBuffer?.id)();
const webglBuffer = this.indexBuffer as WEBGLBuffer;
this.device.gl.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, webglBuffer?.handle || null);
this.init = true;
}
const webglBuffer = this.indexBuffer as WEBGLBuffer;
this.device.gl.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, webglBuffer?.handle || null);
this._applyConstantAttributes();
}

Expand All @@ -134,7 +127,7 @@ export class WEBGLVertexArray extends VertexArray {
// TODO technically this is not necessary, but we might be interfacing
// with code that does not use vertex array objects
this.device.gl.bindVertexArray(null);
// this.device.gl.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, null);
this.device.gl.bindBuffer(GL.ELEMENT_ARRAY_BUFFER, null);
}

// Internal methods
Expand Down

0 comments on commit dc275cc

Please sign in to comment.