Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 304
ammar26 Avatar asked Dec 13 '14 14:12

ammar26


People also ask

What are frame buffers in OpenGL?

A Framebuffer is a collection of buffers that can be used as the destination for rendering. OpenGL has two kinds of framebuffers: the Default Framebuffer, which is provided by the OpenGL Context; and user-created framebuffers called Framebuffer Objects (FBOs).

What is the default framebuffer?

The Default Framebuffer is the Framebuffer that OpenGL is created with. It is created along with the OpenGL Context. Like Framebuffer Objects, the default framebuffer is a series of images. Unlike FBOs, one of these images usually represents what you actually see on some part of your screen.

Where is the frame buffer?

A framebuffer (frame buffer, or sometimes framestore) is a portion of random-access memory (RAM) containing a bitmap that drives a video display. It is a memory buffer containing data representing all the pixels in a complete video frame. Modern video cards contain framebuffer circuitry in their cores.

What is a framebuffer attachment?

Framebuffers represent a collection of memory attachments that are used by a render pass instance. Examples of these memory attachments include the color image buffers and depth buffer that we created in previous samples. A framebuffer provides the attachments that a render pass needs while rendering.


2 Answers

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".

like image 187
Reto Koradi Avatar answered Sep 18 '22 01:09

Reto Koradi


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

like image 21
ratchet freak Avatar answered Sep 21 '22 01:09

ratchet freak