What is the best way to handle FBOs in OpenGL?

后端 未结 2 1203
隐瞒了意图╮
隐瞒了意图╮ 2020-12-13 11:13

I wonder since a long time what would be the best way to handle OpenGL FrameBuffer Objects (FBO). Switching FBOs can be costly but defining new attachments too.

How

相关标签:
2条回答
  • 2020-12-13 11:33

    As a matter of philosophy, modifying an object state requires that it be re-validated. Instead, simply changing the object binding (that's already valid from the previous frame) should be faster for the driver [1].

    So as a first implementation, I'd go for 1 FBO for each render target (or more precisely, render target set. You usually render to multiple buffers at once).

    That said, nothing beats benchmarking your app against multiple implementations.

    [1] I mention for the driver, because an FBO change can force a GPU flush, depending on architecture. It will introduce bubbles in most cases. So it is definitely something that you don't want to do often. It's more important than optimizing the texture bindings, e.g.

    0 讨论(0)
  • 2020-12-13 11:44

    Updated references:

    • NVIDIA 2016 (?): Use multiple FBOs
    • intel 2016: Use multiple FBOs

    NVIDIA 2005 (probably outdated): The last official performance recommendation by NVIDIA I know is almost five years old. In his GDC presentation, Simon Green recommends the following (slide 29):

    In order of increasing performance:

    1. Multiple FBOs
      • create a separate FBO for each texture you want to render to
      • switch using BindFramebuffer()
      • can be 2x faster than wglMakeCurrent() in beta NVIDIA drivers
    2. Single FBO, multiple texture attachments
      • textures should have same format and dimensions
      • use FramebufferTexture() to switch between textures
    3. Single FBO, multiple texture attachments
      • attach textures to different color attachments
      • use glDrawBuffer() to switch rendering to different color attachments

    In my experience, the second case is really faster than the first (ATI Radeon HD4850, Geforce 8800GT). I've not tried the third case, as it would have complicated my code.

    0 讨论(0)
提交回复
热议问题