Should I use multiple threads within my OpenGL ES game?

后端 未结 2 1563
滥情空心
滥情空心 2021-01-13 18:15

I am developing an iPhone game which contains one player and many enemies. I use OpenGL ES to display the game visuals.

I am a little confused as to whether I shoul

2条回答
  •  时光说笑
    2021-01-13 19:00

    I'm going to disagree with Max on this one and say that you shouldn't completely ignore using multithreading in your application. OpenGL ES can be drawn to from a background thread, but you can only communicate to an OpenGL ES context using a single thread at a time.

    Apple has an entire section entitled "Concurrency and OpenGL ES" in their OpenGL ES Programming Guide for iOS. In that, they describe several scenarios for improving performance of an OpenGL ES application using multithreading.

    In general, it's recommended that you move time-consuming operations off of the main thread. The main thread handles the user interface of your application, and if you block that you will prevent standard UI elements from updating and touch events from registering. Depending on how much processing is being done behind the scenes for your game (physics, AI, etc.), you may need to move significant chunks of that to a background thread.

    Multithreading is not a simple topic, but Apple has made this a lot easier through Grand Central Dispatch, so I highly recommend reading their Concurrency Programming Guide which describes this and other techniques for achieving multithreading in your application. Additionally, I taught a class on multithreading and GCD as part of my course on iOS development, the video of which can be found on iTunes U.

    As Apple rolls out multicore devices, taking advantage of multithreading and GCD now will greatly pay off for you in the future.

提交回复
热议问题