title: Quickly read values from the depth buffer
body: <p>I'm working on an implementation of the "Depth on Field" in OpenGL (3.X) with GLSL.
  It works pretty good, central depth is taken up by shaders (texture (tex1, vec2 (0.5))) to autofocus. But using such an implementation focus happens immediately. He should like the eye - gradually adapt. For this I need the depth in the middle on the side of the CPU memory.
  I know how to use the PBO, use it to read the pixel / pixel color works pretty fast (runs asynchronously), but changing the  GL_RGB to GL_DEPTH_COMPONENT performance drops drastically. Do you know any way to read that the central depth comparatively quickly what color?</p>
  
  <pre><code>    glReadPixels(a/2, b/2, 1, 1, GL_RGB , GL_BYTE, 0); // WORKS FINE - 30 ns
      glReadPixels(a/2, b/2, 1, 1, GL_DEPTH_COMPONENT, GL_BYTE, 0); // WORKS SLOOOW - around 3500 microseconds
      glReadPixels(a/2, b/2, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, 0); // WORKS SLOOOW- around 3500 microseconds
  </code></pre>
  
  <p>@EDIT: 
    Created FBO texture:</p>
  
  <pre><code>glTexImage2D(GL_TEXTURE_2D, 0,GL_DEPTH_COMPONENT32F , sett.framebuffer_width,  sett.framebuffer_height, 0,GL_DEPTH_COMPONENT, GL_FLOAT, 0);
  </code></pre>
  
  <p>Downloading Depth:</p>
  
  <pre><code>index = (index + 1) % 2;// for ping-pong PBO
  nextIndex = (index + 1) % 2;// for ping-pong PBO
  glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, pboIds[index]);
  glReadPixels(w/2, h/2, 1, 1, GL_DEPTH_COMPONENT , GL_FLOAT, 0);
  glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 0);
  </code></pre>
  
  <p>Copying depth to ram:</p>
  
  <pre><code>GLfloat tabc[10];
  glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, pboIds[nextIndex]);
  GLfloat* srccccc = (GLfloat*)glMapBuffer(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY);
  tabc[0]=*srccccc;
  std::cout&lt;&lt;"Depth center: "&lt;&lt;tabc[0]&lt;&lt;std::endl;//only to check is that correct
  glUnmapBuffer(GL_PIXEL_PACK_BUFFER_ARB);     
  </code></pre>
  
  <p>It's working now, much faster (357 microseconds from 3500 microseconds).
  Is it good right now? All formats?</p>