From 74d247f8a160074d3b2f6873bb2abb1ad7b44853 Mon Sep 17 00:00:00 2001 From: Donovan Hutchence Date: Mon, 16 Oct 2023 17:45:42 +0100 Subject: [PATCH 1/2] use bufferSubData on subsequent data updates --- src/platform/graphics/webgl/webgl-buffer.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/platform/graphics/webgl/webgl-buffer.js b/src/platform/graphics/webgl/webgl-buffer.js index 7d54871a860..f04da2b2f94 100644 --- a/src/platform/graphics/webgl/webgl-buffer.js +++ b/src/platform/graphics/webgl/webgl-buffer.js @@ -26,10 +26,6 @@ class WebglBuffer { unlock(device, usage, target, storage) { const gl = device.gl; - if (!this.bufferId) { - this.bufferId = gl.createBuffer(); - } - let glUsage; switch (usage) { case BUFFER_STATIC: @@ -46,8 +42,19 @@ class WebglBuffer { break; } + const newBuffer = !this.bufferId; + + if (newBuffer) { + this.bufferId = gl.createBuffer(); + } + gl.bindBuffer(target, this.bufferId); - gl.bufferData(target, storage, glUsage); + + if (newBuffer) { + gl.bufferData(target, storage, glUsage); + } else { + gl.bufferSubData(target, 0, storage); + } } } From c0bd0257837c16f90594e914c5bf02c6b81bbfe5 Mon Sep 17 00:00:00 2001 From: Donovan Hutchence Date: Tue, 17 Oct 2023 09:10:45 +0100 Subject: [PATCH 2/2] small --- src/platform/graphics/webgl/webgl-buffer.js | 41 +++++++++------------ 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/src/platform/graphics/webgl/webgl-buffer.js b/src/platform/graphics/webgl/webgl-buffer.js index f04da2b2f94..b51a7995a98 100644 --- a/src/platform/graphics/webgl/webgl-buffer.js +++ b/src/platform/graphics/webgl/webgl-buffer.js @@ -26,33 +26,28 @@ class WebglBuffer { unlock(device, usage, target, storage) { const gl = device.gl; - 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; - } - - const newBuffer = !this.bufferId; + if (!this.bufferId) { + 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; + } - if (newBuffer) { this.bufferId = gl.createBuffer(); - } - - gl.bindBuffer(target, this.bufferId); - - if (newBuffer) { + gl.bindBuffer(target, this.bufferId); gl.bufferData(target, storage, glUsage); } else { + gl.bindBuffer(target, this.bufferId); gl.bufferSubData(target, 0, storage); } }