I had a hard time finding any examples of how to properly use Core Image with GLKView
in order to smoothly render Core Image "recipes" in response to user inputs. So, after reading the Core Image Programming Guide and the GLKView
class reference, I came up with an approach that works. However, I'm not sure it's valid, so I'm hoping someone can either confirm that it's OK, or point me in a better direction.
Right now, I'm using a GLKView
with a GLKViewController
. The GLKView
delegates drawing to its parent view controller, which implements glkView:drawInRect:
. The drawing method does this:
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect {
// make glkView's background light gray instead of black
glClearColor(backgroundRGB, backgroundRGB, backgroundRGB, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// a custom object that holds a reference to a CIContext
ImageEditingContext* context = [ImageEditingContext getInstance];
// apply a core image recipe
CIImage *outputImage = [context getFilteredPreviewCIImage];
// draw the image
CGRect inRect = outputImage.extent;
inRect.origin.y = (self.glkView.contentScaleFactor * self.glkView.frame.size.height - inRect.size.height) / 2.0;
[context.coreImageContext drawImage:outputImage inRect:inRect fromRect:outputImage.extent];
}
Specifically, I'm concerned about the last line, [context.coreImageContext drawImage:outputImage inRect:inRect fromRect:outputImage.extent]
. Is it valid to call that method from within glkView:drawInRect:
? As I mentioned before, this approach seems to work fine, but I became suspicious of it after running the OpenGL ES Analysis Instruments template. It flagged the line with this issue:
Multi-context Renderbuffer Usage Without Flush: Renderbuffer #2 - Your application used a renderbuffer object that has been updated in a different context without a subsequent flush operation.
My GLKView
and CIContext
are both set up with the same EAGLContext
, so I'm not quite sure what the error message is referring to. Any insight is much appreciated!