PDA

View Full Version : GL_RENDERBUFFER_STENCIL_SIZE returns 0



jbates
07-20-2012, 05:34 PM
The following code isn't producing the results I expect:



GLuint renderbuffer;
glGenRenderbuffers(1, &renderbuffer);
glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, 1, 1);

GLint stencilSize;
glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_STENCIL_SIZE, &stencilSize);


The stencil size is reported to be 0. I've checked glGetError() all along the way and no errors are being reported so it's not like it's an unsupported format. And glGetRenderbufferParameteriv with GL_RENDERBUFFER_INTERNAL_FORMAT is returning GL_STENCIL_INDEX8, so the format is being set. Color and depth formats work as expected.

This happens on my GeForce GTX 670, Windows 7 x64, both with drivers 301.42 and 304.79-BETA, both with and without WGL_CONTEXT_ES2_PROFILE_BIT_EXT.

It doesn't happen on my iOS simulator (I'm developing for both Windows and iOS right now to ensure I'm not using implementation-specific features). The iOS simulator reports the expected size of 8.

Am I doing something wrong or is this a bug?

EDIT:
The same problem seems to occur with GL_STENCIL_INDEX1, GL_STENCIL_INDEX4, and GL_STENCIL_INDEX16, but not GL_DEPTH24_STENCIL8

Alfonse Reinheart
07-20-2012, 05:52 PM
Am I doing something wrong or is this a bug?

Yes, to both.

Never use GL_STENCIL_INDEX8. For anything. If you need a stencil buffer, use GL_DEPTH24_STENCIL8. Yes, according to the spec, you should be able to make GL_STENCIL_INDEX8 work. But you're less likely to encounter a driver bug if you just do the right thing and use what works.

jbates
07-20-2012, 06:07 PM
:)
Thanks for the speedy reply. I had a feeling stencil buffers not packed with a depth buffer weren't recommended. I wasn't actually planning on using it. I'm currently writing a wrapper library with unit tests and GL_STENCIL_INDEX8 was just the format I chose to test my getRenderbufferStencilSize() function.

I was actually considering making my wrapper only include functionality from OpenGL ES 2.0 core, but maybe now I'll include at least GL_OES_packed_depth_stencil too.