backend: glx: add support for setting vsync

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2019-09-25 23:15:17 +01:00
parent db37f74140
commit 0c7a19fda6
No known key found for this signature in database
GPG Key ID: 37C999F617EA1A47
1 changed files with 24 additions and 0 deletions

View File

@ -213,6 +213,22 @@ static void *glx_decouple_user_data(backend_t *base attr_unused, void *ud attr_u
return ret; return ret;
} }
static bool glx_set_swap_interval(int interval, Display *dpy, GLXDrawable drawable) {
bool vsync_enabled = false;
if (glxext.has_GLX_MESA_swap_control) {
vsync_enabled = (glXSwapIntervalMESA((uint)interval) == 0);
}
if (!vsync_enabled && glxext.has_GLX_SGI_swap_control) {
vsync_enabled = (glXSwapIntervalSGI(interval) == 0);
}
if (!vsync_enabled && glxext.has_GLX_EXT_swap_control) {
// glXSwapIntervalEXT doesn't return if it's successful
glXSwapIntervalEXT(dpy, drawable, interval);
vsync_enabled = true;
}
return vsync_enabled;
}
/** /**
* Initialize OpenGL. * Initialize OpenGL.
*/ */
@ -327,6 +343,14 @@ static backend_t *glx_init(session_t *ps) {
gd->gl.decouple_texture_user_data = glx_decouple_user_data; gd->gl.decouple_texture_user_data = glx_decouple_user_data;
gd->gl.release_user_data = glx_release_image; gd->gl.release_user_data = glx_release_image;
if (ps->o.vsync) {
if (!glx_set_swap_interval(1, ps->dpy, tgt)) {
log_error("Failed to enable vsync.");
}
} else {
glx_set_swap_interval(0, ps->dpy, tgt);
}
success = true; success = true;
end: end: