From ee9db307520ff2bcb99d78f4f21be715cf2d5c22 Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Mon, 9 May 2022 09:51:40 +0200 Subject: [PATCH] GL: change vsync back to 1 This reverts b80fcf18 while addressing the resize issue that the original commit was supposed to solve. Adaptive VSync may cause tearing if real frame rate is lower than nominal (display) frame rate. see also #227 --- src/video_display/gl.cpp | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/src/video_display/gl.cpp b/src/video_display/gl.cpp index bb9ae4090..d95a2f1c8 100644 --- a/src/video_display/gl.cpp +++ b/src/video_display/gl.cpp @@ -357,7 +357,7 @@ struct state_gl { time_ns_t t0 = get_time_in_ns(); - int vsync = ADAPTIVE_VSYNC; + int vsync = 1; bool paused = false; enum show_cursor_t { SC_TRUE, SC_FALSE, SC_AUTOHIDE } show_cursor = SC_AUTOHIDE; chrono::steady_clock::time_point cursor_shown_from{}; ///< indicates time point from which is cursor show if show_cursor == SC_AUTOHIDE, timepoint() means cursor is not currently shown @@ -1038,6 +1038,12 @@ static void gl_process_frames(struct state_gl *s) return; } frame = s->frame_queue.front(); + + if (s->current_frame) { + vf_recycle(s->current_frame); + s->free_frame_queue.push(s->current_frame); + } + s->current_frame = frame; } if (!frame) { @@ -1057,14 +1063,6 @@ static void gl_process_frames(struct state_gl *s) gl_reconfigure_screen(s, video_desc_from_frame(frame)); } - if (s->current_frame) { - s->lock.lock(); - vf_recycle(s->current_frame); - s->free_frame_queue.push(s->current_frame); - s->lock.unlock(); - } - s->current_frame = frame; - gl_render(s, frame->tiles[0].data); gl_draw(s->aspect, (s->dxt_height - s->current_display_desc.height) / (float) s->dxt_height * 2, s->vsync != SINGLE_BUF); @@ -1242,17 +1240,15 @@ static void display_gl_print_depth() { static void display_gl_render_last(GLFWwindow *win) { auto *s = (struct state_gl *) glfwGetWindowUserPointer(win); - if (!s->current_frame) { + unique_lock lk(s->lock); + auto *f = s->current_frame; + s->current_frame = nullptr; + lk.unlock(); + if (!f) { return; } // redraw last frame - gl_render(s, s->current_frame->tiles[0].data); - gl_draw(s->aspect, (s->dxt_height - s->current_display_desc.height) / (float) s->dxt_height * 2, s->vsync != SINGLE_BUF); - if (s->vsync == SINGLE_BUF) { - glFlush(); - } else { - glfwSwapBuffers(s->window); - } + display_gl_putf(s, f, PUTF_NONBLOCK); } #if defined HAVE_LINUX || defined WIN32