FBO and MRT problem

My basic FBO setup works well for ONE color attachment, but when I add a second color attachment or call glDrawBuffers() I get a INVALID_FRAMEBUFFER_OPERATION error.
Any Iideas?

		glBindFramebuffer(GL_FRAMEBUFFER_EXT, m_fb);
		glFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_RECTANGLE_ARB, m_tex[0], 0);
		glFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_RECTANGLE_ARB, m_tex[1], 0);

		GLenum buffers[] = {GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT};
		glDrawBuffers(2, buffers);

The two textures are the same size and format and are not previously bound…

This is still puzzeling me!

If someone could recommend a FBO demo with multiple render targets with src I would greatly appreciate it.

Thanks

I believe you are passing wrong arguments in glDrawBuffers. Have a look at the documentation for glDrawBuffers here.

Hope this helps.

oh btw, this is how you should do it

  
// get the current draw buffers
glGetIntegerv(GL_DRAW_BUFFER, &m_drawBuffer);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_uiFrameBufferID);

// singce you want to render to your targets, set the default to none
glDrawBuffer(GL_NONE);

glFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_RECTANGLE_ARB, m_tex[0], 0);
glFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_RECTANGLE_ARB, m_tex[1], 0);

// Do your drawing here...

//finally restore your original DrawBuffers
glDrawBuffer(m_drawBuffer);

Fastian, spreading false information does not help either. Please read the FBO specs before ( FBO specs ).

def, you are on the right track. I cannot tell you why you get INVALID_FRAMEBUFFER_OPERATION, but again, the FBO specs should tell you, when this error is thrown. Please make extensive use of glGetError() and check the status of the FBO in order to track down the exact point where the error is caused.
I don´t know how well MRT plus FBO is already supported in the drivers… It may be well possible that your card´s drivers don´t support it yet.

def, what hardware and driver version are you running? What is the value of GL_MAX_DRAW_BUFFERS? FBO + MRT should be supported on all nv4x class hardware.

INVALID_FRAMEBUFFER_OPERATION means that you attempted to access (render to or read from) the framebuffer while your framebuffer status (glGetFramebufferStatusEXT) is not FRAMEBUFFER_COMPLETE. You should not call GetFramebufferStatus (or glGetError) inside your rendering loop for performance reasons, but it is wise to call CheckFramebufferStatus at the end of FBO initialization to verify that things are set up correctly.

Oh, see also example 8 of the EXT_framebuffer_object specification. Example 8 was added in a spec revision newer than the first date of publication. The updated spec is available on the extensions registry.

Thanks JeffJ, found Rev. 117 of the FBO Specs at the OpenGL Extension Registry (SGI), NVidia is still at Rev. 109. :wink:
Example 8 is exactly what I am trying to do, without the renderbuffer. I am sure I did not check the fbo status AFTER attaching the texture objects… I will post more (error) results soon.

If I have to check the fbo status after attaching the textures, it will end up in the rendering loop, no matter what. But I will only need to check that for debugging.

Originally posted by skynet:
Fastian, spreading false information does not help either. Please read the FBO specs before ( FBO specs ).

Oops. I looked at glDrawBuffers help and thought the input arguments were incorrect according to the help. Either the help is outdated… or I am not understanding the documentation correctly. Either ways, I’m sorry, my mistake.

well…I tried that a few days ago and it’s working that way [I hope it’s correct - I didn’t read the specs for a while…]

init as you wrote:

glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fb);
glFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_RECTANGLE_ARB, m_tex[0], 0);
glFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_RECTANGLE_ARB, m_tex[1], 0);

rendering (for two buffers…):

const GLenum buffers[] = {
	GL_COLOR_ATTACHMENT0_EXT,
	GL_COLOR_ATTACHMENT1_EXT,
};
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fb);
glViewport(0, 0, _width, _height);
for(int i = 0; i < 2; ++i) {
  glDrawBuffer(buffers[i]);
}
glDrawBuffers(2, buffers); 

...start rendering...

Why do you need these lines? :confused:

for(int i = 0; i < 2; ++i) {
  glDrawBuffer(buffers[i]);
}

oh, sorry, these aren’t necessary, it was an experimental code fragment and I just forgot to remove them.

Not sure if you’ve fixed this yet, but I wrote some working FBO MRT code a while back:

fbo_benchmarks.zip

Have a look at the 4-out examples.

Thanks everybody for the help!
I finally found the error. Checking the fbo status after attaching the render targets I got an GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT error. I was using the same fbo for a second pass and forgot to detach one of the render targets…
Without checking the fbo status I only got an GL_INVALID_FRAMEBUFFER_OPERATION_EXT error while calling glEnd() which was really confusing by itself…

Originally posted by Jay Cornwall:
Not sure if you’ve fixed this yet, but I wrote some working FBO MRT code a while back:

Hey that seems to be great code Jay! I will take a closer look at the benchmarks to optimize my code.
Thanks!