Does GlReadPixels flush buffer in openGL ES 2?

I have an application for drawing OpenGL ES 2 (iOS 4), so I keep the support in my CAEAGLLayer, and not clear in every frame:

eaglLayer.opaque = TRUE; eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithBool:TRUE], kEAGLDrawablePropertyRetainedBacking, kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat, nil]; 

I have a button for saving work in a photo album using the code below. Here is the problem. When this is done, and I start drawing again, the entire buffer will be cleared, and my drawing will start from scratch on a blank screen. Is there any way to prevent this? I would like to continue drawing from the same state that I just saved.

I run the same code to save in OpenGL ES 1, and this problem does not occur there. In addition, this problem is visible only on the iPhone (3GS) device, and not on the simulator. Let me know if you have any ideas. Thanks.

 -(void)saveCurrentScreenToPhotoAlbum { CGRect rect = [[UIScreen mainScreen] bounds]; int width = rect.size.width; int height = rect.size.height; NSInteger myDataLength = width * height * 4; GLubyte *buffer = (GLubyte *) malloc(myDataLength); GLubyte *buffer2 = (GLubyte *) malloc(myDataLength); glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer); for(int y = 0; y <height; y++) { for(int x = 0; x <width * 4; x++) { buffer2[(int)((height - 1 - y) * width * 4 + x)] = buffer[(int)(y * 4 * width + x)]; } } free(buffer); CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, buffer2, myDataLength, releaseData); int bitsPerComponent = 8; int bitsPerPixel = 32; int bytesPerRow = 4 * width; CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB(); CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault; CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault; CGImageRef imageRef = CGImageCreate(width, height, bitsPerComponent, bitsPerPixel, bytesPerRow, colorSpaceRef, bitmapInfo, provider, NULL, NO, renderingIntent); CGColorSpaceRelease(colorSpaceRef); CGDataProviderRelease(provider); UIImage *image = [[UIImage alloc] initWithCGImage:imageRef]; // change this to manual alloc/init instead of autorelease CGImageRelease(imageRef); UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil); // add callback for finish saving } // callback for CGDataProviderCreateWithData void releaseData(void *info, const void *data, size_t dataSize) { free((void*)data); } // callback for UIImageWriteToSavedPhotosAlbum - (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo { [image release]; } 
+6
iphone opengl-es glreadpixels
source share
1 answer

The answer to this question is Anna.

I made another call while this function was running, which led to confusing buffer behavior

+1
source share

All Articles