• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

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

[复制链接]
菜鸟教程小白 发表于 2022-12-12 16:46:43 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

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



Best Answer-推荐答案


想通了!在调用 glReadPixels() 之前,您必须将解析帧缓冲区绑定(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/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap