diff --git a/packages/dev/core/src/Engines/Extensions/engine.dynamicBuffer.ts b/packages/dev/core/src/Engines/Extensions/engine.dynamicBuffer.ts index 431995cb8fb..0dad1b254ca 100644 --- a/packages/dev/core/src/Engines/Extensions/engine.dynamicBuffer.ts +++ b/packages/dev/core/src/Engines/Extensions/engine.dynamicBuffer.ts @@ -28,15 +28,17 @@ ThinEngine.prototype.updateDynamicIndexBuffer = function (this: ThinEngine, inde // Force cache update this._currentBoundBuffer[this._gl.ELEMENT_ARRAY_BUFFER] = null; this.bindIndexBuffer(indexBuffer); - let arrayBuffer; - if (indices instanceof Uint16Array || indices instanceof Uint32Array) { - arrayBuffer = indices; + let view: ArrayBufferView; + if (indexBuffer.is32Bits) { + // anything else than Uint32Array needs to be converted to Uint32Array + view = indices instanceof Uint32Array ? indices : new Uint32Array(indices); } else { - arrayBuffer = indexBuffer.is32Bits ? new Uint32Array(indices) : new Uint16Array(indices); + // anything else than Uint16Array needs to be converted to Uint16Array + view = indices instanceof Uint16Array ? indices : new Uint16Array(indices); } - this._gl.bufferData(this._gl.ELEMENT_ARRAY_BUFFER, arrayBuffer, this._gl.DYNAMIC_DRAW); + this._gl.bufferData(this._gl.ELEMENT_ARRAY_BUFFER, view, this._gl.DYNAMIC_DRAW); this._resetIndexBufferBinding(); }; diff --git a/packages/dev/core/src/Engines/WebGPU/Extensions/engine.dynamicBuffer.ts b/packages/dev/core/src/Engines/WebGPU/Extensions/engine.dynamicBuffer.ts index bc194796c40..a504a7f2077 100644 --- a/packages/dev/core/src/Engines/WebGPU/Extensions/engine.dynamicBuffer.ts +++ b/packages/dev/core/src/Engines/WebGPU/Extensions/engine.dynamicBuffer.ts @@ -7,24 +7,10 @@ WebGPUEngine.prototype.updateDynamicIndexBuffer = function (indexBuffer: DataBuf const gpuBuffer = indexBuffer as WebGPUDataBuffer; let view: ArrayBufferView; - if (indices instanceof Uint16Array) { - if (indexBuffer.is32Bits) { - view = Uint32Array.from(indices); - } else { - view = indices; - } - } else if (indices instanceof Uint32Array) { - if (indexBuffer.is32Bits) { - view = indices; - } else { - view = Uint16Array.from(indices); - } + if (indexBuffer.is32Bits) { + view = indices instanceof Uint32Array ? indices : new Uint32Array(indices); } else { - if (indexBuffer.is32Bits) { - view = new Uint32Array(indices); - } else { - view = new Uint16Array(indices); - } + view = indices instanceof Uint16Array ? indices : new Uint16Array(indices); } this._bufferManager.setSubData(gpuBuffer, offset, view);