Multisample FBO problems with stencil buffer

Hi - can anyone see an obvious reason why this should come back as FBO ‘incomplete attachment’ ? :

glGenFramebuffersEXT(1, &fboID);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboID);

glGenRenderbuffersEXT(1, &ColorBufferID);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, ColorBufferID);
glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, 8, GL_RGBA32F_ARB, sx, sy);

glGenRenderbuffersEXT(1, &StencilBufferID);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, StencilBufferID);
glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, 8, GL_STENCIL_INDEX, sx, sy);

glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, ColorBufferID);

glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, StencilBufferID);

Works fine if I remove the stencil buffer (and just keep the color render buffer)

Thanks.

Maybe this can help you?

“NEVER EVER MAKE A STENCIL buffer. All GPUs and all drivers do not support an independent stencil buffer. If you need a stencil buffer, then you need to make a Depth=24, Stencil=8 buffer, also called D24S8. Please search for the example about GL_EXT_packed_depth_stencil on this page.”

http://www.opengl.org/wiki/GL_EXT_framebuffer_object#Stencil

Actually, that’s not the reason. Drivers can ignore specific formats, but only by using GL_UNSUPPORTED. If it actually comes back as GL_INCOMPLETE_ATTACHMENT, then that means you have done something that can’t be done.

What likely happened is that “glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, 8, GL_STENCIL_INDEX, sx, sy);” failed with a glError. Thus, the stencil buffer could not be created, and when you bind it, it isn’t of stencil type.

The solution is, well, what MarkZ3 said :wink:

Changing the internal format for glRenderbufferStorageMultisample to GL_DEPTH24_STENCIL8_EXT, and the attachment point for glFramebufferRenderbufferEXT to DEPTH rather than STENCIL works.

Thanks guys.