Question

I'm trying to use GPUImage with my OpenGL based photo editing app. The problem is that it seems like the two OpenGL contexts conflict which means that GPUImage doesn't function properly.

I've tried adding this before using GPUImage:

[EAGLContext setCurrentContext:[GPUImageContext sharedImageProcessingContext].context];

But it's not helping. The problem that I'm seeing is that when I try to apply a filter to an image, it applies the filter to the previously filtered image i.e.

1) Filter image 1 - output image 2

2) Reload my OpenGL image canvas

3) Filter image 2 - output image 2 (it should be image 3 i.e. the filtered version of image 2)

This happens the first three times I apply the filter, then it starts working correctly. Is there a way to reset the GPUImage context? Or to dispose of the GPUImage context singleton and start afresh?

Was it helpful?

Solution

First, you'll want to make sure that your OpenGL-based drawing application is rendering its scene to a texture and that you're using a texture input (if passing into GPUImage). GPUImage needs to work with textures, not render buffers themselves. If going out from GPUImage, use a texture output and its rendering callback block to know when rendering has finished.

To share content between GPUImage and another OpenGL context, you need to make GPUImage's context part of the same share group as your own OpenGL context. It's probably best not to share the GPUImage context directly, since it performs operation internally on a background dispatch queue and you can't guarantee thread safety if rendering to that in your own code.

The CubeExample sample application on the iOS side shows how to do this for OpenGL ES. In particular, it uses the following line:

    context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2 sharegroup:[[[GPUImageContext sharedImageProcessingContext] context] sharegroup]];

to set up the share group for the OpenGL ES context used for the non-GPUImage rendering there. I'd have to look up what the equivalent is for the Mac and desktop OpenGL, though.

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