28#include <wx/glcanvas.h>
33 #pragma GCC push_options
34 #pragma GCC optimize( "O0" )
36 #pragma optimize( "", off )
51#if defined( __linux__ ) && !defined( KICAD_USE_EGL )
53 if( Display* dpy = glXGetCurrentDisplay() )
55 GLXDrawable drawable = glXGetCurrentDrawable();
57 std::string exts( glXQueryExtensionsString( dpy, DefaultScreen( dpy ) ) );
59 if( glXSwapIntervalEXT && glXQueryDrawable && drawable
60 && exts.find(
"GLX_EXT_swap_control" ) != std::string::npos )
64 if( exts.find(
"GLX_EXT_swap_control_tear" ) == std::string::npos )
74 unsigned lateSwapsEnabled = 0;
75 glXQueryDrawable( dpy, drawable, GLX_LATE_SWAPS_TEAR_EXT,
78 if( !lateSwapsEnabled )
85 unsigned clampedInterval;
86 glXSwapIntervalEXT( dpy, drawable, aVal );
87 glXQueryDrawable( dpy, drawable, GLX_SWAP_INTERVAL_EXT, &clampedInterval );
89 return clampedInterval;
92 if( glXSwapIntervalMESA && glXGetSwapIntervalMESA
93 && exts.find(
"GLX_MESA_swap_control" ) != std::string::npos )
98 if( !glXSwapIntervalMESA( aVal ) )
102 if( glXSwapIntervalSGI && exts.find(
"GLX_SGI_swap_control" ) != std::string::npos )
107 if( !glXSwapIntervalSGI( aVal ) )
112#elif defined( _WIN32 )
114 const GLubyte* vendor = glGetString( GL_VENDOR );
115 const GLubyte* version = glGetString( GL_VERSION );
117 if( wglSwapIntervalEXT && wxGLCanvas::IsExtensionSupported(
"WGL_EXT_swap_control" ) )
119 wxString vendorStr = vendor;
120 wxString versionStr = version;
122 if( aVal == -1 && ( !wxGLCanvas::IsExtensionSupported(
"WGL_EXT_swap_control_tear" ) ) )
126 if( aVal == -1 && vendorStr == wxS(
"ATI Technologies Inc." ) )
128 wxArrayString parts = wxSplit( versionStr.AfterLast(
' ' ),
'.', 0 );
130 if( parts.size() == 4 )
134 if( parts[0].ToLong( &majorVer ) )
142 HDC hdc = wglGetCurrentDC();
143 HGLRC hglrc = wglGetCurrentContext();
147 int currentInterval = wglGetSwapIntervalEXT();
149 if( currentInterval != aVal )
151 wglSwapIntervalEXT( aVal );
152 currentInterval = wglGetSwapIntervalEXT();
155 return currentInterval;
166 #pragma GCC pop_options
168 #pragma optimize( "", on )
static int SetSwapInterval(int aVal)
Attempt to set the OpenGL swap interval.