@@ -44,7 +44,13 @@ private void createIndexBuffer(int vertexCount) {
4444 }
4545 case TRIANGLE_FAN -> buffer = genTriangleFanIndices (vertexCount );
4646 case TRIANGLE_STRIP -> buffer = genTriangleStripIndices (vertexCount );
47- case LINES -> buffer = genLinesIndices (vertexCount );
47+ case LINES -> {
48+ if (indexType == IndexBuffer .IndexType .UINT16 )
49+ buffer = genLinesIndices (vertexCount );
50+ else {
51+ buffer = genIntLinesIndices (vertexCount );
52+ }
53+ }
4854 case DEBUG_LINE_STRIP -> buffer = genDebugLineStripIndices (vertexCount );
4955 default -> throw new IllegalArgumentException ("Unsupported drawType: %s" .formatted (this .drawType ));
5056 }
@@ -167,6 +173,28 @@ public static ByteBuffer genLinesIndices(int vertexCount) {
167173 return buffer ;
168174 }
169175
176+ public static ByteBuffer genIntLinesIndices (int vertexCount ) {
177+ int indexCount = vertexCount * 3 / 2 ;
178+ indexCount = roundUpToDivisible (indexCount , 6 );
179+
180+ ByteBuffer buffer = MemoryUtil .memAlloc (indexCount * Integer .BYTES );
181+ IntBuffer idxs = buffer .asIntBuffer ();
182+
183+ int j = 0 ;
184+ for (int i = 0 ; i < vertexCount ; i += 4 ) {
185+ idxs .put (j + 0 , (i ));
186+ idxs .put (j + 1 , (i + 1 ));
187+ idxs .put (j + 2 , (i + 2 ));
188+ idxs .put (j + 3 , (i + 3 ));
189+ idxs .put (j + 4 , (i + 2 ));
190+ idxs .put (j + 5 , (i + 1 ));
191+
192+ j += 6 ;
193+ }
194+
195+ return buffer ;
196+ }
197+
170198 public static ByteBuffer genTriangleFanIndices (int vertexCount ) {
171199 int indexCount = (vertexCount - 2 ) * 3 ;
172200 ByteBuffer buffer = MemoryUtil .memAlloc (indexCount * Short .BYTES );
0 commit comments