Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Blitting depth does not work

  1. #1
    Intern Contributor
    Join Date
    May 2003
    Location
    Dortmund, Germany
    Posts
    60

    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:
    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:

    Code :
    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?

  2. #2
    Senior Member OpenGL Guru Humus's Avatar
    Join Date
    Mar 2000
    Location
    Stockholm, Sweden
    Posts
    2,444

    Re: Blitting depth does not work

    Quote Originally Posted by namespace
    The result is a complete white screen nomatter what geomerty was rendered
    in the depthbuffer.
    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.

  3. #3
    Intern Contributor
    Join Date
    May 2003
    Location
    Dortmund, Germany
    Posts
    60

    Re: Blitting depth does not work

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •