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 );
116 const GLubyte* version = glGetString( GL_VERSION );
118 if( wglSwapIntervalEXT && wxGLCanvas::IsExtensionSupported(
"WGL_EXT_swap_control" ) )
120 wxString vendorStr = vendor;
121 wxString versionStr = version;
123 if( aVal == -1 && ( !wxGLCanvas::IsExtensionSupported(
"WGL_EXT_swap_control_tear" ) ) )
127 if( aVal == -1 && vendorStr == wxS(
"ATI Technologies Inc." ) )
129 wxArrayString parts = wxSplit( versionStr.AfterLast(
' ' ),
'.', 0 );
131 if( parts.size() == 4 )
135 if( parts[0].ToLong( &majorVer ) )
143 HDC hdc = wglGetCurrentDC();
144 HGLRC hglrc = wglGetCurrentContext();
148 int currentInterval = wglGetSwapIntervalEXT();
150 if( currentInterval != aVal )
152 wglSwapIntervalEXT( aVal );
153 currentInterval = wglGetSwapIntervalEXT();
156 return currentInterval;
167 #pragma GCC pop_options
169 #pragma optimize( "", on )
static int SetSwapInterval(int aVal)
Attempts to set the OpenGL swap interval.