- if (this->display == NULL) { // this implies that the context is also unitialized
- this->display = display;
- // debugging: show version information
- int glxMajor, glxMinor;
- glXQueryVersion(display, &glxMajor, &glxMinor);
- printf("Using GLX version: %d.%d\n", glxMajor, glxMinor);
- // check for swap control functions
- const char *extensions = glXQueryExtensionsString(display, DefaultScreen(display));
- if (std::string(extensions).find("GLX_MESA_swap_control") != std::string::npos) {
- funSwapIntervalMesa = (PFNGLXSWAPINTERVALMESAPROC)glXGetProcAddress((const GLubyte*)"glXSwapIntervalMESA");
- if (funSwapIntervalMesa) printf("glXSwapIntervalMESA is present\n");
- }
- else {
- funSwapIntervalMesa = 0;
- }
- if (std::string(extensions).find("GLX_EXT_swap_control") != std::string::npos) {
- funSwapIntervalExt = (PFNGLXSWAPINTERVALEXTPROC)glXGetProcAddress((const GLubyte*)"glXSwapIntervalEXT");
- if (funSwapIntervalExt) printf("glXSwapIntervalEXT is present\n");
- }
- else {
- funSwapIntervalExt = 0;
- }
- // get the visual
- vi = glXChooseVisual(display, DefaultScreen(display), attrList);
- }
- return vi->visualid;
+ if (this->display == NULL) { // this implies that the context is also unitialized
+ this->display = display;
+ // debugging: show version information
+ int glxMajor, glxMinor;
+ glXQueryVersion(display, &glxMajor, &glxMinor);
+ printf("Using GLX version: %d.%d\n", glxMajor, glxMinor);
+ if (glxMajor == 1 && glxMinor < 4) {
+ // glXChooseFBConfig and glXCreateNewContext require GLX 1.3; GLX_ARB_create_context requires GLX 1.4
+ die("Need at least GLX 1.4 to function properly\n");
+ }
+ // check for extension-based functions
+ funSwapIntervalMesa = (PFNGLXSWAPINTERVALMESAPROC)resolveGLXFunction("GLX_MESA_swap_control", "glXSwapIntervalMESA");
+ funSwapIntervalExt = (PFNGLXSWAPINTERVALEXTPROC)resolveGLXFunction("GLX_EXT_swap_control", "glXSwapIntervalEXT");
+ funCreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC)resolveGLXFunction("GLX_ARB_create_context", "glXCreateContextAttribsARB");
+ // get the first usable framebuffer configuration
+ int count = 0;
+ GLXFBConfig *configs = glXChooseFBConfig(display, DefaultScreen(display), configAttribs, &count);
+ if (count < 1) {
+ die("Failed to choose framebuffer configuration\n");
+ }
+ config = configs[0];
+ XFree(configs);
+ }
+ // return visual ID
+ XVisualInfo *vi = glXGetVisualFromFBConfig(display, config);
+ if (vi== NULL) {
+ die("The GLXFBConfig I got is invalid\n");
+ }
+ VisualID visualid = vi->visualid;
+ XFree(vi);
+ return visualid;
+}
+
+bool GLXBackend::haveGLXExtension(const std::string &name)
+{
+ assert(display != NULL);
+ std::string extensions = glXQueryExtensionsString(display, DefaultScreen(display));
+ return (std::string(" "+extensions+" ").find(" "+name+" ") != std::string::npos);
+}
+
+T_proc GLXBackend::resolveGLXFunction(const char *extension, const char *function)
+{
+ if (!haveGLXExtension(extension)) return NULL;
+ T_proc f = glXGetProcAddress((const GLubyte*)function);
+ if (f)
+ printf("%s is supported, using it for %s\n", extension, function);
+ else
+ printf("%s is supported, but I could not find %s\n", extension, function);
+ return f;