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 ThinEngine.updateDynamicIndexBuffer #12564

Merged
merged 5 commits into from
May 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions packages/dev/core/src/Engines/Extensions/engine.dynamicBuffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down