Should I use multiple threads within my OpenGL ES game?

后端 未结 2 1557
滥情空心
滥情空心 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.

    0 讨论(0)
  • 2021-01-13 19:02

    It really depends on lots of things. First of all you won't get any performance boost if you're using several threads (since all modern iOS-devices has single core processors, though iPad2 has 2). Second several threads make any application much more sophisticated, since you have to keep track of shared resources, synchronize threads and lots more.

    Use several threads only if you really need this. For example you're loading lots of textures into memory from file and it might take several seconds. If you do this on the same thread, where there rendering is performed, then all rendering would hang for that time. So it's better to do that on a separate thread and then give loaded data to the main one. Or you might update physics on a separate thread with higher update rate (however you benefit from this only on several cores).

    If you're a novice developer and making some simple game don't use multiple threads. This stuff requires lot of experience.

    0 讨论(0)
提交回复
热议问题