The solutuion was to use an "OpenGL ES rendering loop " instead of trying to build one with CADisplayLink
. Luckily this was easy since a GLKViewController
does this automtically:
The GLKViewController class provides all of the standard view controller functionality, but additionally implements an OpenGL ES rendering loop.
The only down side is that this strongly ties you to using a GLKViewController
instead of a just adding a GLKView
to an existing UIView. To get around this you need to work out how to implement your own OpenGL ES rendering loop.
// The GLKViewController automatically calls this method
- (void) updateScreen
{
CIImage * result = [Helper generateCoreImage];
// Clears the screen to a grey color
glClearColor(0.5, 0.5, 0.5, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
[self.ciContext drawImage:result
inRect:self.destFrame
fromRect:self.targetFrame];
// `display` needs to be called here according to the docs.
GLKView *view = (GLKView *)self.view;
[view display];
}