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):
- draw frame N (glDrawArrays)
- start asynchronous read of PBO N from buffer (see above)
- draw frame N+1 (glDrawArrays)
- start asynchronous read of PBO N+1 from buffer (see above)
- sync PBO read N (glMapBuffer)
- process N
- draw frame N+2 (glDrawArrays)
- ...
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?