How to handle multitasking in OpenGL ES based apps on iOS 4?
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开发者_Python百科 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.
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).
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.
精彩评论