Binding a stencil render buffer to a frame buffer in opengl
Asked Answered
J

2

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

Jemison answered 18/6, 2012 at 14:27 Comment(0)
H
9

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​.

Hydrogeology answered 18/6, 2012 at 16:32 Comment(6)
+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 :)Jemison
@ViktorSehr: It may not be the stencil; what image format are you using for your texture?Hydrogeology
@Viktor, did the stencil worked as free-standing buffer? Nicol, if I need stencil and color, what could I choose?Provenience
@elect: My answer is quite clear about what you use: a combined depth/stencil image. You simply ignore the depth part of it.Hydrogeology
@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 ?Consonantal
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.Duvall
T
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

Tetrafluoroethylene answered 30/11, 2016 at 12:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.