Reputation: 55
I use a CADisplayLink (running at 20 FPS) to redraw my Opengl ES scene. As I do this, I found that there is a huge lag between touchesBegan and touchesEnded on touch events, almost 200 ms or more.
If I turn off the CADisplayLink then the lag is reduced to 50 ms. Any one know how to fix this issue?
Upvotes: 0
Views: 1167
Reputation: 170309
I assume that your CADisplayLink is running on the main thread, because you don't specify otherwise. If that's the case, then you could be overloading the main thread with your rendering actions, preventing your touch events from being processed (all touch events are handled on the main thread).
My solution for a similar problem was to use a serial GCD queue for OpenGL ES rendering actions, combined with a dispatch semaphore to make sure that only one frame was being rendered at a time in response to a CADisplayLink firing. This answer of mine describes the process in detail, and I link to source code for an application which uses this. As a side benefit, this can improve your rendering speed by up to 40% on the newer multicore devices.
Upvotes: 2