I switched from render buffer to depth texture in my FBO.But it seem like it doesn't contain any depth data.If I render this texture to a full screen quad everything is black.I am pretty sure the texture and FBO setup is ok.FBO is completed and if I clear depth, let's say to gray :
glClearDepth(0.5f);
Then I see the color in the blit pass, but not the data from the geometry rendering.
Anyway, that is how I create the texture:
glBindTexture ( GL_TEXTURE_2D, _id );
glTexStorage2D(GL_TEXTURE_2D,1,intFmt,theWidth,theHeight);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);
glTexParameteri (GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY);
glBindTexture(_target,0);
Where intFmt is GL_DEPTH_COMPONENT24 or GL_DEPTH_COMPONENT32 (tried both..)
That is how I attach it to the FBO:
glBindFramebuffer(GL_FRAMEBUFFER, _frameBuffer);
glBindTexture(GL_TEXTURE_2D, _id);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, target,_id, 0);
And this is blit pass fragment shader:
#version 420
layout(binding=0) uniform sampler2D COLOR_MAP_0;
smooth in vec2 uvsOut;
out vec4 OUTPUT;
void main(void) {
ivec2 tsize = textureSize(COLOR_MAP_0, 0);
vec2 screntc = gl_FragCoord.xy * (1.0 / vec2(tsize));
OUTPUT = vec4(texture(COLOR_MAP_0, screntc).rrr ,1) ;
}
Maybe I should explicitly write depth in fragment shader?
I tried to linearize the depth in the blit fragment shader.It works.Now I can see the depth.But I see white and some gray shades without it.In the snapshot:left part is drawn using linearization while the right part samples from depth texture directly.