PDA

View Full Version : What is wrong with this FBO creation?



Godlike
01-31-2010, 02:25 PM
I'm trying to create a FBO with one color buffer stored in texture, one depth buffer in texture and one stencil render buffer:


uint fbo_id, tex_id, depth_tex_id, stencil_rb;

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

// color
glGenTextures( 1, &tex_id );
glBindTexture( GL_TEXTURE_2D, tex_id );
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB8, 100, 100, 0, GL_RGB, GL_FLOAT, NULL );
glFramebufferTexture2DEXT( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex_id, 0 );

// depth
glGenTextures( 1, &depth_tex_id );
glBindTexture( GL_TEXTURE_2D, depth_tex_id );
glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 100, 100, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL );
glFramebufferTexture2DEXT( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depth_tex_id, 0 );

// stencil
glGenRenderbuffersEXT( 1, &stencil_rb );
glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, stencil_rb );
glRenderbufferStorageEXT( GL_RENDERBUFFER_EXT, GL_STENCIL_INDEX, 100, 100 );
glFramebufferRenderbufferEXT( GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, stencil_rb );

if( glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) != GL_FRAMEBUFFER_COMPLETE_EXT )
FATAL( "!!!!!!!" );

The above code fails all the time. What is wrong with it? Im using an AMD 4870 (unfortunately) under ubuntu linux.

Thanks in advance!

Alfonse Reinheart
01-31-2010, 03:12 PM
I'm trying to create a FBO with one color buffer stored in texture, one depth buffer in texture and one stencil render buffer:

Two problems.

1: You need to actually say what glCheckFramebufferStatus returns. It's not just a binary pass/fail; unless it returns GL_UNSUPPORTED, it can easily clue you in onto the problem.

2: Never, ever use separate stencil and depth buffers. If you need a stencil buffer and a depth buffer, use one texture/renderbuffer with one of the GL_DEPTH_STENCIL types.

dletozeun
01-31-2010, 03:49 PM
Godlike, the default texture minification filter is NEAREST_MIPMAP_LINEAR, so either you set texture minification filter (glTexParameter (http://www.opengl.org/sdk/docs/man/xhtml/glTexParameter.xml))to something that does not require mipmaps generation or you generate them.

In your code, you call glTexImage2D to allocate texture data for color attachment 0 but you don't allocate mipmaps data. Consequently the fbo could not be complete. You just need a call to glGenerateMipmapsEXT() after the glTexImage2D call and the fbo should normally be complete.

Alfonse, what is the problem with using separate buffers for stencil and depth data? This is allowed AFAIK and may be useful.

Alfonse Reinheart
01-31-2010, 04:45 PM
Alfonse, what is the problem with using separate buffers for stencil and depth data? This is allowed AFAIK and may be useful.

An implementation of FBO is allowed to return GL_FRAMEBUFFER_UNSUPPORTED if it doesn't like the combination of bound objects. And however much the spec may technically allow separate depth and stencil buffers, implementations will return GL_FRAMEBUFFER_UNSUPPORTED (or just flat-out not work) if you try it.

Godlike
02-01-2010, 11:00 AM
Thanks for the answers.

@Alfonse Reinheart: How can I make a depth_stencil texture? Not renderbuffer cause I want to access the depth values in a shader.

@dletozeun: after a few tests it appears that mipmaping is now an issue.

Alfonse Reinheart
02-01-2010, 11:40 AM
How can I make a depth_stencil texture? Not renderbuffer cause I want to access the depth values in a shader.

You use the depth/stencil image format in glTexImage.

Godlike
02-01-2010, 11:47 AM
How can I make a depth_stencil texture? Not renderbuffer cause I want to access the depth values in a shader.

You use the depth/stencil image format in glTexImage.

how?

this fails:

glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, 100, 100, 0, GL_DEPTH_STENCIL, GL_FLOAT, NULL );

Alfonse Reinheart
02-01-2010, 12:24 PM
this fails:

Fails as in gives a glError, fails as in crashes... Be more specific.

Godlike
02-01-2010, 01:15 PM
this fails:

Fails as in gives a glError, fails as in crashes... Be more specific.

it returns an "invalid operation".

dletozeun
02-01-2010, 02:22 PM
Godlike, try something like this:



glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8_EXT, 100, 100, 0, GL_DEPTH_STENCIL_EXT, GL_UNSIGNED_INT_24_8_EXT, NULL );




however much the spec may technically allow separate depth and stencil buffers, implementations will return GL_FRAMEBUFFER_UNSUPPORTED (or just flat-out not work) if you try it.


I don't have tried to create this kind of fbo yet. You mean that most of the current drivers gl implementation does not support seperate depth and stencil buffers?