Results 1 to 5 of 5

Thread: FBO with different size attachments

  1. #1
    Senior Member Frequent Contributor
    Join Date
    Mar 2009
    Location
    Karachi, Pakistan
    Posts
    810

    FBO with different size attachments

    hi all,
    Is it possible to do have a single FBO with different size color attachments like this ( I m trying to render to 8 downscaled color attachments. This setup code does not give me any errors though. For test I have written a simple fragment shader (given later) but the output does not produce the correct result I only see the color of the 0th attachment).
    Code :
    const int MAX_ATTACHMENTS=8;
    glGenTextures(MAX_ATTACHMENTS, attachID);
    glGenFramebuffers(1, &fboID);
    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fboID);
    int width = screen_width;
    int height = screen_height;
    for(int i = 0;i < MAX_ATTACHMENTS;i++) {
       glBindTexture(GL_TEXTURE_2D, attachID[i]);
       glTexParameteri(GL_TEXTURE_2D , GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D , GL_TEXTURE_WRAP_S, GL_CLAMP);
    glTexParameteri(GL_TEXTURE_2D , GL_TEXTURE_WRAP_T, GL_CLAMP);
    glTexImage2D(GL_TEXTURE_2D , 0, GL_RGBA, width, height, 0, GL_RGBA, GL_FLOAT, NULL);
    width = width >> 1;
    height = height >> 1;
    glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0+i, GL_TEXTURE_2D, attachID[i], 0);
    }
    GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
    if (status == GL_FRAMEBUFFER_COMPLETE_EXT ) {
    printf("FBO setup succeeded.");
    } else {
    printf("Problem with FBO setup.");
    }
    and here is the fragment shader code
    Code :
    #version 130
    void main() {
    gl_FragData[0] = vec4(1,0,0,1);
    gl_FragData[1] = vec4(0,1,0,1);
    gl_FragData[2] = vec4(0,0,1,1);
    gl_FragData[3] = vec4(1,1,0,1);
    gl_FragData[4] = vec4(1,0,1,1);
    gl_FragData[5] = vec4(0,1,1,1);
    gl_FragData[6] = vec4(0.5,1,1,1);
    gl_FragData[7] = vec4(0.5,1,0.5,1);
    }
    Regards,
    Mobeen

  2. #2
    Member Newbie
    Join Date
    Oct 2009
    Posts
    34

    Re: FBO with different size attachments

    Hi,

    the specification says (OpenGL 3.3 Core Profile Specification (updated March 11, 2010) page 230) that:

    If the attachment sizes are not all identical, rendering will be limited to the
    largest area that can fit in all of the attachments (an intersection of rectangles
    having a lower left of (0; 0) and an upper right of (width; height) for each
    attachment).
    However, that's only half of your problem. I don't know why it produces only 1 color for all attachments. But why are you checking the framebuffer status with the EXT function if previously the FBO is managed by the core functions? By the way the GL_EXT_FRAMEBUFFER extension doesn't support different-size color attachments.

  3. #3
    Senior Member Regular Contributor
    Join Date
    Mar 2009
    Posts
    153

    Re: FBO with different size attachments

    You have to use glDrawBuffers command to say to which draw buffers you want to render. By default rendering uses only draw buffer 0.

  4. #4
    Senior Member Frequent Contributor
    Join Date
    Mar 2009
    Location
    Karachi, Pakistan
    Posts
    810

    Re: FBO with different size attachments

    Thanks for your replies. To make it simple I am keeping the same width /height as the screen size at the moment. I have modified the fbo code to be more 3.3 compliant. I will get back after I make the changes you guys have mentioned.

    Thanks.
    Mobeen
    Regards,
    Mobeen

  5. #5
    Senior Member Frequent Contributor
    Join Date
    Mar 2009
    Location
    Karachi, Pakistan
    Posts
    810

    Re: FBO with different size attachments

    Hi all,
    I got it working. Thanks all.

    Regards,
    Mobeen
    Regards,
    Mobeen

Similar Threads

  1. Framebuffer depth attachments
    By Jnanadeva in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 12-21-2013, 02:25 AM
  2. FBO attachments with different shaders
    By miujin in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 03-10-2011, 03:47 AM
  3. fbo with attachments of different formats
    By Vexator in forum OpenGL: Advanced Coding
    Replies: 12
    Last Post: 10-14-2007, 06:59 PM
  4. Proper use of FBO attachments
    By Tiberius in forum OpenGL: Advanced Coding
    Replies: 5
    Last Post: 01-17-2006, 06:48 PM
  5. Color attachments in FBO
    By Zulfiqar Malik in forum OpenGL: Advanced Coding
    Replies: 6
    Last Post: 09-08-2005, 01:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean