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

时间:2011-07-18 10:13:25

标签: ios opengl-es glreadpixels

我想使用glreadpixel()捕捉我的游戏画面。 它在ig版本3.1.1的2g iphone上也可以在模拟器上正常工作。 但在ipad版本4.2.1的ipad上它没有。我开始知道这个问题。适用于特定设备上的ios 4.0版(ipad) 我们绑定深度缓冲区并使用抗锯齿技术。当我们使用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()或opegl es中的任何其他类似函数时,是否知道如何使用抗锯齿来包含深度信息?

2 个答案:

答案 0 :(得分:4)

想出来!在调用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);

确保在渲染下一帧之前将sample-framebuffer绑定为GL_FRAMEBUFFER,但默认的Apple模板已经执行此操作。

答案 1 :(得分:0)

这不会解决您的问题,但会帮助您定制搜索。由于您使用的是OpenGL- ES glReadPixels()将无法读取深度缓冲区。我目前在申请时遇到了同样的功能问题。