Search code examples
opengl-esfbo

glBindFramebuffer is causing performance drop in OpenGLES


i am doing rendering in 3 FBOs so i have 3 passes. while rendering to 3rd FBO when I call glBindFramebuffer() its causing my application to run at lower fps. If I just use 3rd FBO for rendering in all 3 passes, i get same fps but if i use 1st FBO to render in all 3 passes I get higher fps. what might be the reason for this behavior?


Solution

  • There is often an unintuitive cost in ES to unbinding a framebuffer because of the complexity involved in preserving the contents for the next binding. However you often don't actually want the contents preserved — e.g. for the buffer the user can actually see you'll almost always clear, draw geometry, present, end drawing loop; clear, draw geometry, present, end drawing loop; etc. So there's no benefit to retaining the contents of the buffer for the next binding. Once it's been presented you're never going to look at the contents again.

    Under ES 3 you can signal that using glInvalidateFramebuffer; if your GPU and platform supports it, use EXT_discard_framebuffer under ES 2.

    This guess has assumed, of course, that when you're rendering to your third rather than your first object, that implies changing the binding more often.

    A second guess: if your additional framebuffers are for rendering-to-texture whereas your first is whatever the system did to bridge you to the screen then there's obviously a potential performance difference there because the output target may not be of the same format.