Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(webgl): Pair calls to bind/unbind VAO #2032

Merged
merged 2 commits into from Mar 13, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 5 additions & 12 deletions modules/webgl/src/adapter/resources/webgl-vertex-array.ts
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