Sign in to follow this  
ThomasM

FBO Completeness with Stencil Renderbuffer

Recommended Posts

Hi! When I'm creating a framebuffer object with a depth attachment (or also called renderbuffer), a color attachment and a depth texture attachment, everything works well. But if I add a stencil attachment, glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) returns GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT. My code is the following:
	// creating an rgb renderbuffer with 32 bit floating point colors
	GLuint rgb_rb;
	glGenRenderbuffersEXT(1, &rgb_rb);
	glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rgb_rb);
	glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGB32F_ARB, FRAME_WIDTH, FRAME_HEIGHT);

	// creating an 24-bit depth renderbuffer
	GLuint depth_rb;
	glGenRenderbuffersEXT(1, &depth_rb);
	glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depth_rb);
	glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, FRAME_WIDTH, FRAME_HEIGHT);

	// creating stencil renderbuffer
	GLuint stencil_rb;
	glGenRenderbuffersEXT(1, &stencil_rb);
	glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, stencil_rb);
	glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_STENCIL_INDEX, FRAME_WIDTH, FRAME_HEIGHT);

	// creating the framebuffer object
	glGenFramebuffersEXT(1, &frameBuffer_id);
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, frameBuffer_id);

	// bind renderbuffers to framebuffer object
	glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depth_rb);
	glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, rgb_rb);
	glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, stencil_rb);

	// connect a depth texture
	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, frameBufferTexture, 0);	
What am I doing wrong? It seems to be no driver bug, I've tried numerous drivers...

Share this post


Link to post
Share on other sites
As far as I know it's not possible to attach a stencil renderbuffer to a framebuffer object due to implementation difficulties. I had this problem a few months ago, and the only information I could find about the problem was that it might be possible to have the stencil attachment interleaved in the depth buffer, but I have no idea if it is possible, or in that case how to implement it. Hope someone else can shed some more light upon this problem...

Share this post


Link to post
Share on other sites
Quote:
Original post by Erim
and the only information I could find about the problem was that it might be possible to have the stencil attachment interleaved in the depth buffer, but I have no idea if it is possible, or in that case how to implement it.


Its coming "soon", there is a depth_stencil extension which extends openGL for a depth stencil pixel format and adds the ability to correctly bind it to the depth and stencil sections of an FBO.

I'd expect NV to have it out pretty soon and ATI to follow in around 2 to 3 months time (thats how far ahead the internal driver development is at ATI, drivers arent released until a package is WHQL stamped)

Share this post


Link to post
Share on other sites
There is a way around to your problem, because the extension depth+stencil works fine when using a texture. Here some code:


#define GL_DEPTH_STENCIL_EXT 0x84F9
#define GL_UNSIGNED_INT_24_8_EXT 0x84FA
#define GL_DEPTH24_STENCIL8_EXT 0x88F0
#define GL_TEXTURE_STENCIL_SIZE_EXT 0x88F1




When creating your depth+stencil texture, use GL_DEPTH24_STENCIL8_EXT for internal format, GL_DEPTH_STENCIL_EXT for format and GL_UNSIGNED_INT_24_8_EXT for the type.
Then you attach the texture as depth attachment and stencil attachment.

I may be wrong but I think that several depth attachments are useless since only the last one will be effective (there is no way to access different depth attachments).

[Edit]
May be just using GL_DEPTH24_STENCIL8_EXT instead of GL_DEPTH_COMPONENT24 in glRenderbufferStorageEXT works fine to create a depth+stencil buffer (just give it a try ;) ).

Share this post


Link to post
Share on other sites
Quote:
Original post by phantom
Quote:
Original post by Erim
and the only information I could find about the problem was that it might be possible to have the stencil attachment interleaved in the depth buffer, but I have no idea if it is possible, or in that case how to implement it.


Its coming "soon", there is a depth_stencil extension which extends openGL for a depth stencil pixel format and adds the ability to correctly bind it to the depth and stencil sections of an FBO.

I'd expect NV to have it out pretty soon and ATI to follow in around 2 to 3 months time (thats how far ahead the internal driver development is at ATI, drivers arent released until a package is WHQL stamped)


nVIDIA already has it in the 81.85 official drivers.

Share this post


Link to post
Share on other sites
This code should work:


// creating an rgb renderbuffer with 32 bit floating point colors

GLuint rgb_rb;
glGenRenderbuffersEXT(1, &rgb_rb);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rgb_rb);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGB32F_ARB, FRAME_WIDTH, FRAME_HEIGHT);

// creating an 24-bit depth + 8-bit stencil texture

GLenum texTarget = GL_TEXTURE_RECTANGLE_ARB;
GLenum texInternalFormat = GL_DEPTH24_STENCIL8_EXT;
GLenum texFormat = GL_DEPTH_STENCIL_EXT;
GLenum texType = GL_UNSIGNED_INT_24_8_EXT;
GLenum texFilterMode = GL_NEAREST;
GLuint depth_stencil_texture = 0;
glGenTextures(1, &depth_stencil_texture);
glBindTexture(texTarget, depth_stencil_texture);
glTexImage2D(texTarget, 0, texInternalFormat, FRAME_WIDTH, FRAME_HEIGHT, 0, texFormat, texType, NULL);

glTexParameterf(texTarget, GL_TEXTURE_MIN_FILTER, texFilterMode);
glTexParameterf(texTarget, GL_TEXTURE_MAG_FILTER, texFilterMode);
glTexParameterf(texTarget, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(texTarget, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(texTarget, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL);

// creating the framebuffer object

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

// bind renderbuffer to framebuffer object

glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, rgb_rb);

// connect a depth stencil texture
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, texTarget , depth_stencil_texture, 0);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, texTarget , depth_stencil_texture, 0);




A similar code works for me (in my case the color attachment is a texture too). If you still get GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT, I can't think of anything except driver issue.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this