 			$0.startTime + $0.duration > Date()
 		}
 		
+		renderLists[bufferIndex] = ContiguousArray(runningEffects.map { $0.primitive })
 		var fx = Array<InstanceUniforms>()
 		fx.reserveCapacity(runningEffects.count)
 		for effect in runningEffects {

		encoder.setVertexBuffer(instanceUniforms[bufferIndex], offset: 0, index: 2)
		
		var instanceCursor = 0
		for effect in runningEffects {
			encoder.setVertexBufferOffset(instanceCursor, index: 2)
			render(primitive: effect.primitive, into: encoder)
			
			instanceCursor += MemoryLayout<InstanceUniforms>.stride
		}

}

class EffectRenderer {
	typealias EffectPrimitive = RegionEffect.EffectPrimitive
	typealias RenderList = ContiguousArray<EffectPrimitive>
	static let kMaxSimultaneousEffects = 8
	let device: MTLDevice
	let pipeline: MTLRenderPipelineState
	let instanceUniforms: [MTLBuffer]
	
	var runningEffects : [RegionEffect]
	var renderLists : [RenderList]
	
	var animating: Bool { get {
		return !runningEffects.isEmpty
	}}
