From 763c53eb55eda9928b5cb6318e8061d77b2c8113 Mon Sep 17 00:00:00 2001 From: Garrett Johnson Date: Fri, 17 Nov 2023 19:07:16 +0900 Subject: [PATCH] WebGPURenderer: Add "updateRanges" support for WebGLAttributeUtils (#27149) * Add "updateRanges" support for WebGLAttributeUtils * Fix failed test --- .../webgl/utils/WebGLAttributeUtils.js | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/examples/jsm/renderers/webgl/utils/WebGLAttributeUtils.js b/examples/jsm/renderers/webgl/utils/WebGLAttributeUtils.js index 7372b3dfe7b20d..8cdee5b2cb7630 100644 --- a/examples/jsm/renderers/webgl/utils/WebGLAttributeUtils.js +++ b/examples/jsm/renderers/webgl/utils/WebGLAttributeUtils.js @@ -105,9 +105,30 @@ class WebGLAttributeUtils { const bufferAttribute = attribute.isInterleavedBufferAttribute ? attribute.data : attribute; const bufferData = backend.get( bufferAttribute ); const bufferType = bufferData.bufferType; + const updateRanges = attribute.isInterleavedBufferAttribute ? attribute.data.updateRanges : attribute.updateRanges; gl.bindBuffer( bufferType, bufferData.bufferGPU ); - gl.bufferSubData( bufferType, 0, array ); + + if ( updateRanges.length === 0 ) { + + // Not using update ranges + + gl.bufferSubData( bufferType, 0, array ); + + } else { + + for ( let i = 0, l = updateRanges.length; i < l; i ++ ) { + + const range = updateRanges[ i ]; + gl.bufferSubData( bufferType, range.start * array.BYTES_PER_ELEMENT, + array, range.start, range.count ); + + } + + bufferAttribute.clearUpdateRanges(); + + } + gl.bindBuffer( bufferType, null ); bufferData.version = bufferAttribute.version;