簡體   English   中英

OpenGLES將代碼混合到金屬翻譯

[英]OpenGLES blending code to Metal translation

我有這個簡單的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

相對於OpenGL代碼,混合配置似乎是正確的。 管道描述符具有用於alpha混合的默認值,可能很好。 alphaBlendOperation默認為.addsourceAlphaBlendFactor默認為.onedestinationAlphaBlendFactor默認為.zero

當然,還有其他一些因素可能會影響性能,例如着色器功能的細節。

您如何衡量效果?

Metal應用程序可以比OpenGL應用程序具有更高的性能,但這不是因為任何給定的單個渲染操作都更快。 GPU硬件的性能將成為限制因素。 Metal可以消除OpenGL的開銷,為應用提供對資源管理的更多控制權等,從而獲得更高的性能。在不代表真實應用的非常簡單的測試用例中,這些因素可能不會出現。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM