Blitting depth does not work

Hello,

I’m trying to blit color and depth from my main framebuffer to my secondary framebuffer.
Both, the main and secondary framebuffer use textures as color- and depthattachments and are framebuffer-complete.

This is my code:


if(cur::gfx_driver->SupportsFBOBlit())
{
  m_fbc_main_color.Bind_Read();
  if(!gl->CheckFrameBufferCompleteness(GL_READ_FRAMEBUFFER_EXT))
    PEASSERT(0);

  m_fbc_secondary.Bind_Write();
  if(!gl->CheckFrameBufferCompleteness(GL_DRAW_FRAMEBUFFER_EXT))
    PEASSERT(0);

  glBlitFramebufferEXT(0, 0, m_rt_main_c.urt_size[0], m_rt_main_c.urt_size[1],
    0, 0, m_rt_main_c.urt_size[0], m_rt_main_c.urt_size[1],
    GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST);
}
else
{
  m_rt_secondary_c->Bind(0); // bind color texture
  glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, m_rt_main_c.urt_size[0], m_rt_main_c.urt_size[1]);

  m_rt_secondary_d->Bind(0); // bind depth texture
  glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, m_rt_main_c.urt_size[0], m_rt_main_c.urt_size[1]);
}

Both codepaths work for color but not for depth.
After blitting I render the depthbuffer to the screen with the following shader:

uniform sampler2D u_fbdepth;
uniform vec2 u_fb_texelsize;

void main()
{
	vec2 st = gl_FragCoord.xy;
	st *= u_fb_texelsize;
	st = clamp(st, 0.0, 1.0);

	vec3 depth = texture2D(u_fbdepth, st).xyz;
	gl_FragColor = vec4(depth, 0.0);
} 

The result is a complete white screen nomatter what geomerty was rendered
in the depthbuffer. Any hints what I’m missing?

This may very well be correct. Most depth values will be very close to 1.0 under regular perspective projection. Try visualizing it with something like pow(depth, 50.0) to get some visible contrast.

Thanks, the pow() worked wonders. Both codepaths yield equal results. :slight_smile: