Set VSYNC to adaptive (if available)
Swap syncs can limit the redraw rate as the screen waits for previously issued syncs. Setting this to -1 allows for adaptive swapping (resorting to unsynced if it falls behind) if it is supported by the card but will fall back to unsynced (0) if the adaptive is not supported. Fixes https://gitlab.com/kicad/code/kicad/issues/4226
This commit is contained in:
parent
860e58432b
commit
a210fd570f
|
@ -28,6 +28,7 @@
|
|||
*/
|
||||
|
||||
#include <GL/glew.h> // Must be included first
|
||||
#include <gl_utils.h>
|
||||
#include <wx/tokenzr.h>
|
||||
|
||||
#include "../common_ogl/ogl_utils.h"
|
||||
|
|
|
@ -32,6 +32,8 @@
|
|||
#define GL_SILENCE_DEPRECATION 1
|
||||
#endif
|
||||
|
||||
#include <gl_utils.h>
|
||||
|
||||
#include <gal/opengl/opengl_gal.h>
|
||||
#include <gal/opengl/utils.h>
|
||||
#include <gal/definitions.h>
|
||||
|
@ -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 );
|
||||
|
|
|
@ -478,7 +478,6 @@ private:
|
|||
|
||||
VECTOR2D getScreenPixelSize() const;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Basic OpenGL initialization.
|
||||
*/
|
||||
|
|
|
@ -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 <GL/glxew.h>
|
||||
#endif
|
||||
|
||||
#include <limits>
|
||||
|
||||
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 <wglext.h> 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<int>::max();
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* GL_CONTEXT_MANAGER_H */
|
||||
|
Loading…
Reference in New Issue