KiCad PCB EDA Suite
GL_UTILS Class Reference

#include <gl_utils.h>

Static Public Member Functions

static int SetSwapInterval (int aVal)
 Attempts to set the OpenGL swap interval. More...
 

Detailed Description

Definition at line 33 of file gl_utils.h.

Member Function Documentation

◆ SetSwapInterval()

static int GL_UTILS::SetSwapInterval ( int  aVal)
inlinestatic

Attempts to set the OpenGL swap interval.

Parameters
aValif -1 = try to set adaptive swapping, 0 = sync off, 1 = sync with VSYNC rate.
Returns
actual value set

This routine is written for Linux using X11 only. The equivalent functions under Windows would include <wglext.h> and call wglSwapIntervalEXT

Definition at line 42 of file gl_utils.h.

43  {
46 #if defined( __linux__ ) && !defined( KICAD_USE_EGL )
47 
48  Display *dpy = glXGetCurrentDisplay();
49  GLXDrawable drawable = glXGetCurrentDrawable();
50  std::string vendor( reinterpret_cast<const char*>( glGetString( GL_VENDOR ) ) );
51  bool is_mesa = ( vendor.find( "Mesa" ) != std::string::npos );
52 
53  if( !is_mesa && glXSwapIntervalEXT && glXQueryDrawable && dpy && drawable )
54  {
55  std::string exts( glXQueryExtensionsString( dpy, DefaultScreen( dpy ) ) );
56 
57  if( aVal < 0 )
58  {
59  if( exts.find( "GLX_EXT_swap_control_tear" ) == std::string::npos )
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 = 0;
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  }

Referenced by KIGFX::OPENGL_GAL::init(), and EDA_3D_CANVAS::initializeOpenGL().


The documentation for this class was generated from the following file: