Reputation: 3416
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.
Upvotes: 0
Views: 788
Reputation: 45362
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.
Upvotes: 1