I'm developing an OpenGL application and I need to find how many framebuffer color attachments are supported. Is there a way to query OpenGL for that value?
The minimum value for both these limits is 8 in OpenGL 3.
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).
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.
Renderbuffer is simply a data storage object containing a single image of a renderable internal format. It is used to store OpenGL logical buffers that do not have corresponding texture format, such as stencil or depth buffer.
There are two values that can potentially limit how many attachments you can use:
GL_MAX_COLOR_ATTACHMENTS
specifies how many color attachment points an FBO has. In other words, it correspond to the maximum value n
you can use when specifying attachment points with GL_COLOR_ATTACHMENTn
. This will limit how many color textures/renderbuffers can be attached to the FBO concurrently. You can get this limit with:
GLint maxAttach = 0;
glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, &maxAttach);
GL_MAX_DRAW_BUFFERS
specifies how many buffers you can draw to at the same time. It is the maximum number of buffers you're allowed to pass to glDrawBuffers()
, and also the maximum number of outputs allowed in fragment shaders. You can get this limit with:
GLint maxDrawBuf = 0;
glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuf);
These two values do not have to be the same. So it is possible that you can have a certain number of attachments, but you can't draw to all of them at the same time.
The minimum value for both these limits is 8 in OpenGL 3.x and higher, up to and including the current 4.5 spec.
You can get it by querying
int maxColorAttachments;
glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, &maxColorAttachments);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With