More about rendering in separate thread

Member
Posts: 93
Joined: 2008.11
Post: #1
Hello,

Currently I have the following setup in my game:
1) Runloop for Logic updates which runs in a separate thread
2) Runloop for Rendering which does all OpenGL rendering. The while(flag) loop here is looping in a separate thread however all the calls which actually render using GL calls are made on the main thread.

From all that I have read on the forum and on different Howtos/Faqs I still can't understand how people manage to get OpenGL rendering totally hidden in a separate thread. I would like to get some inputs on this subject.
I have a scrolling text screen at ~80fps in my game and the main game screen is working pretty fast on the simulator but on the iPhone it is much slower than it used to be when I had logic/render in one routine and that routine was called by NSTimer at 60fps rate. I also noticed some jumps in the animation and these jumps seems to have a constant frequency (about 1 sec.). Please note that I disabled the FPS counting/displaying code in my run loops so I wouldn't expect the freezes to be caused by that.

The second problem with the current setup is that touching the screen during animation is causing a huge performance degradation. I hope that will change once I have rendering in a new thread (not the main thread) and the input will be handled as usual on the main thread. Is that the correct/expected way?

I'm pretty new to opengl so please excuse me if I'm doing totally wrong. Any inputs are appreciated.
Thanks in advance!
Quote this message in a reply
Member
Posts: 93
Joined: 2008.11
Post: #2
I was doing totally right except for one thing: i had to call setCurrentContext every time I would need to access my opengl stuff from another thread. That's all I was missing.
Now I have both logic and rendering in separate threads and things seems to work better.. actually I didn't get (yet) better performance than the one with the NSTimer setup.. however it's nice to have things split from each other.
However 2 things still happen.
1) I still get some (small though) jumps with some constant frequency.. it looks more like 0.5/0.4 seconds now.
2) Touching the screen during animation still eats up a lot of processing time which leads to animation jumps as well.

I'm on firmware 2.0.2. 1st generation iPhone. Any ideas?

TIA,
Alex
Quote this message in a reply
Moderator
Posts: 335
Joined: 2002.04
Post: #3
Update to the 2.2 firmware. Apart from staying relevant to current users, it supposedly improves the multi-touch response.
Quote this message in a reply
Member
Posts: 93
Joined: 2008.11
Post: #4
Well, thanks for the tip. I might want to upgrade soon. But what about other games like quake1 for the iPhone which work on my same hardware and don't have my problems? How they managed to fix that? Ideas?
Quote this message in a reply
Moderator
Posts: 335
Joined: 2002.04
Post: #5
Quake's not actually out on the iPhone, only under jailbroken ones, so it's possible that currently it's using undocumented APIs that won't work on a proper iPhone without a rewrite.
Quote this message in a reply
Member
Posts: 93
Joined: 2008.11
Post: #6
Would not be a problem in my case since I will not release my software through the appstore anyway. Besides my game requires jailbreak to put songs into the songs dir on the iphone.. it would otherwise be illegal for me to distribute songs with the application. I'm working on tapmania - the Dance dance revolution for iPhone which mimics StepMania in many cases.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Universal, or separate apps? MattDiamond 10 4,454 Sep 12, 2010 07:08 PM
Last Post: MattDiamond
  emulator slow when rendering from a second thread captainfreedom 1 2,839 Jan 30, 2010 05:05 PM
Last Post: ChrisD
  Messaging between separate views Toontingy 0 2,038 Jan 9, 2010 05:10 PM
Last Post: Toontingy
  OpenGL render loop - NSTimer vs rendering thread smallstepforman 27 23,258 Feb 2, 2009 10:22 AM
Last Post: ThemsAllTook
  Most efficient run/rendering loop/thread iPhoneGG 5 5,788 Dec 4, 2008 12:50 AM
Last Post: godexsoft