gpt4 book ai didi

ios - 使用深度缓冲区和抗锯齿技术时 glreadpixel() 读取数据时出现问题

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:51:50 26 4
gpt4 key购买 nike

我想使用 glreadpixel() 捕获我的游戏屏幕。它在 ios 版本 3.1.1 的 2g iphone 上也可以在模拟器上正常工作。但在 ios 版本 4.2.1 的 ipad 上它没有。我开始知道这个问题。对于特定设备 (ipad) 上的 ios 4.0 版我们绑定(bind)深度缓冲区并使用抗锯齿技术。当我们使用 opengl 的 glreadpixel() 从帧缓冲区捕获数据时,在目标缓冲区中返回全 0 ...

如果我们不将深度缓冲区绑定(bind)到帧缓冲区并且不使用抗锯齿技术,它工作正常。

我使用的代码是:-

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 中的任何其他类似函数时将深度信息包含在抗锯齿中吗?

最佳答案

想通了!在调用 glReadPixels() 之前,您必须将 resolve-framebuffer 绑定(bind)回 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);

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

关于ios - 使用深度缓冲区和抗锯齿技术时 glreadpixel() 读取数据时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6731385/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com