OpenGLES将代码混合到金属翻译

时间:2018-05-28 07:49:08

标签: ios opengl-es metal

我有这个简单的OpenGLES混合代码到Metal:

 glBlendEquation(GL_FUNC_ADD);
 glBlendFunc(GL_ONE, GL_ONE);
 glEnable(GL_BLEND);

我在Metal中编写了代码,但如果确实做同样的工作,我会很困惑。具体来说,我是否需要提及alpha混合因子或否。因为我看到这个代码在Metal中的性能比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

1 个答案:

答案 0 :(得分:2)

相对于OpenGL代码,混合配置似乎是正确的。管道描述符具有alpha混合的默认值,可能很好。 alphaBlendOperation默认为.addsourceAlphaBlendFactor默认为.onedestinationAlphaBlendFactor默认为.zero

当然,还有其他一些可能会影响性能的因素,例如着色器功能的细节。

您如何衡量绩效?

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

相关问题