PDA

View Full Version : FBO+DEPTH_STENCIL+81.xx = trouble?



DraKKaR
03-02-2006, 07:50 AM
Hello, I'm trying to setup a FBO with a texture2d color, depth and stencil attachments. This is the source code I use for FBO setup:


GLuint fb, rtt, depth_stencil_rb;
glGenFramebuffersEXT(1,&fb);
glGenTextures(1,&rtt);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,fb);
glBindTexture(GL_TEXTURE_2D,rtt);

glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA8,t->GetWidth(),t->GetHeight(),0,GL_RGBA,GL_UNSIGNED_BYTE,NULL);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,GL_CO LOR_ATTACHMENT0_EXT,GL_TEXTURE_2D,rtt,0);

glGenRenderbuffersEXT(1,&depth_stencil_rb); glBindRenderbufferEXT(GL_RENDERBUFFER_EXT,depth_st encil_rb); glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT,0x84F 9/*GL_DEPTH_STENCIL_EXT*/,t->GetWidth(),t->GetHeight());
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,GL _DEPTH_ATTACHMENT_EXT,GL_RENDERBUFFER_EXT,depth_st encil_rb); glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,GL _STENCIL_ATTACHMENT_EXT,GL_RENDERBUFFER_EXT,depth_ stencil_rb);

glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT); glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);

This code seems to work because it passes the checkFBOStatus test. However, when I'm trying to use the stencil, it doesn't seems to work properly.

I try to readback the contents in the depth_stencil buffer with:


glReadPixels(0,0,t->GetWidth(),t->GetHeight(),0x84F9/*GL_DEPTH_STENCIL_EXT*/,0x84FA/*GL_UNSIGNED_INT_24_8_EXT*/, pixels); after setting the stencil value with:


glClearStencil(8);
glClear(GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT) ; But it I allways get the same data in the pixels array: 0, don't matter to what value I clean the depth_stencil buffer.

Is there any problem in my code? Any one of you have some source code of a depth_stencil FBO working? (or only a stencil FBO at least).

Thanks in advance.

knackered
03-02-2006, 10:26 AM
I wouldn't be able to tell you because any driver above 78.01 makes all OpenGL apps crash on this machine (gf6800gt).

DraKKaR
03-03-2006, 04:18 PM
I can't believe any one of you have any source code using FBO+depth_stencil or can't tell me this should run OK

Matt Zamborsky
03-04-2006, 06:06 AM
I olny tried depth stencil texture and it worked as expected:

glGenTextures(1,&m_idDepthStencil);
glBindTexture(GL_TEXTURE_2D,m_idDepthStencil);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_FALSE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8_EXT, m_width, m_height, 0, GL_DEPTH_STENCIL_EXT, GL_UNSIGNED_INT_24_8_EXT, NULL);
glBindTexture(GL_TEXTURE_2D,0);

glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, m_idDepthStencil, 0);
glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_TEXTURE_2D, m_idDepthStencil, 0);

Andrew Lauritzen
03-06-2006, 11:00 AM
To my knowledge, separate depth and stencil attachments are currently unsupported on all hardware (due to difficultly of implementation I believe). You'll have to use EXT_packed_depth_stencil as shown in the previous post to get both with FBOs.