您不能直接使用 glReadPixels 读取多重采样缓冲区,因为它会引发 GL_INVALID_OPERATION 错误。您需要 blit 到另一个表面,以便 GPU 可以进行下采样。您可以对后台缓冲区进行 blit,但存在“像素所有者船舶测试”的问题。最好再做一个FBO。假设您制作了另一个 FBO,现在您想要 blit。这需要 GL_EXT_framebuffer_blit。通常,当您的驱动程序支持 GL_EXT_framebuffer_multisample 时,它也支持 GL_EXT_framebuffer_blit,例如 nVidia Geforce 8 系列。
//Bind the MS FBO
glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, multisample_fboID);
//Bind the standard FBO
glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, fboID);
//Let's say I want to copy the entire surface
//Let's say I only want to copy the color buffer only
//Let's say I don't need the GPU to do filtering since both surfaces have the same dimension
glBlitFramebufferEXT(0, 0, width, height, 0, 0, width, height, GL_COLOR_BUFFER_BIT, GL_NEAREST);
//--------------------
//Bind the standard FBO for reading
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboID);
glReadPixels(0, 0, width, height, GL_BGRA, GL_UNSIGNED_BYTE, pixels);
来源:GL EXT 帧缓冲多样本