Search code examples
openglframebufferfbo

Re-create FBO (frame buffer object) each frame


I would like to create FBO but that will be "shared" between all contexts. Because an FBO is container and can not be "shared", but only its buffers, I thought to do the follow:

  1. Create an object FBODescriptor that is a descriptor of the desired FBO, it also contains opengl buffers that are shared.

  2. At each frame, and in any context that is active, I create the FBO (so it is available for the current context), attach to it the buffers, and delete the FBO container after the rendering.

In this way, I have a desired FBO that is available for any context.

My assumption is that because the resources buffers are existing and no need to re-create them each frame but only the FBO container, it doesn't have a meaningful penalty.

May it works?


Solution

  • This will work, in the sense that it will function. But it is not in any way good. Indeed, any solution you come up with that results in "create an OpenGL object every frame" should be immediately discarded. Or at least considered highly suspect.

    FBOs often do a lot of validation of their state. This is not cheap. Indeed, the recommendation has often been to not modify FBOs at all after you finish making them. Don't attach new images, don't remove them, anything. This would obviously include deleting and recreating them.

    If you want to propagate changes to framebuffers across contexts, then you should do it in a way where you only modify or recreate FBOs when you need to. That is, when they actually change.