Blitting multisampled FBO with multiple color attachments in OpenGL

◇◆丶佛笑我妖孽 提交于 2019-12-11 08:53:49

问题


I have a frame buffer object in an OpenGL program with multiple colour attachments, and am trying to upgrade it to a multisampled FBO.

As I understand it, a multisampled FBO is only able to use render buffers, specifically ones created using glRenderbufferStorageMultisampleEXT. If I want something rendered to this FBO in a texture, I need to create a second FBO with textures for its attachments, then blit the multisampled FBO to the regular FBO using glBlitFramebufferEXT.

The very, very sparse examples I've seen assume a single colour attachment. What do I do when I want to blit multiple colour attachments?


回答1:


From the EXT_framebuffer_blit specification

12) Should we add support for multiple ReadBuffers, so that multiple color buffers may be copied with a single call to BlitFramebuffer?

Resolved: No, we considered this but the behavior is awkward to define and the functionality is of limited use.

From the arb_framebuffer_object specification (which superscedes the EXT_ version)

When the color buffer is transferred, values are taken from the read buffer of the read framebuffer and written to each of the draw buffers of the draw framebuffer, just as with CopyPixels.

So... It's pretty clear that you resolve only from a single color buffer per blit.

To do multiple ones, you need to do a Blit for each buffer, changing your READ_BUFFER for each buffer you want to blit, and select the corresponding draw buffer of the draw framebuffer.




回答2:


You can create a new Fbo and assign the renderbuffer in slot 1 to it at slot 0. Then bind for reading and blit from that to your final destination Fbx.

i.e. An Fbo can be created purely for binding an existing renderbuffer that was written to by another Fbo. An Fbo doesn't actually own the buffers that are connected to it so multiple Fbx can be bound to the same textures/renderbuffers(though not at the same time).

// Render to Fbo0 Fbo0 : [ColorBuffer0, ColorBuffer1, DethBuffer]

// Bind another fbo with ColorBuffer1 at slot 0 for reading Fbo1 : [ColorBuffer1]

// blit Fbo0 ColorBuffer0 > Fbo2 Texture0 Fbo0 : [ColorBuffer0, ColorBuffer1, DethBuffer] => Fbo2 : [Texture0]

//blit Fbo1 ColorBuffer1 (bound at slot0) > Fbo3 Texture1 (bound at slot0) Fbo1 : [ColorBuffer1] => Fbo3 : [Texture1]



来源:https://stackoverflow.com/questions/1773973/blitting-multisampled-fbo-with-multiple-color-attachments-in-opengl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!