来自 FBO 的 glReadPixels 因多重采样而失败
我有一个带有颜色和深度附件的 FBO 对象,我对其进行渲染,然后使用 glReadPixels()
读取该对象,并且我正在尝试向其添加多重采样支持。
我为颜色附件和深度附件调用 glRenderbufferStorageMultisampleEXT()
而不是 glRenderbufferStorage()
。 帧缓冲区对象似乎已成功创建并报告为完成。
渲染后,我尝试使用 glReadPixels()
读取它。 当样本数为 0 时,即多重采样禁用,它可以完美工作,我得到了我想要的图像。 当我将样本数设置为其他值(例如 4)时,帧缓冲区仍然构建正常,但 glReadPixels()
失败并显示 INVALID_OPERATION
任何人都知道可能会发生什么这里错了?
编辑:glReadPixels 的代码:
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, ptr);
其中 ptr 指向 width*height uints 数组。
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?
EDIT: The code of glReadPixels:
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, ptr);
where ptr points to an array of width*height uints.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您无法使用 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.
Something like this:
您不能直接使用 glReadPixels 读取多重采样缓冲区,因为它会引发 GL_INVALID_OPERATION 错误。 您需要位块传输到另一个表面,以便 GPU 可以进行下采样。 您可以位图传输到后备缓冲区,但存在“像素所有权测试”的问题。 最好再做一个FBO。 假设您创建了另一个 FBO,现在您想要 blit。 这需要GL_EXT_framebuffer_blit。 通常,当您的驱动程序支持 GL_EXT_framebuffer_multisample 时,它也支持 GL_EXT_framebuffer_blit,例如 nVidia Geforce 8 系列。
来源:GL EXT 帧缓冲区多重采样
You can't read the multisample buffer directly with glReadPixels since it would raise an GL_INVALID_OPERATION error. You need to blit to another surface so that the GPU can do a downsample. You could blit to the backbuffer, but there is the problem of the "pixel owner ship test". It is best to make another FBO. Let's assume you made another FBO and now you want blit. This requires GL_EXT_framebuffer_blit. Typically, when your driver supports GL_EXT_framebuffer_multisample, it also supports GL_EXT_framebuffer_blit, for example the nVidia Geforce 8 series.
Source: GL EXT framebuffer multisample