PDA

View Full Version : FBO : how to set a 24_8_NV texture in the depth attachment of a fbo (for hardware SM)



oxium
03-15-2006, 08:52 AM
Hi,

I'm currently porting my DX9 hardware shadow mapping implementation on opengl.
So i have to use the frame buffer object extension.
For the moment, i can create a Float32 render target but need to improve it with nvidia hardware implementation.

I use the following init code, i must miss something because no shadows are displayed (i check shadow bias and pixel/vertex shader, it seems the problem is in my fbo)




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

glGenTextures(1, &_Texture._gluiTextureIndex);
glBindTexture(_Texture._bindingTarget, _Texture._gluiTextureIndex);

glTexImage2D(_Texture._bindingTarget, 0, GL_RGBA8, uiWidth, uiHeight, 0, GL_RGBA, GL_FLOAT, NULL);
glTexParameterf(_Texture._bindingTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(_Texture._bindingTarget, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(_Texture._bindingTarget, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(_Texture._bindingTarget, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

// attach texture to framebuffer object
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, _Texture._bindingTarget, _Texture._gluiTextureIndex, 0);

glGenTextures(1, &_Texture._gluiTextureIndex);
glBindTexture(_Texture._bindingTarget, _Texture._gluiTextureIndex);

glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, uiWidth, uiHeight, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT/*GL_FLOAT*/, 0);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

// attach texture to framebuffer object
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, _Texture._bindingTarget, _Texture._gluiTextureIndex, 0);
Any ideas ?
I'm sure i'm not the first one to implement hardware SM with frame buffer object !!
If somebody knows a good sample showind how to use this wonderful extension, don't hesitate. :)
Thanks in advance.

Overmind
03-15-2006, 10:44 AM
Assuming _Texture._bindingTarget holds the correct value, that is GL_TEXTURE_2D, I see no problem with your code.

Insert error checks (glGetError) and check framebuffer for completeness (glCheckFramebufferStatusEXT) before rendering.

You could try out if your shadow mapping code works correctly by using glCopyTexSubImage instead of directly rendering into the texture, just to make sure the problem is really with FBO.

oxium
03-16-2006, 12:04 AM
yep the binding target is GL_TEXTURE_2D
and i call a glCheckFramebufferStatusEXT after this init code without error...

maybe the problem is in my shadow mapping code, that sounds very strange..
good idea the glCopyTexSubImage test, i will give it a try.

thanks

ebray99
03-17-2006, 07:21 AM
Change the following:

glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, uiWidth, uiHeight, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT_24_8_EXT, 0);

To

glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8_EXT, uiWidth, uiHeight, 0, GL_DEPTH_STENCIL_EXT, GL_UNSIGNED_INT/*GL_FLOAT*/, 0);

Also, you're not setting the compare mode on the shadow map. You can do that by adding the following:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL);

See the following for more details:
http://oss.sgi.com/projects/ogl-sample/registry/ARB/shadow.txt

- Kevin B