如何在 iOS 4 上处理基于 OpenGL ES 的应用程序中的多任务处理?
我正在观看 WWDC 视频(第 105 节),该视频讨论了 iOS 的多任务处理4.刚才提到了一个有趣的事情:
“您的应用程序运行时的任何 GPU 使用情况 任一背景状态 导致自动终止 该应用程序。这包括对 OpenGL 的任何调用。”
如果整个应用程序基于 OpenGL,如何处理这一“要求”?
注意:我问 这个问题因为我的基于OpenGL的应用程序似乎在模拟器中很好地执行多任务处理,但在设备上却不行( iPhone 4)...应用程序在设备上运行时会自动终止,这可能是由于“低效”内存分配(当应用程序进入后台时我不会释放任何资源)...或者可能是。由于我刚刚了解到的“不使用 GPU”限制。
I'm watching a WWDC video (session 105) that's talking about multitasking with iOS 4. Something interesting was just mentioned:
"any GPU usage while your app is in
either of the background states
results in automatic termination of
the app. This includes any calls to OpenGL."
How does one handle this "requirement" if the entire app is OpenGL based?
Note: I asked this question because my OpenGL based app seems to do multitasking just fine in the simulator but not on the device (iPhone 4)... the app is automatically terminated when run on the device. It may be due to "inefficient" memory allocation (I don't release any resources when the app goes to the background)... or it could be due to this "no GPU usage" restriction I just learned about.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要将处理逻辑与绘制和更新(OpenGL 调用)分开。然后,您可以在进入和退出后台状态(applicationDidEnterBackground / applicationWillEnterForeground)时为应用程序设置全局状态,并使用该标志跳过 OpenGL 绘图调用(以及不应从后台状态执行的任何其他代码)。
You need to separate processing logic from draw and update (OpenGL calls). Then, you can set a global state for your app when going in and out of background states (applicationDidEnterBackground / applicationWillEnterForeground) and use that flag to skip your OpenGL drawing calls (and any other code that should not be executed from the background state).
请参阅 iOS 版 OpenGL ES 编程指南
特别需要注意的是,应根据 applicationDidEnterBackground: 和/或 applicationWillResignActive: 调用 glFinish()。
据我了解,如果所有 OpenGL ES 执行都是事件处理的结果,那么您将不需要使用全局“前台”标志,因为您的应用程序在后台时不会处理任何事件。
See the documentation at OpenGL ES Programming Guide for iOS
In particular, it should be noted that a call to glFinish() should be made as a result of applicationDidEnterBackground: and/or applicationWillResignActive:.
It is my understanding that you will not need to use a global "in foreground" flag if all OpenGL ES execution is a result of event-handling, since your application will not handle any events while it is in the background.