@@ -18,6 +18,10 @@ class Mesh extends Node {
1818 int numItems;
1919
2020 Mesh ( MeshData meshData, [this .drawPoints= false ]) {
21+
22+ if ( ! meshData.isOptimized)
23+ meshData.optimize ();
24+
2125 this .texture = meshData.texture;
2226 this .texture2 = meshData.texture2;
2327
@@ -55,7 +59,10 @@ class Mesh extends Node {
5559 numItems = meshData.vertexIndices.length;
5660 vertexIndexBuffer = gl.createBuffer ();
5761 gl.bindBuffer (ELEMENT_ARRAY_BUFFER , vertexIndexBuffer);
58- gl.bufferDataTyped (ELEMENT_ARRAY_BUFFER , meshData.vertexIndices as Uint16List , STATIC_DRAW );
62+ if (ChronosGL .useElementIndexUint)
63+ gl.bufferDataTyped (ELEMENT_ARRAY_BUFFER , meshData.vertexIndices as Uint32List , STATIC_DRAW );
64+ else
65+ gl.bufferDataTyped (ELEMENT_ARRAY_BUFFER , meshData.vertexIndices as Uint16List , STATIC_DRAW );
5966 } else {
6067 numItems = meshData.vertices.length ~ / 3 ;
6168 }
@@ -147,7 +154,7 @@ class Mesh extends Node {
147154 gl.drawArrays (TRIANGLES , 0 , numItems);
148155 } else {
149156 gl.bindBuffer (ELEMENT_ARRAY_BUFFER , vertexIndexBuffer);
150- gl.drawElements (TRIANGLES , numItems, UNSIGNED_SHORT , 0 );
157+ gl.drawElements (TRIANGLES , numItems, ChronosGL .useElementIndexUint ? UNSIGNED_INT : UNSIGNED_SHORT , 0 );
151158 }
152159
153160 if ( debug)
0 commit comments