         
         // Presents a drawable object when the command buffer is executed.
         commandBuffer!.presentDrawable(drawable)
+        
+        commandBuffer!.addCompletedHandler { (buffer:MTLCommandBuffer) -> Void in
+            dispatch_semaphore_signal(self.inflightSemaphore)
+        }
+        
         // The CommandBuffer is executed by the GPU.
         commandBuffer!.commit()
     }

    
    init(device: MTLDevice) {
        self.device = device
        makePipeline()
        makeBuffers()
    }


class MBERenderer: MBEMetalViewDelegate {
    
    let kInFlightCommandBufferes = 3
    let inflightSemaphore:dispatch_semaphore_t
    
    var device: MTLDevice
    var commandQueue:MTLCommandQueue?
    var pipeline:MTLRenderPipelineState?
