     var pipelineState: MTLRenderPipelineState!
     
     var uniformsBuffer: MTLBuffer!
-    var vertexBuffer: MTLBuffer!
     var textureCoordBuffer: MTLBuffer!
     var textures: [MTLTexture]!
-   
+
+    let VERTEX_BUFFER_COUNT = 2
+    var vertexBufferIndex = 0
+    var vertexBuffers: [MTLBuffer]!
+
     var displayLink: CVDisplayLink?
 
     var animation: Animation!

            x+w/2, y-h/2, //c
            x+w/2, y+h/2  //d
        ]
        let arraySize = sizeofArray(vertexData)
        let bufferPointer = vertexBuffer.contents() + arraySize * index
        memcpy(bufferPointer, vertexData, arraySize)
        vertexBuffer.didModifyRange(NSMakeRange(arraySize * index, sizeofArray(vertexData)))
    }

    func screenpos(_ p: (x: Double, y: Double)) -> (x: Float, y: Float)


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