 		
 		self.indexBuffer = newIndexBuffer
 		self.indexBuffer.label = "\(debugName) index buffer"
-		
-		elementCount = indices.count
 	}
 }
 
+
 func render<T>(primitive: IndexedRenderPrimitive<T>, into encoder: MTLRenderCommandEncoder) {
 	encoder.setVertexBuffer(primitive.vertexBuffer, offset: 0, index: 0)
-	encoder.drawIndexedPrimitives(type: .triangle,
-																indexCount: primitive.elementCount,
-																indexType: .uint16,
-																indexBuffer: primitive.indexBuffer,
-																indexBufferOffset: 0)
+	
+	var cursor = 0
+	for range in primitive.elementCounts {
+		encoder.drawIndexedPrimitives(type: primitive.drawMode,
+																	indexCount: range,
+																	indexType: .uint32,
+																	indexBuffer: primitive.indexBuffer,
+																	indexBufferOffset: cursor)
+		cursor += range * MemoryLayout<UInt32>.stride
+	}
 }

		
		ownerHash = hash
		name = debugName
		
		guard !indices.isEmpty else {
			fatalError("Do not create render primitive for empty meshes")
		}
		
		let vertexBufLen = MemoryLayout<VertexType>.stride * vertices.count
		let indexBufLen = MemoryLayout<UInt16>.stride * indices.count
		
		guard let newVertBuffer = device.makeBuffer(bytes: vertices, length: vertexBufLen, options: .storageModeShared),
					let	newIndexBuffer = device.makeBuffer(bytes: indices, length: indexBufLen, options: .storageModeShared) else {
				fatalError("Could not create buffers for \(debugName)")
		}
		

class IndexedRenderPrimitive<VertexType> {
	let ownerHash: Int
	
	let drawMode: MTLPrimitiveType
	let vertexBuffer: MTLBuffer
	let elementCounts: [Int]
	let indexBuffer: MTLBuffer
	
	let color: Color
	let name: String
	
	init(polygons: [[VertexType]],
			 indices: [[UInt16]],
			 drawMode mode: MTLPrimitiveType,
			 device: MTLDevice,
			 color c: Color,
			 ownerHash hash: Int, debugName: String) {
