KiCad PCB EDA Suite
gl_utils.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2020 Kicad Developers, see AUTHORS.txt for contributors
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-3.0.html
19  * or you may search the http://www.gnu.org website for the version 3 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23 
24 #ifndef GL_UTILS_H
25 #define GL_UTILS_H
26 
27 #include <gal/opengl/kiglew.h> // Must be included first
28 #include <wx/utils.h>
29 
30 #include <limits>
31 
32 class GL_UTILS
33 {
34 public:
41  static int SetSwapInterval( int aVal )
42  {
45 #if defined( __linux__ ) && !defined( KICAD_USE_EGL )
46 
49  if( wxGetEnv( wxT( "SSH_CONNECTION"), nullptr ) )
50  return 0;
51 
52  Display *dpy = glXGetCurrentDisplay();
53  GLXDrawable drawable = glXGetCurrentDrawable();
54 
55  if( glXSwapIntervalEXT && glXQueryDrawable && dpy && drawable )
56  {
57  if( aVal < 0 )
58  {
59  if( !GLX_EXT_swap_control_tear )
60  {
61  aVal = 0;
62  }
63  else
64  {
65  // Even though the extensions might be available,
66  // we need to be sure that late/adaptive swaps are
67  // enabled on the drawable.
68 
69  unsigned lateSwapsEnabled;
70  glXQueryDrawable( dpy, drawable, GLX_LATE_SWAPS_TEAR_EXT, &lateSwapsEnabled );
71 
72  if( !lateSwapsEnabled )
73  {
74  aVal = 0;
75  }
76  }
77  }
78 
79  unsigned clampedInterval;
80  glXSwapIntervalEXT( dpy, drawable, aVal );
81  glXQueryDrawable( dpy, drawable, GLX_SWAP_INTERVAL_EXT, &clampedInterval );
82 
83  return clampedInterval;
84  }
85 
86  if( glXSwapIntervalMESA &&glXGetSwapIntervalMESA )
87  {
88  if( aVal < 0 )
89  aVal = 0;
90 
91  glXSwapIntervalMESA( aVal );
92  return glXGetSwapIntervalMESA();
93  }
94 
95  if( glXSwapIntervalSGI )
96  {
97  if( aVal < 1 )
98  aVal = 1;
99 
100  if( glXSwapIntervalSGI( aVal ) )
101  glXSwapIntervalSGI( 1 );
102 
103  return 1;
104  }
105 
106  return std::numeric_limits<int>::max();
107 #else
108  return 0;
109 #endif
110  }
111 };
112 
113 #endif /* GL_CONTEXT_MANAGER_H */
114 
static int SetSwapInterval(int aVal)
Attempts to set the OpenGL swap interval.
Definition: gl_utils.h:41