From 2a3263780858dde2b035e4f59867aab11254633b Mon Sep 17 00:00:00 2001 From: Tim Deubler Date: Wed, 23 Oct 2024 12:14:33 +0200 Subject: [PATCH] improved GeometryBuffer index handling Signed-off-by: Tim Deubler --- .../displays/webgl/buffer/GeometryBuffer.ts | 36 ++++++++----------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/packages/display/src/displays/webgl/buffer/GeometryBuffer.ts b/packages/display/src/displays/webgl/buffer/GeometryBuffer.ts index 509cb1b1d..cdae7736a 100644 --- a/packages/display/src/displays/webgl/buffer/GeometryBuffer.ts +++ b/packages/display/src/displays/webgl/buffer/GeometryBuffer.ts @@ -213,31 +213,23 @@ class GeometryBuffer { } private createIndex(index: number[] | Uint16Array | Uint32Array, i32?: boolean): IndexGrp { + const data = Array.isArray(index) ? + i32 ? new Uint32Array(index) : new Uint16Array(index) + : index; + // let i = index.length; + // while (i--) { + // if (index[i] > 0xffff) { + // i32 = true; + // break; + // } + // } return { - index: i32 ? { - data: isTypedArray(index) ? (index) : new Uint32Array(index), - type: GL_UNSIGNED_INT, - length: index.length - } : { - data: isTypedArray(index) ? (index) : new Uint16Array(index), - type: GL_UNSIGNED_SHORT, - length: index.length + index: { + type: data.constructor == Uint32Array ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT, + length: index.length, + data } }; - - - // return { - // index: i32 ? { - // data: new Uint32Array(3), - // // data: isTypedArray(index) ? (index) : new Uint32Array(index), - // type: GL_UNSIGNED_INT, - // length: index.length - // } : { - // data: isTypedArray(index) ? index : new Uint16Array(index), - // type: GL_UNSIGNED_SHORT, - // length: index.length - // } - // }; } private createArrays(arrays: ArrayData) {