How to check which Frame Buffer Object is currently bound in OpenGL?
Asked Answered
C

2

16

I'm working with OpenGL Frame Buffer Objects. I have created a Frame Buffer Object with 2 color textures and a depth texture.

I'm using

glBindFramebuffer(GL_READ_FRAMEBUFFER, ID);

To bind my framebuffer, but on console i'm getting this warning

Redundant State change in glBindFramebuffer call, FBO 1 already bound

How can I check which of my framebuffers is already bound? I mean which OpenGL function allows me to check the ID of the already bound framebuffer so that I can prevent redundant binding.

Chaconne answered 13/12, 2014 at 14:28 Comment(0)
P
30

Hold your horses... Yes, you can get the currently bound draw and read FBOs with:

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

and for backwards compatibility, GL_FRAMEBUFFER_BINDING is equivalent to GL_DRAW_FRAMEBUFFER_BINDING:

glGetIntegerv(GL_FRAMEBUFFER_BINDING, &drawFboId);

But for the scenario you describe, you most likely do not want to use this. The diagnostic message tells you that you're making a redundant state change. But querying the current state to compare it with your new value is most likely much worse.

glGet*() calls can cause a certain level of synchronization, and be fairly harmful to performance. They should generally be avoided in performance critical parts of your code.

You have two options that are both likely to be better than what you were planning to do:

  1. Ignore the diagnostic message. The driver will probably detect the redundant change, and avoid unnecessary work anyway. And it can do that much more efficiently than a solution that involves the app making glGet*() calls.
  2. Keep track of the most recently bound FBO in your own code, so that you can filter out redundant changes without using any glGet*() calls.

In any case, what you had in mind would be like the proverbial "putting out fire with gasoline".

Picro answered 13/12, 2014 at 18:38 Comment(0)
R
12

It's simply glGetIntegerv(GL_FRAMEBUFFER_BINDING, &result);

Roughandtumble answered 13/12, 2014 at 14:32 Comment(5)
glGetIntergerv is undefinedChaconne
@ammar26: Then your OpenGL implementation is broken :-\ That's an OpenGL 1.0 function. You probably just spelled it wrong though, it's glGetIntegervIllegalize
Im running OpenGL 4.2 with GLUT and Gl3wChaconne
@ammar26: The function has been available and is still in all OpenGL versions and profiles.Intermezzo
Just FYI for future readers, he spelt it wrong. "glGetIntergerv is undefined", that's because it's spelt Integer not Interger - you accidentally added an extra 'r'.Windowsill

© 2022 - 2024 — McMap. All rights reserved.