title: Reading data from the GPU asynchronously with Pixel Buffer Objects
body: <p>Getting data from the GPU seems to be a very slow task if you want to read it synchronized with the rest of your application. One possibility is to read <em>asynchronously</em> with the help of Pixel Buffer Objects. Unfortunately, I am not able to see how this is done.</p>
  <p>First, I create a Pixel Buffer Object:</p>
  <pre><code>glGenBuffers(1, &amp;pbo);
  glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo);
  glBufferData(GL_PIXEL_PACK_BUFFER, pbo_size, 0, GL_DYNAMIC_READ);
  glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
  </code></pre>
  <p>Then I want to read pixels from a Frame Buffer Object:</p>
  <pre><code>glReadBuffer(GL_COLOR_ATTACHMENT0);
  glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo);
  glReadPixels(0, 0, w, h, GL_RGBA, GL_FLOAT, 0);
  GLfloat *ptr = glMapBufferRange(GL_PIXEL_PACK_BUFFER, 0, pbo_size, GL_MAP_READ_BIT);
  memcpy(pixels, ptr, pbo_size);
  glUnmapBuffer(GL_PIXEL_PACK_BUFFER);
  glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
  </code></pre>
  <p>But how is this asynchronous? Is glReadPixels or glMapBufferRange blocking the application until the GPU is 'ready'?</p>