0

When calling glBindFramebuffer(GLenum target, GLuint framebuffer);, I know that target can either be GL_READ_FRAMEBUFFER, GL_DRAW_FRAMEBUFFER, or GL_FRAMEBUFFER which is both.

However, when I attach texture or Renderbuffer objects to the framebuffer, I must provide a binding target as well.

My question is, when I attach anything to a framebuffer through binding target target, does it stay constant?

This means when a renderbuffer is attached to a framebuffer through binding point GL_DRAW_FRAMEBUFFER, it will always be the target of drawing operations, and if I want that renderbuffer to be read from then I must call glFramebufferRenderbuffer() again with target set to GL_READ_FRAMEBUFFER this time.

Can anyone confirm this? I'm asking because I'm trying to encapsulate all these in C++ classes.

1 Answer 1

1

This means when a renderbuffer is attached to a framebuffer through binding point GL_DRAW_FRAMEBUFFER, it will always be the target of drawing operations, and if I want that renderbuffer to be read from then I must call glFramebufferRenderbuffer() again with target set to GL_READ_FRAMEBUFFER this time.

No. The attachments are per-FBO state, they have nothing to do with the binding point the FBO is bound.

An object may be bound to semantically different binding targets, but the object itself defines all of it's state. For example, you might load data to an buffer which is bound as GL_PIXEL_UNPACK_BUFFER, and later use this data as vertex attributes by binding it as GL_VERTEX_ARRAY_BUFFER.

However, when I attach texture or Renderbuffer objects to the framebuffer, I must provide a binding target as well.

Well, that is beacuse traditional GL uses bind to modify semantics. If you want to manipulate the state of any object, you must bind it to some target (matching the object type, of course), and all state setting functions will reference the object indirectly by addressing the target. This does not meen that the modifications have anything to do with the binding point.

Bind-to-modify his has been an often criticised principle of OpenGL. For a long time, the EXT_direct_state_access extension had been implemented by some vendors, to address this issue. It provides functions to directly reference the objects instead of indirectly using the binding points. In your example, glNamedFramebufferRenderbufferEXT will allow you to directly attach a renderbuffer without binding the FBO first.

Finally with OpenGL 4.5, direct state access was promoted a core feature of OpenGL, and the ARB_direct_state_access was created to allow implementors to provide the final API (which is different from the EXT version in some aspects) for earlier GL versions. Now there is the official glNamedFramebufferRenderbuffer() function.

Sign up to request clarification or add additional context in comments.

5 Comments

I understand the bind to modify semantics, but I'm still confused about these framebuffer objects. When I call glFramebufferRenderbuffer(), it doesn't matter if I set target to GL_READ_FRAMEBUFFER or GL_DRAW_FRAMEBUFFER, as long as it's the bound one? (by glBindFramebuffer())
Well, GL_FRAMEBUFFER binding target is just a shortcut to bind it to both the read and the draw framebuffer. As a result, it will be bound at both targets, and modifying it via any of the tagetes will work, as the same object is referenced.
I see. A little off-topic question: it seems like I can call glDeleteRenderbuffers() on my Renderbuffer object after it has been attached to a framebuffer, and nothing bad happens. Is this normal? Would you advice to do it?
@Pilpel: Yes, it is specified that way. You only lose the object name (and a further call to the glGen*() functions might reuse that name), so you can't reference this object any more after the deletion. The object itself will be kept around as long as it is still referenced by some container object (the FBO in this case).
When you delete a renderbuffer, it is automatically detached from an FBO that is currently bound, but not from other FBOs. In the second case, you can get into really weird situations where you have multiple objects with the same name, because the name can be reused while the original object still exists. I would strongly discourage calling glDeleteRenderbuffers() for renderbuffers that you're still using.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.