在使用深度缓冲和抗锯齿技术时,通过glreadpixel()读取数据时出现问题

我想用glreadpixel()捕捉我的游戏画面。 它也可以在2g iphone上使用ios版本3.1.1在模拟器上正常工作。 但与iOS 4.2.1版本的iPad没有。 我来了解这个问题。 对于特定设备(ipad)上面的ios版本4.0,我们绑定深度缓冲区并使用抗锯齿技术。 当我们使用opengl的glreadpixel()从帧缓冲区捕获数据返回目标缓冲区中的所有0 …

如果我们不把深度缓冲区绑定到帧缓冲区,并且不使用抗锯齿技术,它就可以正常工作。

我使用的代码是:

CGRect screenBounds = [[UIScreen mainScreen] bounds];

int backingWidth = screenBounds.size.width; int backingHeight =screenBounds.size.height; NSLog(@"width : %f Height : %f",screenBounds.size.width,screenBounds.size.height); CGSize esize = CGSizeMake(screenBounds.size.width, screenBounds.size.height); NSInteger myDataLength = esize.width * esize.height * 4; GLuint *buffer = (GLuint *) malloc(myDataLength); glReadPixels(0, 0, esize.width, esize.height, GL_RGBA, GL_UNSIGNED_BYTE, buffer); for(int y = 0; y < backingHeight / 2; y++) { for(int xt = 0; xt < backingWidth; xt++) { GLuint top = buffer[y * backingWidth + xt]; GLuint bottom = buffer[(backingHeight - 1 - y) * backingWidth + xt]; buffer[(backingHeight - 1 - y) * backingWidth + xt] = top; buffer[y * backingWidth + xt] = bottom; } } CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, buffer, myDataLength, releaseScreenshotData); const int bitsPerComponent = 8; const int bitsPerPixel = 4 * bitsPerComponent; const int bytesPerRow = 4 * backingWidth; CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB(); CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault; CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault; CGImageRef imageRef = CGImageCreate(backingWidth,backingHeight, bitsPerComponent, bitsPerPixel, bytesPerRow, colorSpaceRef, bitmapInfo, provider, NULL, NO, renderingIntent); CGColorSpaceRelease(colorSpaceRef); CGDataProviderRelease(provider); /* UIImage *myImage = [UIImage imageWithCGImage:imageRef]; CGImageRelease(imageRef); [snap setImage:myImage]; [self addSubview:snap];*/ 

任何想法如何在使用glreadpixel()或任何其他类似的函数在操作中包含抗锯齿的深度信息?

弄清楚了! 在调用glReadPixels()之前,必须将resolve-framebuffer绑定回GL_FRAMEBUFFER

 glBindFramebuffer(GL_FRAMEBUFFER, resolveFramebuffer); glBindRenderbuffer(GL_RENDERBUFFER, colorRenderbuffer); glReadPixels(xpos, ypos, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixelByteArray); glBindFramebuffer(GL_FRAMEBUFFER, sampleFrameBuffer); 

确保在呈现下一帧之前将样本帧缓冲区绑定为GL_FRAMEBUFFER,但默认的Apple模板已经这样做了。

这不会解决你的问题,但将有助于定制你的search。 由于您使用OpenGL ESglReadPixels()将无法读取深度缓冲区。 我目前与我的应用程序有相同的function问题。