来自FBO的glReadPixels因多重采样而失败

sho*_*osh 7 opengl fbo multisampling

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

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

编辑:glReadPixels的代码:

glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, ptr);
Run Code Online (Sandbox Code Playgroud)

其中ptr指向一个宽度为*height uints的数组.

Ste*_*rds 24

我不认为您可以使用glReadPixels()读取多重采样的FBO.您需要从多重采样FBO blit到普通FBO,绑定普通FBO,然后从普通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);
Run Code Online (Sandbox Code Playgroud)

  • 在这里(滚动到底部):http://www.opengl.org/wiki/GL_EXT_framebuffer_multisample (2认同)