views:

529

answers:

2

It appears that touch events are happening on a different thread then OpenGL rendering. Is this the case? The context for this question is a particle system I am building that uses touch events to trigger OpenGL drawing. Since OpenGL drawing is rather heavyweight I am concerned about threading implications.

Any insight would be much appreciated.

Regards, Doug

A: 

Unless you otherwise specify, your code runs on the main thread. That being said, some library/SDK calls launch their own separate threads. In this manner you could possibly be indirectly creating other threads.

As for your specific case, My won experience doesn't match. Touch Events are processed on the main thread, as is openGL.

Kailoa Kadano
Hang on, since OpenGL runs on the GPU not the CPU by definition it runs in a parallel thread. drawView is typically called from a timer which I assume simply signals the GPU to do it's thing.You can see this in any OpenGL app that also involves touch events. Otherwise rendering would hang waitng on the complete of touch sequences.
dugla
+1  A: 

Nope. Same thread.

You submit commands to the OpenGL subsystem and then they are executed on the GPU, so not "by definition" a parallel thread b/c the graphics processor doesn't necessarily have the concept of threads in the same way as the CPU.

The default OpenGL project just creates an NSTimer that fires on the main thread every frame and calls into OpenGL.

What you are probably observing is that most drawing commands are asynchronous. Since you're drawing into an offscreen buffer on the iPhone, you'll only see the results when you swap the buffers after you're done drawing:

    [context presentRenderbuffer:GL_RENDERBUFFER_OES];
Andrew Pouliot