我正在使用CADisplayLink在iOS上为一个非常简单的OpenGL ES动画发起“更新”事件。动画有大约10个纹理四边形。我尝试以60 FPS运行,我看到了一些故障。将此值更改为30 FPS时,动画运行更顺畅。在分析了这个之后,我发现大部分时间花在了presentRenderBuffer上。
结果如下:
m_displayLink.frameInterval = 2;
[379406923.204] Update time 0.000358
[379406923.206] Render time 0.001402
[379406923.207] Present time 0.001136
[379406923.238] Update time 0.000370
[379406923.239] Render time 0.001393
[379406923.241] Present time 0.001148
[379406923.271] Update time 0.000368
[379406923.273] Render time 0.001377
[379406923.274] Present time 0.001226
[379406923.305] Update time 0.000380
[379406923.307] Render time 0.001390
[379406923.308] Present time 0.001183
[379406923.338] Update time 0.000375
[379406923.339] Render time 0.001376
[379406923.341] Present time 0.001178
[379406923.372] Update time 0.000981
[379406923.375] Render time 0.001418
[379406923.379] Present time 0.004452
从m_displayLink.frameInterval = 2
分析的结果我可以看到总帧时间足以达到60 FPS,但是当将m_displayLink.frameInterval
值更改为1
时,结果是意外的:
m_displayLink.frameInterval = 1;
[379407317.151] Update time 0.000204
[379407317.152] Render time 0.000827
[379407317.172] Present time 0.019173
[379407317.172] Update time 0.000231
[379407317.173] Render time 0.000856
[379407317.201] Present time 0.027540
[379407317.202] Update time 0.000204
[379407317.202] Render time 0.000834
[379407317.218] Present time 0.015187
[379407317.218] Update time 0.000192
[379407317.219] Render time 0.000803
[379407317.251] Present time 0.031392
[379407317.252] Update time 0.000215
[379407317.253] Render time 0.000858
[379407317.267] Present time 0.014433
[379407317.268] Update time 0.000196
[379407317.269] Render time 0.001248
[379407317.301] Present time 0.031312
正如你可以看到当前时间使用
时要大几倍m_displayLink.frameInterval = 1;
请注意Render()
的最后一个命令是glFinish()
你知道为什么会出现这种意想不到的行为吗?是否有可能实现60 FPS(从第一次分析到我有大约500FPS!)?
答案 0 :(得分:2)
我通过从view initWithFrame
移动OpenGL初始化来解决问题(纯粹的运气!)。我知道这听起来很尴尬,但这将我的GPU使用率从96%降低到6%。现在简单的应用程序在60 FPS下运行非常流畅,CPU使用率为2%,GPU使用率为6%(应该是这样!)。