How to check which frame buffer object is currently linked in OpenGL?

I work with OpenGL buffer objects. I created a frame buffer object with 2 color textures and a depth texture.

I use

glBindFramebuffer(GL_READ_FRAMEBUFFER, ID); 

To link my framebuffer, but on the console I get this warning

 Redundant State change in glBindFramebuffer call, FBO 1 already bound 

How to check which framebuffers are already connected? I mean, what OpenGL function allows me to check the identifier of an already linked framebuffer so that I can prevent excessive binding.

+5
source share
2 answers

Hold the horses ... Yes, you can get the draw tied at the moment and read the FBOs with:

 GLint drawFboId = 0, readFboId = 0; glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &drawFboId); glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &readFboId); 

and for backward compatibility, GL_FRAMEBUFFER_BINDING equivalent to GL_DRAW_FRAMEBUFFER_BINDING :

 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &drawFboId); 

But for the scenario you are describing, you most likely do not want to use this one . A diagnostic message tells you that you are making an excessive state change. But asking for the current state to compare it to your new value is likely much worse.

glGet*() calls can cause a certain level of synchronization and be quite detrimental to performance. They should usually be avoided in critical parts of your code.

You have two options that are likely to be better than you planned:

  • Ignore diagnostic message. The driver is likely to detect a redundant change and in any case avoid unnecessary work. And he can do it much more efficiently than a solution that includes an application that calls glGet*() calls.
  • Keep track of the latest related FBOs in your own code so you can filter out redundant changes without using glGet*() calls.

In any case, what you had in mind would be like the notorious "extinguishing fire with gasoline."

+13
source

This is just glGetIntegerv(GL_FRAMEBUFFER_BINDING, &result);

+5
source

Source: https://habr.com/ru/post/1208952/


All Articles