PDA

View Full Version : Multiple framebuffer objects



expliced
01-25-2012, 04:12 PM
Hi guy!

I have a few questions about fbos, i've tried to search but did not find what is was looking for.

At the moment i am trying to use 2 fbos. I have bound two textures to the first fbo at GL_COLOR_ATTACHMENT0 and GL_COLOR_ATTACHMENT1. But when i bind a texture at GL_COLOR_ATTACHMENT0 in the other fbo the rendering goes blank.

Is this supposed to happened? Then i bind the last texture to GL_COLOR_ATTACHMENT2 in the second fbo the rendering is not affected, but as i have understood, the fbos should be separate and not display this kind of behaviour.

mobeen
01-25-2012, 05:13 PM
Why are you changing the attachment during rendering? Normally, you would assign color attachments to the fbo at initialization and then when rendering, you would redirect the rendering through glDrawBuffers function passing it the attachment you want to draw to.

To be of more help, could u show how you are doing it currently?

expliced
01-25-2012, 05:40 PM
Sorry for not being clear enough.

I am not changing the attachments during rendering, i do all the assigning at the fbo initiations, and my problem still persists.

My initiation code for the first fbo:


glGenFramebuffers(1, &frameBufferMainId);
glBindFramebuffer(GL_FRAMEBUFFER, frameBufferMainId);

GLuint depthBuffer;

glGenRenderbuffers(1, &depthBuffer);
glBindRenderbuffer(GL_RENDERBUFFER, depthBuffer);
glRenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH_COM PONENT,1000,800);

glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_ ATTACHMENT,GL_RENDERBUFFER, depthBuffer);


glGenTextures(1,&mainColorTextureId);

glBindTexture(GL_TEXTURE_2D,mainColorTextureId);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB32F,1000,800,0, GL_RGB,GL_UNSIGNED_BYTE,NULL);

glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATT ACHMENT0,GL_TEXTURE_2D,mainColorTextureId,0);

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);


glGenTextures(1,&mainNormalTextureId);

glBindTexture(GL_TEXTURE_2D,mainNormalTextureId);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB32F,1000,800,0, GL_RGB,GL_FLOAT,NULL);

glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATT ACHMENT1,GL_TEXTURE_2D,mainNormalTextureId,0);

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);

//i attach 2 more textures, but the code is almost identical to the code above, so no point in showing it


And the initiation code for the second fbo:



glGenBuffers(1, &frameBufferSubId);
glBindFramebuffer(GL_FRAMEBUFFER, frameBufferSubId);

glGenTextures(1,&subTextureId);

glBindTexture(GL_TEXTURE_2D,subColorTextureId);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,1000,800,0,GL_ RGB,GL_UNSIGNED_BYTE,NULL);

//if i remove this line...
glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATT ACHMENT0,GL_TEXTURE_2D,subTextureId,0);

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);


glGenTextures(1,&subAmbientOcclusionId);

glBindTexture(GL_TEXTURE_2D,subAmbientOcclusionTex tureId);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,1000,800,0,GL_ RGB,GL_UNSIGNED_BYTE,NULL);

//...and this line the rendering seems to be doing ok
glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATT ACHMENT1,GL_TEXTURE_2D,subAmbientOcclusionTextureI d,0);

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);

Dan Bartlett
01-25-2012, 07:26 PM
think you have a typo:



glGenBuffers(1, &frameBufferSubId);

should be:


glGenFramebuffers(1, &frameBufferSubId);

expliced
01-26-2012, 03:56 AM
Irl nerdrage. That was the problem! I guess thats what i get for not sleeping properly. Thanks for the help!