Get maximum number of framebuffer color attachments?
Asked Answered
E

2

10

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?

Effie answered 17/4, 2015 at 19:35 Comment(0)
L
18

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.

Leonardoleoncavallo answered 18/4, 2015 at 3:27 Comment(0)
E
5

You can get it by querying

int maxColorAttachments;
glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, &maxColorAttachments);
Effie answered 17/4, 2015 at 19:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.