来自FBO的glReadPixels多次采样失败 [英] glReadPixels from FBO fails with multisampling

查看:92
本文介绍了来自FBO的glReadPixels多次采样失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有颜色和深度附件的FBO对象,我将该对象渲染为颜色,然后使用glReadPixels()读取,我正尝试向其添加多采样支持.
而不是glRenderbufferStorage(),我为颜色附件和深度附件都调用了glRenderbufferStorageMultisampleEXT().帧缓冲区对象似乎已成功创建,并报告为已完成.
渲染后,我尝试使用glReadPixels()从中读取.当样本数量为0时,即多重采样禁用它可以正常工作,并且我得到了想要的图像.当我将样本数量设置为其他值(例如4)时,帧缓冲区仍然可以正常构建,但glReadPixels()失败,并显示INVALID_OPERATION

I have an FBO object with a color and depth attachment which I render to and then read from using glReadPixels() and I'm trying to add to it multisampling support.
Instead of glRenderbufferStorage() I'm calling glRenderbufferStorageMultisampleEXT() for both the color attachment and the depth attachment. The frame buffer object seem to have been created successfully and is reported as complete.
After rendering I'm trying to read from it with glReadPixels(). When the number of samples is 0 i.e. multisampling disables it works perfectly and I get the image I want. when I set the number of samples to something else, say 4, the frame buffer is still constructed OK but glReadPixels() fails with an INVALID_OPERATION

任何人都知道这里可能有什么问题吗?

Anyone have an idea what could be wrong here?

glReadPixels的代码:

The code of glReadPixels:

glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, ptr);

其中ptr指向一个宽度*高度单位的数组.

where ptr points to an array of width*height uints.

推荐答案

我认为您无法使用glReadPixels()从多重采样的FBO中读取内容.您需要从多次采样的FBO中剔除到正常的FBO,绑定正常的FBO,然后从正常的FBO中读取像素.

I don't think you can read from a multisampled FBO with glReadPixels(). You need to blit from the multisampled FBO to a normal FBO, bind the normal FBO, and then read the pixels from the normal FBO.

类似这样的东西:

// Bind the multisampled FBO for reading
glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, my_multisample_fbo);
// Bind the normal FBO for drawing
glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, my_fbo);
// Blit the multisampled FBO to the normal FBO
glBlitFramebufferEXT(0, 0, width, height, 0, 0, width, height, GL_COLOR_BUFFER_BIT, GL_NEAREST);
//Bind the normal FBO for reading
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, my_fbo);
// Read the pixels!
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);

这篇关于来自FBO的glReadPixels多次采样失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆