From e9161f67fe097b2e79f0068af72f272417a65734 Mon Sep 17 00:00:00 2001 From: Themaister Date: Sun, 27 Apr 2014 10:40:24 +0200 Subject: [PATCH] Avoid reading back random RGUI frames in async recording. --- gfx/gl.c | 11 +++++++---- gfx/gl_common.h | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/gfx/gl.c b/gfx/gl.c index 42af5f5c64..cc405747dc 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -1327,8 +1327,8 @@ static void gl_pbo_async_readback(void *data) glBindBuffer(GL_PIXEL_PACK_BUFFER, gl->pbo_readback[gl->pbo_readback_index++]); gl->pbo_readback_index &= 3; - // If set, we 3 rendered frames already buffered up. - gl->pbo_readback_valid |= gl->pbo_readback_index == 0; + // 4 frames back, we can readback. + gl->pbo_readback_valid[gl->pbo_readback_index] = true; glPixelStorei(GL_PACK_ROW_LENGTH, 0); glPixelStorei(GL_PACK_ALIGNMENT, get_alignment(gl->vp.width * sizeof(uint32_t))); @@ -1557,7 +1557,8 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei GL_RGBA, GL_UNSIGNED_BYTE, gl->readback_buffer_screenshot); } #ifdef HAVE_GL_ASYNC_READBACK - else if (gl->pbo_readback_enable) + // Don't readback if we're in RGUI. + else if (gl->pbo_readback_enable && !gl->rgui_texture_enable) gl_pbo_async_readback(gl); #endif #endif @@ -2464,12 +2465,14 @@ static bool gl_read_viewport(void *data, uint8_t *buffer) #ifdef HAVE_GL_ASYNC_READBACK if (gl->pbo_readback_enable) { - if (!gl->pbo_readback_valid) // We haven't buffered up enough frames yet, come back later. + // Don't readback if we're in RGUI. + if (!gl->pbo_readback_valid[gl->pbo_readback_index]) // We haven't buffered up enough frames yet, come back later. { context_bind_hw_render(gl, true); return false; } + gl->pbo_readback_valid[gl->pbo_readback_index] = false; glBindBuffer(GL_PIXEL_PACK_BUFFER, gl->pbo_readback[gl->pbo_readback_index]); #ifdef HAVE_OPENGLES3 // Slower path, but should work on all implementations at least. diff --git a/gfx/gl_common.h b/gfx/gl_common.h index 0d1ac66b99..4569343ead 100644 --- a/gfx/gl_common.h +++ b/gfx/gl_common.h @@ -247,8 +247,8 @@ typedef struct gl #ifdef HAVE_GL_ASYNC_READBACK // PBOs used for asynchronous viewport readbacks. GLuint pbo_readback[4]; + bool pbo_readback_valid[4]; bool pbo_readback_enable; - bool pbo_readback_valid; unsigned pbo_readback_index; struct scaler_ctx pbo_readback_scaler; #endif