I've worked with Apple's GLImageProcessing Example - Where I apply various filters to an image. I've followed GLImageProcessing Multiple Filters? to make it work with two filters.
The Original example by Apple works great at doesn't leak memory.
Using the code from the Question mentioned above makes the app consume all of the iPhone memory in 10-20 seconds of use giving me a Memory Warning and finally making the app crash.
I know it's related to creating the aditional Textures and Frame Buffer Objects (FBO's) but I'm not sure how to correctly manage them (and their memory)
The code:
void drawGL(int wide, int high, float contrastVal,float brightnessVal)
{
//INIT
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrthof(0, wide, 0, high, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glScalef(wide, high, 1);
glGetIntegerv(GL_FRAMEBUFFER_BINDING_OES, (GLint *)&SystemFBO);
// Create the texture and the FBO the will hold the result of applying the first filter
glGenTextures(1, &ResultTexture);
glBindTexture(GL_TEXTURE_2D, ResultTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, wide, high, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glGenFramebuffersOES(1, &ResultTextureFBO);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, ResultTextureFBO);
glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, ResultTexture, 0);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, ResultTextureFBO);
glBindTexture(GL_TEXTURE_2D, Input.texID);
glViewport(0, 0, wide, high);
brightness(flipquad, contrastVal);
glCheckError();;
glBindFramebufferOES(GL_FRAMEBUFFER_OES, SystemFBO);
glBindTexture(GL_TEXTURE_2D, ResultTexture);
glViewport(0, 0, wide, high);
contrast(fullquad,brightnessVal);
glCheckError();
}
Is there a better way to do this?