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).


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

#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);
}

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.

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

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

Hi all,
I got it working. Thanks all.

Regards,
Mobeen