6

Have anyone done this succesfully? It seems whatever index format I use in the stencil render buffer glCheckFramebufferStatus(...) returns GL_FRAMEBUFFER_UNSUPPORTED. I've succesfully bound both a depth\color render buffer, but whenever I try to do the same thing with my stencil buffer I get (as I said) GL_FRAMEBUFFER_UNSUPPORTED.

Here is snippets of my code:

// Create frame buffer
GLuint fb;
glGenFramebuffers(1, &fb);

// Create stencil render buffer (note that I create depth buffer the exact same way, and It works.
GLuint sb;
glGenRenderbuffers(1, &sb);
glBindRenderbuffer(GL_RENDERBUFFER, sb);
glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, w, h);

// Attach color
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, cb, 0);

// Attach stencil buffer
glBindFramebuffer(GL_FRAMEBUFFER, fb);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rb);
// And here I get an GL_FRAMEBUFFER_UNSUPPORTED when doing glCheckFramebufferStatus()

Any ideas?

Note: The color attachement is a texture and not a renderbuffer

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
Viktor Sehr
  • 12,825
  • 5
  • 58
  • 90

2 Answers2

8

Never use a free-standing stencil buffer. If you need stencil, always use a depth+stencil image format. Note that the stencil index formats are not required image formats.

Even though you're not using a depth buffer here, you still should use GL_DEPTH24_STENCIL8, which you should attach to GL_DEPTH_STENCIL_ATTACHMENT​.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • +1 Hmm I think I tried it but didn't work, however it works at my ATI card at home, if I get it to work at my nvidia at work, I'll give your answer green :) – Viktor Sehr Jun 18 '12 at 18:33
  • @ViktorSehr: It may not be the stencil; what image format are you using for your texture? – Nicol Bolas Jun 18 '12 at 18:34
  • @Viktor, did the stencil worked as free-standing buffer? Nicol, if I need stencil and color, what could I choose? – elect Mar 11 '13 at 14:44
  • @elect: My answer is quite clear about what you use: a combined depth/stencil image. You simply ignore the depth part of it. – Nicol Bolas Mar 11 '13 at 14:53
  • @NicolBolas I have a question regarding this:If I specify depth renderbuffer along with the stencil then should I also specify the format GL_DEPTH24_STENCIL8 to the depth buffer? and GL_DEPTH_STENCIL_ATTACHMENT​ too? Or the depth buffer is created as usual with GL_DEPTH_ATTACHMENT and GL_DEPTH_COMPONENT24 ? – Michael IV Apr 29 '13 at 10:17
  • AS ALWAYS MR BOLAS WITH THE ANSWERS. On iOS, even though the `GL_STENCIL_INDEX8` and `GL_STENCIL_INDEX8_OES` are defined, they do not seem to work at all (you always get `GL_FRAMEBUFFER_UNSUPPORTED`). It seems you __must__ use the depth+stencil format `GL_DEPTH24_STENCIL8_OES` to get the stencil buffer to work at all. – bobobobo May 02 '13 at 19:13
1

You can use stencil-only on recent nvidia hardware/drivers

glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_TEXTURE_2D, fboStencilTexture, 0);

Still no support for both separate depth and stencil

Anton Duzenko
  • 2,366
  • 1
  • 21
  • 26