     func createBuffer(device: MTLDevice, bytecount: Int, options: MTLResourceOptions, createWith: (Self) -> EncodableBuffer) -> EncodableBuffer {
         return createWith(self)
     }
+    
+    func getBuffer() -> EncodableBuffer {
+        var buffer = buffers[buffersIndex]
+        buffersIndex = (buffersIndex + 1) % buffersCount
+        
+        // return the buffer unmodified and let the user determine how to write to it
+        return buffer
+    }
+    
+    func getBuffer(bufferIndex: Int) -> EncodableBuffer {
+        return buffers[bufferIndex]
+    }
 }
 
 class BaseBufferPool: BufferPool {

    func prepareBufferPool(device: MTLDevice, bytecount: Int, options: MTLResourceOptions, createWith: (Self) -> EncodableBuffer)
    func createBuffer(device: MTLDevice, bytecount: Int, options: MTLResourceOptions) -> EncodableBuffer
    func createBuffer(device: MTLDevice, bytecount: Int, options: MTLResourceOptions, createWith: (Self) -> EncodableBuffer) -> EncodableBuffer
    func releaseBuffer()
    
    func getBuffer() -> EncodableBuffer
}

//TODO: must dispatch_semaphore_signal from view render() !!!

extension BufferPool {
    //    var bytecount:Int
    //    var availableBuffersIndex:Int = 0
    //    var availableBuffersSemaphore:dispatch_semaphore_t?
    //    internal var buffers: [Buffer] = []
    //    private var inflightBuffersCount:Int
    
    func prepareBufferPool(device: MTLDevice, bytecount: Int, options: MTLResourceOptions = .CPUCacheModeDefaultCache) {
        buffersSemaphore = dispatch_semaphore_create(buffersCount)
        for _ in 0...buffersCount-1 {
            let buffer = createBuffer(device, bytecount: self.bytecount, options: options)
            buffers.append(buffer)

    var bytecount:Int
    var buffersCount:Int
    var buffersIndex:Int = 0
    internal var buffers: [EncodableBuffer] = []
    
    required init(device: MTLDevice, bytecount: Int, buffersCount: Int, options: MTLResourceOptions = .CPUCacheModeDefaultCache) {
        self.bytecount = bytecount
        self.buffersCount = buffersCount
    }
    
    //deinit {
        //TODO: release buffer memory?
    //}
}

class SingleBuffer: BufferPool {
