From 0e2d3236b50ea52dddf2d911f87ac48c9f0f9f5f Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 7 Jun 2022 22:33:28 +0300 Subject: [PATCH] OpenGL: Fix SetSwapInterval logic. - Don't use GLX extension functions unless they are supported on the connection. GLEW only checks for client library support. - Don't try to set swap interval using glXSwapIntervalSGI when vsync is not requested. Fixes https://gitlab.com/kicad/code/kicad/issues/11751 --- include/gl_utils.h | 88 +++++++++++++++++++++++----------------------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/include/gl_utils.h b/include/gl_utils.h index 0723558f7b..0a80f31991 100644 --- a/include/gl_utils.h +++ b/include/gl_utils.h @@ -24,7 +24,7 @@ #ifndef GL_UTILS_H #define GL_UTILS_H -#include // Must be included first +#include // Must be included first #include #include @@ -45,62 +45,63 @@ public: /// Windows would include and call wglSwapIntervalEXT #if defined( __linux__ ) && !defined( KICAD_USE_EGL ) - Display *dpy = glXGetCurrentDisplay(); - GLXDrawable drawable = glXGetCurrentDrawable(); - std::string vendor( reinterpret_cast( glGetString( GL_VENDOR ) ) ); - bool is_mesa = ( vendor.find( "Mesa" ) != std::string::npos ); - - if( !is_mesa && glXSwapIntervalEXT && glXQueryDrawable && dpy && drawable ) + if( Display* dpy = glXGetCurrentDisplay() ) { + GLXDrawable drawable = glXGetCurrentDrawable(); + std::string exts( glXQueryExtensionsString( dpy, DefaultScreen( dpy ) ) ); - if( aVal < 0 ) + if( glXSwapIntervalEXT && glXQueryDrawable && drawable + && exts.find( "GLX_EXT_swap_control" ) != std::string::npos ) { - if( exts.find( "GLX_EXT_swap_control_tear" ) == std::string::npos ) + if( aVal < 0 ) { - aVal = 0; - } - else - { - // Even though the extensions might be available, - // we need to be sure that late/adaptive swaps are - // enabled on the drawable. - - unsigned lateSwapsEnabled = 0; - glXQueryDrawable( dpy, drawable, GLX_LATE_SWAPS_TEAR_EXT, &lateSwapsEnabled ); - - if( !lateSwapsEnabled ) + if( exts.find( "GLX_EXT_swap_control_tear" ) == std::string::npos ) { aVal = 0; } + else + { + // Even though the extensions might be available, + // we need to be sure that late/adaptive swaps are + // enabled on the drawable. + + unsigned lateSwapsEnabled = 0; + glXQueryDrawable( dpy, drawable, GLX_LATE_SWAPS_TEAR_EXT, + &lateSwapsEnabled ); + + if( !lateSwapsEnabled ) + { + aVal = 0; + } + } } + + unsigned clampedInterval; + glXSwapIntervalEXT( dpy, drawable, aVal ); + glXQueryDrawable( dpy, drawable, GLX_SWAP_INTERVAL_EXT, &clampedInterval ); + + return clampedInterval; } - unsigned clampedInterval; - glXSwapIntervalEXT( dpy, drawable, aVal ); - glXQueryDrawable( dpy, drawable, GLX_SWAP_INTERVAL_EXT, &clampedInterval ); + if( glXSwapIntervalMESA && glXGetSwapIntervalMESA + && exts.find( "GLX_MESA_swap_control" ) != std::string::npos ) + { + if( aVal < 0 ) + aVal = 0; - return clampedInterval; - } + glXSwapIntervalMESA( aVal ); + return glXGetSwapIntervalMESA(); + } - if( glXSwapIntervalMESA &&glXGetSwapIntervalMESA ) - { - if( aVal < 0 ) - aVal = 0; + if( aVal > 0 && glXSwapIntervalSGI + && exts.find( "GLX_SGI_swap_control" ) != std::string::npos ) + { + if( glXSwapIntervalSGI( aVal ) ) + glXSwapIntervalSGI( 1 ); - glXSwapIntervalMESA( aVal ); - return glXGetSwapIntervalMESA(); - } - - if( glXSwapIntervalSGI ) - { - if( aVal < 1 ) - aVal = 1; - - if( glXSwapIntervalSGI( aVal ) ) - glXSwapIntervalSGI( 1 ); - - return 1; + return 1; + } } return std::numeric_limits::max(); @@ -111,4 +112,3 @@ public: }; #endif /* GL_CONTEXT_MANAGER_H */ -