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 #ifdef __linux__
28 #include <GL/glxew.h>
29 #endif
30 
31 #include <limits>
32 
33 class GL_UTILS
34 {
35 public:
41  static int SetSwapInterval( int aVal )
42  {
45  #ifdef __linux__
46  Display *dpy = glXGetCurrentDisplay();
47  GLXDrawable drawable = glXGetCurrentDrawable();
48 
49  if( glXSwapIntervalEXT && glXQueryDrawable && dpy && drawable )
50  {
51  unsigned clampedInterval;
52  glXSwapIntervalEXT( dpy, drawable, aVal );
53  glXQueryDrawable( dpy, drawable, GLX_SWAP_INTERVAL_EXT, &clampedInterval );
54 
55  return clampedInterval;
56  }
57 
58  if( glXSwapIntervalMESA &&glXGetSwapIntervalMESA )
59  {
60  if( aVal < 0 )
61  aVal = 0;
62 
63  glXSwapIntervalMESA( aVal );
64  return glXGetSwapIntervalMESA();
65  }
66 
67  if( glXSwapIntervalSGI )
68  {
69  if( aVal < 1 )
70  aVal = 1;
71 
72  if( glXSwapIntervalSGI( aVal ) )
73  glXSwapIntervalSGI( 1 );
74 
75  return 1;
76  }
77 
78  return std::numeric_limits<int>::max();
79  #else
80  return 0;
81  #endif
82  }
83 };
84 
85 #endif /* GL_CONTEXT_MANAGER_H */
86 
static int SetSwapInterval(int aVal)
Attempts to set the OpenGL swap interval.
Definition: gl_utils.h:41