0

I am developing an application that needs to read back the whole frame from the openGL frame buffer.
In order to improve the performance, I'm using asynchronous glReadPixels with multiple PBOs:

glBindBuffer(GL_PIXEL_PACK_BUFFER, m_pbos[m_index]);
glReadPixels(0, 0, GLL_WINDOW_SIZE, GLL_WINDOW_SIZE, GL_RED, GL_UNSIGNED_BYTE, 0);
glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);

After reading some tutorials, I do the following (e.g. with 2 PBOs):

  1. draw frame N (glDrawArrays)
  2. start asynchronous read of PBO N from buffer (see above)
  3. draw frame N+1 (glDrawArrays)
  4. start asynchronous read of PBO N+1 from buffer (see above)
  5. sync PBO read N (glMapBuffer)
  6. process N
  7. draw frame N+2 (glDrawArrays)
  8. ...

This seems to work correctly, but I have some concerns regarding the pipeline.
Typically, the drawing operation on frame N+1 (3) is done before the completion of the asynchronous reading of the frame N (2).
Is the frame buffer overwritten by the drawing operation?
If the glReadPixels runs asynchronously (2), is the frame N corrupted by this overwrite?

iome
  • 153
  • 7
  • A [OpenGL Context](https://www.khronos.org/opengl/wiki/OpenGL_Context) is thread-local. A single context cannot be current in multiple threads at the same time. Do you use multiple and shared contexts? – Rabbid76 Sep 08 '20 at 14:56
  • 1
    It is a single thread application. The glReadPixels() with PBO can schedule asynchronous DMA transfer and returns immediately without stall. Therefore, the CPU can execute other process – iome Sep 09 '20 at 07:56

0 Answers0