diff --git a/3d-viewer/3d_canvas/eda_3d_canvas.cpp b/3d-viewer/3d_canvas/eda_3d_canvas.cpp index 03ba99efd2..a95e2c29bf 100644 --- a/3d-viewer/3d_canvas/eda_3d_canvas.cpp +++ b/3d-viewer/3d_canvas/eda_3d_canvas.cpp @@ -28,6 +28,7 @@ */ #include // Must be included first +#include #include #include "../common_ogl/ogl_utils.h" diff --git a/common/gal/opengl/opengl_gal.cpp b/common/gal/opengl/opengl_gal.cpp index ef6944a790..fe7f30b6ce 100644 --- a/common/gal/opengl/opengl_gal.cpp +++ b/common/gal/opengl/opengl_gal.cpp @@ -32,6 +32,8 @@ #define GL_SILENCE_DEPRECATION 1 #endif +#include + #include #include #include @@ -2040,6 +2042,8 @@ void OPENGL_GAL::init() throw std::runtime_error( "Requested texture size is not supported" ); } + GL_UTILS::SetSwapInterval( -1 ); + cachedManager = new VERTEX_MANAGER( true ); nonCachedManager = new VERTEX_MANAGER( false ); overlayManager = new VERTEX_MANAGER( false ); diff --git a/include/gal/opengl/opengl_gal.h b/include/gal/opengl/opengl_gal.h index 5d0e97fee1..ad367289fa 100644 --- a/include/gal/opengl/opengl_gal.h +++ b/include/gal/opengl/opengl_gal.h @@ -478,7 +478,6 @@ private: VECTOR2D getScreenPixelSize() const; - /** * @brief Basic OpenGL initialization. */ diff --git a/include/gl_utils.h b/include/gl_utils.h new file mode 100644 index 0000000000..30760d6b55 --- /dev/null +++ b/include/gl_utils.h @@ -0,0 +1,86 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2020 Kicad Developers, see AUTHORS.txt for contributors + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-3.0.html + * or you may search the http://www.gnu.org website for the version 3 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef GL_UTILS_H +#define GL_UTILS_H + +#ifndef __WINDOWS__ +#include +#endif + +#include + +class GL_UTILS +{ +public: + /** + * Attempts to set the OpenGL swap interval + * @param aVal if -1 = try to set adaptive swapping, 0 = sync off, 1 = sync with VSYNC rate + * @return actual value set + */ + static int SetSwapInterval( int aVal ) + { + /// This routine is written for Linux only. The equivalent functions under Windows would + /// include and call wglSwapIntervalEXT + #ifndef __WINDOWS__ + Display *dpy = glXGetCurrentDisplay(); + GLXDrawable drawable = glXGetCurrentDrawable(); + + if( glXSwapIntervalEXT && glXQueryDrawable && dpy && drawable ) + { + unsigned clampedInterval; + glXSwapIntervalEXT( dpy, drawable, aVal ); + glXQueryDrawable( dpy, drawable, GLX_SWAP_INTERVAL_EXT, &clampedInterval ); + + return clampedInterval; + } + + if( glXSwapIntervalMESA &&glXGetSwapIntervalMESA ) + { + if( aVal < 0 ) + aVal = 0; + + glXSwapIntervalMESA( aVal ); + return glXGetSwapIntervalMESA(); + } + + if( glXSwapIntervalSGI ) + { + if( aVal < 1 ) + aVal = 1; + + if( glXSwapIntervalSGI( aVal ) ) + glXSwapIntervalSGI( 1 ); + + return 1; + } + + return std::numeric_limits::max(); + #else + return 0; + #endif + } +}; + +#endif /* GL_CONTEXT_MANAGER_H */ +