Question

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

Was it helpful?

Solution

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];

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top