我有一个带有颜色和深度附件的 FBO 对象,我将其渲染到然后使用 glReadPixels()
读取我正在尝试添加多重采样支持。
而不是 glRenderbufferStorage()
我调用 glRenderbufferStorageMultisampleEXT()
对于颜色附件和深度附件。帧缓冲区对象似乎已成功创建并报告为完整。
渲染后,我尝试使用 glReadPixels()
从中读取.当样本数为 0 时,即禁用多重采样时,它工作得很好,我得到了我想要的图像。当我将样本数设置为其他值时,比如 4,帧缓冲区仍然可以正常构建,但是 glReadPixels()
失败并返回 INVALID_OPERATION
有人知道这里可能出了什么问题吗?
编辑: glReadPixels 的代码:
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, ptr);
其中 ptr 指向宽度*高度单位的数组。
最佳答案
我认为您无法使用 glReadPixels() 从多采样 FBO 中读取数据。您需要从多重采样 FBO 到普通 FBO,绑定(bind)普通 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);
关于opengl - 来自 FBO 的 glReadPixels 因多重采样而失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/765434/