在 OpenGL 中处理 FBO 的最佳方法是什么? [英] What is the best way to handle FBOs in OpenGL?

查看:42
本文介绍了在 OpenGL 中处理 FBO 的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很久以来就想知道处理 OpenGL FrameBuffer 对象 (FBO) 的最佳方法是什么.切换 FBO 的成本可能很高,但也需要定义新的附件.

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.

你是如何快速做到的?

我在这三个之间犹豫:

  • 1 个 FBO 用于一切,更改附件但不要在 FBO 之间切换

  • 1 FBO for everything, change attachment but don't switch between FBOs

为渲染路径中的每个渲染目标(大小 + 格式)提供 1 个 FBO.这意味着我将为类似的渲染目标重用相同的 FBO.但是这样自定义模糊会花费 4 个以上的 FBO.

1 FBO for each render target (size + format) in the rendering path. That means i will reuse the same FBO for similar render targets. But this way a custom blur would cost 4+ FBOs.

每个渲染目标 1 个 FBO,只设置一次附件,然后在 FBO 之间切换

1 FBO for each render target, set attachments only once and then switch between FBOs

另外,我是否应该尽量减少 FBO 开关的数量(就像我尽量减少纹理绑定的数量)?

Also, should I minimize the number of FBO switches (like I minimize the number of texture bindings) ?

推荐答案

更新参考:

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

NVIDIA 2005(可能已经过时):我所知道的 NVIDIA 上一次官方性能推荐已经快五年了.在他的 GDC 演示文稿中,Simon Green 建议以下(幻灯片 29):

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):

按照提高性能的顺序:

  1. 多个 FBO
    • 为要渲染的每个纹理创建一个单独的 FBO
    • 使用BindFramebuffer()
    • 切换
    • 在测试版 NVIDIA 驱动程序中比 wglMakeCurrent() 快 2 倍
  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
  • 纹理应该具有相同的格式和尺寸
  • 使用FramebufferTexture()切换纹理
  • 将纹理附加到不同颜色的附件
  • 使用glDrawBuffer()切换渲染到不同颜色的附件
  • attach textures to different color attachments
  • use glDrawBuffer() to switch rendering to different color attachments

根据我的经验,第二种情况确实比第一种情况快(ATI Radeon HD4850、Geforce 8800GT).我没有尝试过第三种情况,因为它会使我的代码复杂化.

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.

这篇关于在 OpenGL 中处理 FBO 的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆