简体   繁体   中英

OpenGL ES - glImageProcessing - remove texture

I am using the glImageProcessing example from Apple to perform some filter operations on. However, I would like to be able to load a new image into the texture.

Currently, the example loads the image with the line:

loadTexture("Image.png", &Input, &renderer); 

(which I've modified to accept an actual UIImage):

loadTexture(image, &Input, &renderer);

However, in testing how to redraw a new image I tried implementing (in Imaging.c):

loadTexture(image, &Input, &renderer);
loadTexture(newImage, &Input, &renderer);

and the sample app crashes at the line:

CFDataRef data = CGDataProviderCopyData(CGImageGetDataProvider(CGImage)); 

in Texture.c

I have also tried deleting the active texture by

loadTexture(image, &Input, &renderer);
glDeleteTextures(GL_TEXTURE_2D, 0);
loadTexture(newImage, &Input, &renderer);

which also fails.

Does anyone have any idea how to remove the image/texture from the opengl es interface so that I can load a new image???

Note: in Texture.c, apple states "The caller of this function is responsible for deleting the GL texture object." I suppose this is what I am asking how to do. Apple doesn't seem to give any clues;-)

Also note: I've seen this question posed many places, but no one seems to have an answer. I'm sure others will appreciate some help on this topic as well! Many thanks!

Cheers, Brett

You're using glDeleteTextures() incorrectly in the second case. The first parameter to that function is how many textures you wish to delete, and the second is an array of texture names (or a pointer to a single texture name). You'll need to do something like the following:

glDeleteTextures(1, &textureName);

Where textureName is the name of the texture obtained at its creation. It looks like that value is stored within the texID component of the Image struct passed into loadTexture() .

That doesn't fully explain the crash you see, which seems like a memory management issue with your input image (possibly an autoreleased object that is being discarded before you access its CGImage component).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM