Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios OpenGLES混合代码到金属翻译_Ios_Opengl Es_Metal - Fatal编程技术网

Ios OpenGLES混合代码到金属翻译

Ios OpenGLES混合代码到金属翻译,ios,opengl-es,metal,Ios,Opengl Es,Metal,我有一个简单的OpenGLES混合代码: glBlendEquation(GL_FUNC_ADD); glBlendFunc(GL_ONE, GL_ONE); glEnable(GL_BLEND); 我用金属编写了代码,但我不知道它是否真的能做同样的工作。具体来说,我需要提到alpha混合因子还是不需要。因为我看到这段代码在金属中的性能比OpenGLES差,这很奇怪。请让我知道这个代码中是否缺少任何东西 let renderPipelineDescriptorGreen = MTL

我有一个简单的OpenGLES混合代码:

 glBlendEquation(GL_FUNC_ADD);
 glBlendFunc(GL_ONE, GL_ONE);
 glEnable(GL_BLEND);
我用金属编写了代码,但我不知道它是否真的能做同样的工作。具体来说,我需要提到alpha混合因子还是不需要。因为我看到这段代码在金属中的性能比OpenGLES差,这很奇怪。请让我知道这个代码中是否缺少任何东西

   let renderPipelineDescriptorGreen = MTLRenderPipelineDescriptor()
    renderPipelineDescriptorGreen.vertexFunction = vertexFunctionGreen
    renderPipelineDescriptorGreen.fragmentFunction = fragmentFunctionAccumulator
    renderPipelineDescriptorGreen.colorAttachments[0].pixelFormat = .bgra8Unorm
    renderPipelineDescriptorGreen.colorAttachments[0].isBlendingEnabled = true
    renderPipelineDescriptorGreen.colorAttachments[0].rgbBlendOperation = .add
    renderPipelineDescriptorGreen.colorAttachments[0].sourceRGBBlendFactor = .one
    renderPipelineDescriptorGreen.colorAttachments[0].destinationRGBBlendFactor = .one

与OpenGL代码相比,混合配置似乎是正确的。管道描述符具有alpha混合的默认值,这些值可能很好
alphaBlendOperation
默认为
。add
sourceAlphaBlendFactor
默认为
。one
,而
DestinationalAlphablendFactor
默认为
。zero

当然,还有其他可能影响性能的因素,比如着色器函数的细节

你是如何衡量业绩的


金属应用程序可以比OpenGL应用程序具有更高的性能,但这并不是因为任何给定的单一渲染操作都更快。GPU硬件的性能将是那里的限制因素。Metal可以通过消除OpenGL的开销、让应用程序更好地控制资源管理等来实现更高的性能。在不代表真实应用程序的非常简单的测试用例中,这些因素可能不会显示出来。

与OpenGLES中的类似代码相比,我纯粹是用FPS来衡量性能(这是GPUImage框架的HistogramFilter)。OpenGLES代码中唯一的区别是GPUImage将像素值作为顶点传递给顶点着色器(这意味着它在CPU中读取纹理的像素值),而我像这里一样在GPU的顶点着色器中读取像素值:-好的,我想我没有在GPUImage代码中设置用于比较的等效参数。金属代码比OpenGLES 2.0快2倍。