PDA

View Full Version : fbo with depth attachment does not work



lodder
10-18-2005, 08:39 PM
Hi,

I am trying to a fbo with only a depth buffer attachment to work. I read the spec and the document in the new ATI SDK, both have examples for it. This is what I have so far:

// generate fbo object
glGenFramebuffersEXT(1, &m_FBO);
CheckFrameBufferStatus(__LINE__);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_FBO);
CheckFrameBufferStatus(__LINE__);

// generate depth attachment
glGenTextures(1, &m_DepthAttachment);
glBindTexture(GL_TEXTURE_2D, m_DepthAttachment);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT16, width, height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);

//glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL _CLAMP);
//glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL _CLAMP);

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_NEAREST);

// attach depth texture
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, m_DepthAttachment, 0);
glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);
CheckFrameBufferStatus(__LINE__);

glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);This is the initalisation code. It gives me no errors. New the render code:

glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_FBO);
glClear(GL_DEPTH_BUFFER_BIT);
// Render some geometry here...
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);Later on, I try to use m_DepthAttachment as GL_TEXTURE_2D object, but this doesnt work. The quad is always white :(

Do you have any ideas?

Thanks in advance, Enrico

alkiem
10-18-2005, 10:11 PM
Hi,
if you want to use your depth texture to do depth comparison, you need to add:
glTexParameteri( GL_TEXTURE2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE_ARB );
glTexParameteri( GL_TEXTURE2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL );

It works form me, i'm doing shadow mapping with fbo btw.

lodder
10-18-2005, 10:54 PM
Thanks for your reply.
I do not want to do shadow mapping (for now). I just want to display the texture and see the depth values. But the fbo texture is always white and my model is rendered.

Zulfiqar Malik
10-18-2005, 11:13 PM
Depth component textures are meaning less in terms of color. You can however write a fragment shader in which you lookup a value from a depth texture and use it as a color for fragments.

alkiem
10-18-2005, 11:30 PM
To see the depth values, i only apply the depth texture to a quad, but you need to have TEXTURE_COMPARE_MODE_ARB = NONE in this case.

Jens Scheddin
10-19-2005, 01:22 AM
Originally posted by lodder:
Thanks for your reply.
I do not want to do shadow mapping (for now). I just want to display the texture and see the depth values. But the fbo texture is always white and my model is rendered.It may look like the texture is pure white, as the difference in color could be very small.

lodder
10-19-2005, 03:07 AM
Originally posted by alkiem:
To see the depth values, i only apply the depth texture to a quad, but you need to have TEXTURE_COMPARE_MODE_ARB = NONE in this case.Do you have something else activated? The shadow map test, for example? Or do you only have set this comparison after you created your depth texture?


Originally posted by Zulfiqar Malik:
Depth component textures are meaning less in terms of color. You can however write a fragment shader in which you lookup a value from a depth texture and use it as a color for fragments.Ok, so I need shaders. I will try that...

@Jens: I render only a triangle, nothing else. There should be at least something visible, or?

alkiem
10-19-2005, 03:52 AM
Originally posted by lodder:
Do you have something else activated? The shadow map test, for example? Or do you only have set this comparison after you created your depth texture?
Nothing is activated, i just render the shadow map in the depth texture bound to the fbo. Everything about shadow map test is made in a fragment shader when rendering the scene from the camera point of view. When you want to see the depth texture, as i said before, if the depth texture was initialized with:
glTexParameteri( GL_TEXTURE2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE_ARB );
you just need to do:
glTexParameteri( GL_TEXTURE2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_NONE );
But, GL_NONE is the default value of GL_TEXTURE_COMPARE_MODE_ARB, so in your case, it should work directly.

Do you try not to enable the fbo and rendering to frame buffer directly to see if there is sthg visible in the viewport? Your problem may not be with fbo, unless it is linked to driver/graphic card issue.

lodder
10-19-2005, 05:32 AM
This comparison changes nothing for me. It is still the same. I render a quad two times:
1) The usual frame buffer (works)
2) Into the depth texture (does not work)
I rendered into a color attachment and this works without any problems...

What to try now?

jide
10-19-2005, 06:23 AM
When I tried it, few months ago, I needed to have another buffer along with the depth buffer, like a logical color buffer.
Otherwise, I just had nothing just like you.
Make a research about your question, many keys were written.

lodder
10-19-2005, 06:25 AM
Originally posted by jide:
When I tried it, few months ago, I needed to have another buffer along with the depth buffer, like a logical color buffer.
Otherwise, I just had nothing just like you.
Make a research about your question, many keys were written.Did you render into a RenderBuffer or texture? Spec says explicit, I can render depth values into a texture... This is confusing...

jide
10-19-2005, 06:39 AM
I tried out both, but it was on nv cards.

Jens Scheddin
10-21-2005, 07:07 AM
Originally posted by lodder:
[QB@Jens: I render only a triangle, nothing else. There should be at least something visible, or?[/QB]No. The difference between the color (or depth value) is probably too small to notice. I realized that, when filling a screenshot with a brush in a paint program with, for example, black.

lodder
10-23-2005, 02:16 AM
Hi,

got it working now; even without shaders :)
The problem: I used a NPOT color attachment and this works without problems on my X700Pro and Radeon9800Pro. I get a working NPOT depth attachment only, if I use GL_UNSIGNED_BYTE or GL_FLOAT as type parameter for glTexImage2D(). When I use GL_UNSIGNED_SHORT, the depth attachment does not work. But why wont I get a error message, when it doesnt work?? :mad:

Maybe I should report this to ATI...