开发者

Load an OpenGl view in the background. iPhone

开发者 https://www.devze.com 2023-01-14 01:15 出处:网络
I have an OpenGL view that renders a 3D model. It is a basic modification on Apples EAGLView. This view is added to a controller\'s .view and displayed with presentModalViewController: . I would like

I have an OpenGL view that renders a 3D model. It is a basic modification on Apples EAGLView. This view is added to a controller's .view and displayed with presentModalViewController: . I would like to do all of the model loading, and OpenGL state configuration in a background thread at app launch before the user chooses to display the view. Is this possible? Can I load textures, setup lighting, and generally just get everything ready to render in a background thread? My fear is that the Cocoa touch portions of the app on the main are going to manipulate the OpenGL state while I am setting up my renderer in the background. The controller will be displayed from the main thread of course. This level of understanding of OpenGl-ES is not something I deal with often, 开发者_高级运维so please be gentile if my question is strange in any way :)


You absolutely can do background loading on a thread. Some of the key points: - There is probably not much of a win to moving OGL state setup to a background thread - the total amount of change you'd induce in a context before the start of the first draw doesn't add up to a ton of time. Background loading is useful for textures and VBOs, as well as the load time that has to happen first to get the data to feed to the GL. - You'll need to detach the context from the main thread and move it to the worker thread. We do this using pthreads to "send" the context to the worker. - In our use, we hide the GL view to ensure that it doesn't need to be drawn while in a load state. (Frankly during load it may not contain anything useful.) So during async load the visible UI is all non-GL Cocoa.

This approach is more difficult than what you would do on the desktop: simply share the objects in two contexts (so that you can load and draw at the same time). When we looked at that approach more than a year ago, it wasn't possible on IOS; it may be possible now, I do not know.

0

精彩评论

暂无评论...
验证码 换一张
取 消