PDA

View Full Version : Duplicate a Framebuffer including all attachments + specifics



Helifax
05-10-2015, 05:47 AM
Hello all,

First time posting here:)
I am working on a project currently and I am having some trouble with "duplicating" a framebuffer.
To be mode exact:

- The original APP generates a framebuffer (I don't know what type of textures or format in which they are).
- I am interested that at some point when the original code does something like:

glBindFrameBuffer(GL_FRAMEBUFFER, X);
glDrawArrays()
etc

To do something like:

glBindFrameBuffer(GL_FRAMEBUFFER, X);
glDrawArrays()

// Get all the info from GL_FRAMEBUFFER X (including attachements)
glGenFramebuffer(my_framebuffer);
// Duplicate everything
// Attach textures, etc
glBindFrameBuffer(GL_FRAMEBUFFER, my_framebuffer); // the copy of the original framebuffer
glDrawArrays()
...

Now I've been looking about how can I "query" and obtain all the formats of a framebuffer for sometime and wasn't able to do this.
Anyone has any ideas on how to do this ?:)

Thank you in advance!

PS: Framebuffer is not zero(0) screen framebuffer but a different, generated, one.

Alfonse Reinheart
05-10-2015, 09:04 AM
Framebuffers do not have "formats". Framebuffers have images attached to them (either from a texture or renderbuffer). It is those images which have formats. You can detect what kind of image is attached and fetch the attached texture (https://www.opengl.org/wiki/Texture)/renderbuffer (https://www.opengl.org/wiki/Renderbuffer_Object). But it is only from that image that you can get the format.

Now, you can in fact query properties of the attached image through the framebuffer (https://www.opengl.org/wiki/GLAPI/glGetFramebufferAttachmentParameter). But that won't be very useful for actually making an appropriate texture/renderbuffer for your copy. You need the actual OpenGL internal format (https://www.opengl.org/wiki/Image Format), which you can query from textures (https://www.opengl.org/wiki/GLAPI/glGetTexLevelParameter) and renderbuffers (https://www.opengl.org/wiki/GLAPI/glGetRenderbufferParameter).

arekkusu
05-10-2015, 11:54 AM
But that won't be very useful
There is no GL API to query the target of an FBO attachment, so you'll have to play a guessing game (perturbing the error state) between GetFramebufferAttachmentParameter and GetTexLevelParameter.

Also if the user is binding FBO zero, you'll have to look outside the GL API to figure out the dimensions of the system drawable.

Alfonse Reinheart
05-10-2015, 02:04 PM
There is no GL API to query the target of an FBO attachment, so you'll have to play a guessing game (perturbing the error state) between GetFramebufferAttachmentParameter and GetTexLevelParameter.

What you're saying is only true if you are referring to the target of a texture that is attached to the framebuffer. You can query the type of attachment (renderbuffer, texture, or none) just fine. Once you have the texture object, the problem is knowing the target so that you can query state from it and duplicate it.

To figure that one out, you have to call glBindTexture with every possible texture target, checking for errors after each one. The one that doesn't fail is the right one.

Helifax
05-11-2015, 02:48 AM
Sorry for the late reply:)

First I want to say a BIG thank you everyone for replying. I had a feeling this was the case. I just hoped there was a mechanism that looks closer to the DX Com system which could basically give the "whole" copy/info of a FBO.

In any case, I used your advice and was able to get all the information from a FB and was able to duplicate it (Attached Textures and Renderbuffers).

Big thank you again!