在MTKView上从ARKit模仿相机框架

时间:2018-03-23 15:10:22

标签: ios camera arkit metal

我试图在ARFrame上对来自MTKView的帧进行blit。出于各种原因,我试图避免使用着色器。我现在做的基本上是这样的:

drawInMTKView方法中:

// When the session:didUpdateFrame callback is called I create a
// CIImage from the CVPixelBufferRef inside ARFrame provided and
// set the property in the view

- (void)drawInMTKView:(nonnull MTKView *)view {
    if (!view.currentDrawable || !view.currentRenderPassDescriptor) {
        return;
    }

    id<MTLCommandBuffer> commandBuffer = [commandQueue commandBuffer];

    [ciContext render:ciImage
               toMTLTexture:mtkView.currentDrawable.texture
               commandBuffer:commandBuffer bounds:CGRectMake(0, 0, view.drawableSize.width, view.drawableSize.height) colorSpace:colorSpace];
    [commandBuffer presentDrawable:mtkView.currentDrawable];
    [commandBuffer commit];
}

问题是我无法覆盖整个视图并且无法正确旋转。它在视图旋转时也会崩溃,可能是因为它试图在缓冲区边界外写入。我通过给出一个100x100矩形作为render:toMTLTexture方法的绑定来测试。

如果有人能指导我如何正确渲染,我会很高兴。提前谢谢。

Sample screenshot

0 个答案:

没有答案