Ios 有人知道如何将一点OpenGL代码转换成金属代码吗?

Ios 有人知道如何将一点OpenGL代码转换成金属代码吗?,ios,objective-c,opengl,avfoundation,metal,Ios,Objective C,Opengl,Avfoundation,Metal,我一直在使用一些OpenGL代码来完成objective-c相机捕获任务,我几乎不懂。现在OpenGL贬值了,我不知道如何将这一点点OpenGL代码转换成金属。如果有人对这两个方面都有足够的了解,可以转换以下内容,请提供帮助 if (self.eaglContext != [EAGLContext currentContext]) { [EAGLContext setCurrentContext:self.eaglContext]; } glClearColor(0.5, 0.5, 0.

我一直在使用一些OpenGL代码来完成objective-c相机捕获任务,我几乎不懂。现在OpenGL贬值了,我不知道如何将这一点点OpenGL代码转换成金属。如果有人对这两个方面都有足够的了解,可以转换以下内容,请提供帮助

if (self.eaglContext != [EAGLContext currentContext]) {
    [EAGLContext setCurrentContext:self.eaglContext];
}
glClearColor(0.5, 0.5, 0.5, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
还有一点我没有看到的OpenGL:

_eaglContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
_videoPreviewView = [[GLKView alloc] initWithFrame:self.view.bounds context:_eaglContext];
_videoPreviewView.enableSetNeedsDisplay = NO;
_videoPreviewView.transform = CGAffineTransformMakeRotation(M_PI_2);
_videoPreviewView.frame = self.view.bounds;
[self.view addSubview:_videoPreviewView];
[self.view sendSubviewToBack:_videoPreviewView];
[_videoPreviewView bindDrawable];
_videoPreviewViewBounds = CGRectZero;
_videoPreviewViewBounds.size.width = _videoPreviewView.drawableWidth;
_videoPreviewViewBounds.size.height = _videoPreviewView.drawableHeight;
_ciContext = [CIContext contextWithEAGLContext:_eaglContext options:@{kCIContextWorkingColorSpace : [NSNull null]} ];

从OpenGL到Metal并不是一个简单的转换。第一步是将
GLKView
替换为
MTKView
。然后,您需要创建一个
id
来处理实际的绘图、调整大小等。我建议您观看WWDC 2016的视频。它显示了如何使用
MTKView
启动和运行

要进行混合,需要在用于创建渲染管道状态的
MTLRenderPipelineColorAttachmentDescriptor
上设置混合选项。您需要将
blendingEnabled
属性设置为
YES
,并将
rgbblendooperation
属性设置为
mtlblendooperationadd
。然后将
sourceRGBBlendFactor
设置为
MTLBlendFactorOne
,将
destinationRGBBlendFactor
设置为
mtlblendfactorneminussourcealpha


您可以通过
+[CIContext contextWithMetalDevice:options://code>

id
创建
CIContext
,您还可以看看这个吗?对不起,我从未使用过AV框架,所以对此一无所知。