/** * Attempt to determine whether or not the display is synched to vblank. */ static void query_vsync(Display *dpy) { int interval = 0; if (is_glx_extension_supported(dpy, "GLX_MESA_swap_control")) { PFNGLXGETSWAPINTERVALMESAPROC pglXGetSwapIntervalMESA = (PFNGLXGETSWAPINTERVALMESAPROC) glXGetProcAddressARB((const GLubyte *) "glXGetSwapIntervalMESA"); interval = (*pglXGetSwapIntervalMESA)(); } else if (is_glx_extension_supported(dpy, "GLX_SGI_swap_control")) { /* The default swap interval with this extension is 1. Assume that it * is set to the default. * * Many Mesa-based drivers default to 0, but all of these drivers also * export GLX_MESA_swap_control. In that case, this branch will never * be taken, and the correct result should be reported. */ interval = 1; } if (interval > 0) { printf("Running synchronized to the vertical refresh. The framerate should be\n"); if (interval == 1) { printf("approximately the same as the monitor refresh rate.\n"); } else if (interval > 1) { printf("approximately 1/%d the monitor refresh rate.\n", interval); } } }
/** * Attempt to determine whether or not the display is synched to vblank. */ static void query_vsync(Display *dpy, GLXDrawable drawable) { int interval = 0; #if defined(GLX_EXT_swap_control) if (is_glx_extension_supported(dpy, "GLX_EXT_swap_control")) { PFNGLXSWAPINTERVALEXTPROC pglXSwapIntervalEXT = (PFNGLXSWAPINTERVALEXTPROC) glXGetProcAddressARB((const GLubyte *) "glXSwapIntervalEXT"); unsigned int tmp = -1; if (swapinterval >= 1) (*pglXSwapIntervalEXT)(dpy, drawable, swapinterval); glXQueryDrawable(dpy, drawable, GLX_SWAP_INTERVAL_EXT, &tmp); interval = tmp; } else #endif if (is_glx_extension_supported(dpy, "GLX_MESA_swap_control")) { PFNGLXGETSWAPINTERVALMESAPROC pglXGetSwapIntervalMESA = (PFNGLXGETSWAPINTERVALMESAPROC) glXGetProcAddressARB((const GLubyte *) "glXGetSwapIntervalMESA"); if (swapinterval >= 1) { PFNGLXSWAPINTERVALMESAPROC pglXSwapIntervalMESA = (PFNGLXSWAPINTERVALMESAPROC) glXGetProcAddressARB((const GLubyte *) "glXSwapIntervalMESA"); (*pglXSwapIntervalMESA)(swapinterval); } interval = (*pglXGetSwapIntervalMESA)(); } else if (is_glx_extension_supported(dpy, "GLX_SGI_swap_control")) { /* The default swap interval with this extension is 0. Assume that it * is set to the default unless it was overridden on the command line. */ interval = 0; if (swapinterval >= 1) { PFNGLXSWAPINTERVALSGIPROC pglXSwapIntervalSGI = (PFNGLXSWAPINTERVALSGIPROC) glXGetProcAddressARB((const GLubyte *) "glXSwapIntervalSGI"); (*pglXSwapIntervalSGI)(swapinterval); interval = swapinterval; } } if (interval > 0) { printf("Running synchronized to the vertical refresh. The framerate should be\n"); if (interval == 1) { printf("approximately the same as the monitor refresh rate.\n"); } else if (interval > 1) { printf("approximately 1/%d the monitor refresh rate.\n", interval); } } }
void CL_OpenGLWindowProvider_GLX::setup_swap_interval_pointers() { glXSwapIntervalSGI = (ptr_glXSwapIntervalSGI) CL_OpenGL::get_proc_address("glXSwapIntervalSGI"); glXSwapIntervalMESA = (ptr_glXSwapIntervalMESA) CL_OpenGL::get_proc_address("glXSwapIntervalMESA"); // See - http://dri.freedesktop.org/wiki/glXGetProcAddressNeverReturnsNULL ,get_proc_address() may return an invalid extension address if ( !is_glx_extension_supported("GLX_SGI_swap_control") ) { glXSwapIntervalSGI = NULL; } if ( !is_glx_extension_supported("GLX_MESA_swap_control") ) { glXSwapIntervalMESA = NULL; } }
static void query_swap_event(Display *dpy) { if ( ! is_glx_extension_supported(dpy, "GLX_INTEL_swap_event")) { printf("The GLX_INTEL_swap_event is not supported in current version.\n"); piglit_report_result(PIGLIT_SKIP); } else { printf("The GLX_INTEL_swap_event is supported in current version.\n"); } if (interval_diff) { if ( ! is_glx_extension_supported(dpy, "GLX_MESA_swap_control")) { printf("GLX_MESA_swap_control was not supported by the driver.\n"); piglit_report_result(PIGLIT_SKIP); } else { pglXGetSwapIntervalMESA = (PFNGLXGETSWAPINTERVALMESAPROC) glXGetProcAddressARB((const GLubyte *) "glXGetSwapIntervalMESA"); pglXSwapIntervalMESA = (PFNGLXSWAPINTERVALMESAPROC) glXGetProcAddressARB((const GLubyte *) "glXSwapIntervalMESA"); } } }
GLXContext CL_OpenGLWindowProvider_GLX::create_context_glx_1_3(const CL_OpenGLWindowDescription &gl_desc, GLXContext shared_context) { GLXContext context; context = glx.glXCreateNewContext(x11_window.get_display(), fbconfig, GLX_RGBA_TYPE, shared_context, True); if(context == NULL) throw CL_Exception("glXCreateContext failed"); ptr_glXCreateContextAttribs glXCreateContextAttribs = NULL; if (is_glx_extension_supported("GLX_ARB_create_context")) { if (glx.glXGetProcAddressARB) glXCreateContextAttribs = (ptr_glXCreateContextAttribs) glx.glXGetProcAddressARB((GLubyte*) "glXCreateContextAttribsARB"); if (glx.glXGetProcAddress) glXCreateContextAttribs = (ptr_glXCreateContextAttribs) glx.glXGetProcAddress((GLubyte*) "glXCreateContextAttribsARB"); } if (glXCreateContextAttribs) { // Install an X error handler so the application won't exit if GL 3.0 context allocation fails. // // Note this error handler is global. All display connections in all threads // of a process use the same error handler, so be sure to guard against other // threads issuing X commands while this code is running. int (*oldHandler)(Display*, XErrorEvent*) = XSetErrorHandler(&cl_ctxErrorHandler); GLXContext context_gl3 = 0; int gl_major = gl_desc.get_version_major(); int gl_minor = gl_desc.get_version_minor(); if (gl_desc.get_allow_lower_versions() == false) { context_gl3 = create_context_glx_1_3_helper(shared_context, gl_major, gl_minor, gl_desc, glXCreateContextAttribs); if (!context_gl3) throw CL_Exception(cl_format("This application requires OpenGL %1.%2 or above. Try updating your drivers, or upgrade to a newer graphics card.", gl_major, gl_minor)); } else { static const char opengl_version_list[] = { // Clanlib supported version pairs 4,1, 4,0, 3,3, 3,2, 3,1, 3,0, 0,0, // End of list }; const char *opengl_version_list_ptr = opengl_version_list; do { int major = *(opengl_version_list_ptr++); if (major == 0) break; int minor = *(opengl_version_list_ptr++); // Find the appropriate version in the list if (major > gl_major) continue; if (major == gl_major) { if (minor > gl_minor) continue; } context_gl3 = create_context_glx_1_3_helper(shared_context, gl_major, gl_minor, gl_desc, glXCreateContextAttribs); }while(!context_gl3); } // Restore the original error handler XSetErrorHandler( oldHandler ); if (context_gl3) { glx.glXDestroyContext(x11_window.get_display(), context); context = context_gl3; } } return context; }