             x+w/2, y-h/2, //c
             x+w/2, y+h/2  //d
         ]
+        let currentVertextBuffer = vertexBuffers[vertexBufferIndex]
         let arraySize = sizeofArray(vertexData)
-        let bufferPointer = vertexBuffer.contents() + arraySize * index
+        let bufferPointer = currentVertextBuffer.contents() + arraySize * index
         memcpy(bufferPointer, vertexData, arraySize)
-        vertexBuffer.didModifyRange(NSMakeRange(arraySize * index, sizeofArray(vertexData)))
+        currentVertextBuffer.didModifyRange(NSMakeRange(arraySize * index, sizeofArray(vertexData)))
     }
 
     func screenpos(_ p: (x: Double, y: Double)) -> (x: Float, y: Float)


    func updateVertexBuffer()
    {
        updateVertextBufferWithTextureQuad(position: screenpos(animation.currentState!.p0), at:0)
        updateVertextBufferWithTextureQuad(position: screenpos(animation.currentState!.p1), at:1)
        updateVertextBufferWithTextureQuad(position: screenpos(animation.currentState!.p2), at:2)

    var pipelineState: MTLRenderPipelineState!
    
    var uniformsBuffer: MTLBuffer!
    var textureCoordBuffer: MTLBuffer!
    var textures: [MTLTexture]!

    let VERTEX_BUFFER_COUNT = 2
    var vertexBufferIndex = 0
    var vertexBuffers: [MTLBuffer]!

    var displayLink: CVDisplayLink?

    var animation: Animation!
