PDA

View Full Version : FBO and MRT problem



def
12-19-2005, 03:09 AM
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...

def
12-21-2005, 12:38 AM
This is still puzzeling me!

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

Thanks

Fastian
12-21-2005, 03:46 AM
I believe you are passing wrong arguments in glDrawBuffers. Have a look at the documentation for glDrawBuffers here. (http://developer.3dlabs.com/documents/GLmanpages/glDrawBuffers.htm)

Hope this helps.

Fastian
12-21-2005, 03:54 AM
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);

skynet
12-21-2005, 08:23 AM
Fastian, spreading false information does not help either. Please read the FBO specs before ( FBO specs (http://oss.sgi.com/projects/ogl-sample/registry/EXT/framebuffer_object.txt) ).

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.

JeffJ
12-21-2005, 09:23 AM
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.

JeffJ
12-21-2005, 09:28 AM
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.

def
12-21-2005, 11:20 AM
Thanks JeffJ, found Rev. 117 of the FBO Specs at the OpenGL Extension Registry (SGI), NVidia is still at Rev. 109. ;)
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.

Fastian
12-22-2005, 05:23 AM
Originally posted by skynet:
Fastian, spreading false information does not help either. Please read the FBO specs before ( FBO specs (http://oss.sgi.com/projects/ogl-sample/registry/EXT/framebuffer_object.txt) ).
Oops. I looked at glDrawBuffers help (http://developer.3dlabs.com/documents/GLmanpages/glDrawBuffers.htm) 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.

AnselmG
12-22-2005, 07:56 AM
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...

Java Cool Dude
12-22-2005, 09:41 AM
Why do you need these lines? :confused:

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

AnselmG
12-22-2005, 01:30 PM
oh, sorry, these aren't necessary, it was an experimental code fragment and I just forgot to remove them.

Jay Cornwall
12-22-2005, 01:31 PM
Not sure if you've fixed this yet, but I wrote some working FBO MRT code a while back:

fbo_benchmarks.zip (http://www.esuna.co.uk/~jay/papers/source/fbo/fbo_benchmarks.zip)

Have a look at the 4-out examples.

def
12-23-2005, 12:20 AM
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...

def
12-23-2005, 12:24 AM
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!