Skip to content

Commit

Permalink
Buffer update speedup (#5758)
Browse files Browse the repository at this point in the history
  • Loading branch information
slimbuck authored Oct 17, 2023
1 parent efdf9d0 commit d54b1df
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions src/platform/graphics/webgl/webgl-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,29 @@ class WebglBuffer {
const gl = device.gl;

if (!this.bufferId) {
this.bufferId = gl.createBuffer();
}
let glUsage;
switch (usage) {
case BUFFER_STATIC:
glUsage = gl.STATIC_DRAW;
break;
case BUFFER_DYNAMIC:
glUsage = gl.DYNAMIC_DRAW;
break;
case BUFFER_STREAM:
glUsage = gl.STREAM_DRAW;
break;
case BUFFER_GPUDYNAMIC:
glUsage = device.isWebGL2 ? gl.DYNAMIC_COPY : gl.STATIC_DRAW;
break;
}

let glUsage;
switch (usage) {
case BUFFER_STATIC:
glUsage = gl.STATIC_DRAW;
break;
case BUFFER_DYNAMIC:
glUsage = gl.DYNAMIC_DRAW;
break;
case BUFFER_STREAM:
glUsage = gl.STREAM_DRAW;
break;
case BUFFER_GPUDYNAMIC:
glUsage = device.isWebGL2 ? gl.DYNAMIC_COPY : gl.STATIC_DRAW;
break;
this.bufferId = gl.createBuffer();
gl.bindBuffer(target, this.bufferId);
gl.bufferData(target, storage, glUsage);
} else {
gl.bindBuffer(target, this.bufferId);
gl.bufferSubData(target, 0, storage);
}

gl.bindBuffer(target, this.bufferId);
gl.bufferData(target, storage, glUsage);
}
}

Expand Down

0 comments on commit d54b1df

Please sign in to comment.