Пример #1
0
/*< private >*/
void
_gdk_x11_gl_print_glx_info (Display *xdisplay,
                            int      screen_num)
{
    static gboolean done = FALSE;

    if (!done)
    {
        g_message (" -- Server GLX_VENDOR     : %s",
                   glXQueryServerString (xdisplay, screen_num, GLX_VENDOR));
        g_message (" -- Server GLX_VERSION    : %s",
                   glXQueryServerString (xdisplay, screen_num, GLX_VERSION));
        g_message (" -- Server GLX_EXTENSIONS : %s",
                   glXQueryServerString (xdisplay, screen_num, GLX_EXTENSIONS));

        g_message (" -- Client GLX_VENDOR     : %s",
                   glXGetClientString (xdisplay, GLX_VENDOR));
        g_message (" -- Client GLX_VERSION    : %s",
                   glXGetClientString (xdisplay, GLX_VERSION));
        g_message (" -- Client GLX_EXTENSIONS : %s",
                   glXGetClientString (xdisplay, GLX_EXTENSIONS));

        done = TRUE;
    }
}
static gboolean
_has_texture_from_pixmap (Display *display)
{
        int screen;
        const char *server_extensions;
        const char *client_extensions;
        gboolean ret = FALSE;

        screen = DefaultScreen (display);

        server_extensions = glXQueryServerString (display, screen,
                                                  GLX_EXTENSIONS);
        if (!_has_extension (server_extensions,
                            "GLX_EXT_texture_from_pixmap"))
                goto out;

        client_extensions = glXGetClientString (display, GLX_EXTENSIONS);
        if (!_has_extension (client_extensions,
                            "GLX_EXT_texture_from_pixmap"))
                goto out;

        ret = TRUE;

out:
        return ret;
}
Пример #3
0
/**
 * Test if we pixel buffers are available for a particular X screen.
 * Input:  dpy - the X display
 *         screen - screen number
 * Return:  0 = pixel buffers not available.
 *          1 = pixel buffers are available via GLX 1.3.
 *          2 = pixel buffers are available via GLX_SGIX_fbconfig/pbuffer.
 */
int
QueryPbuffers(Display *dpy, int screen)
{
#if defined(GLX_VERSION_1_3)
   {
      /* GLX 1.3 supports pbuffers */
      int glxVersionMajor, glxVersionMinor;
      if (!glXQueryVersion(dpy, &glxVersionMajor, &glxVersionMinor)) {
         /* GLX not available! */
         return 0;
      }
      if (glxVersionMajor * 100 + glxVersionMinor >= 103) {
         return 1;
      }
      /* fall-through */
   }
#endif

#if defined(GLX_SGIX_fbconfig) && defined(GLX_SGIX_pbuffer)
   /* Try the SGIX extensions */
   {
      char *extensions;
      extensions = (char *) glXQueryServerString(dpy, screen, GLX_EXTENSIONS);
      if (!extensions ||
          !strstr(extensions,"GLX_SGIX_fbconfig") ||
          !strstr(extensions,"GLX_SGIX_pbuffer")) {
         return 0;
      }
      return 2;
   }
#endif

   return 0;
}
HeadlessDisplay::HeadlessDisplay() {
#if MBGL_USE_CGL
    // TODO: test if OpenGL 4.1 with GL_ARB_ES2_compatibility is supported
    // If it is, use kCGLOGLPVersion_3_2_Core and enable that extension.
    CGLPixelFormatAttribute attributes[] = {
        kCGLPFAOpenGLProfile,
        static_cast<CGLPixelFormatAttribute>(kCGLOGLPVersion_Legacy),
        kCGLPFAAccelerated,
        static_cast<CGLPixelFormatAttribute>(0)
    };

    GLint num;
    CGLError error = CGLChoosePixelFormat(attributes, &pixelFormat, &num);
    if (error != kCGLNoError) {
        throw std::runtime_error(std::string("Error choosing pixel format:") + CGLErrorString(error) + "\n");
        return;
    }
    if (num <= 0) {
        throw std::runtime_error("No pixel formats found.");
        return;
    }
#endif

#if MBGL_USE_GLX
    if (!XInitThreads()) {
        throw std::runtime_error("Failed to XInitThreads.");
    }

    xDisplay = XOpenDisplay(nullptr);
    if (xDisplay == nullptr) {
        throw std::runtime_error("Failed to open X display.");
    }

    const char *extensions = reinterpret_cast<const char *>(glXQueryServerString(xDisplay, DefaultScreen(xDisplay), GLX_EXTENSIONS));
    if (!extensions) {
        throw std::runtime_error("Cannot read GLX extensions.");
    }
    if (!strstr(extensions,"GLX_SGIX_fbconfig")) {
        throw std::runtime_error("Extension GLX_SGIX_fbconfig was not found.");
    }
    if (!strstr(extensions, "GLX_SGIX_pbuffer")) {
        throw std::runtime_error("Cannot find glXCreateContextAttribsARB.");
    }

    // We're creating a dummy pbuffer anyway that we're not using.
    static int pixelFormat[] = {
        GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT,
        None
    };

    int configs = 0;
    fbConfigs = glXChooseFBConfig(xDisplay, DefaultScreen(xDisplay), pixelFormat, &configs);
    if (fbConfigs == nullptr) {
        throw std::runtime_error("Failed to glXChooseFBConfig.");
    }
    if (configs <= 0) {
        throw std::runtime_error("No Framebuffer configurations.");
    }
#endif
}
Пример #5
0
JNIEXPORT jint JNICALL GLX_NATIVE(glXQueryServerString)
	(JNIEnv *env, jclass that, jint arg0, jint arg1, jint arg2)
{
	jint rc = 0;
	GLX_NATIVE_ENTER(env, that, glXQueryServerString_FUNC);
	rc = (jint)glXQueryServerString(arg0, arg1, arg2);
	GLX_NATIVE_EXIT(env, that, glXQueryServerString_FUNC);
	return rc;
}
Пример #6
0
static void screenInfo( Display *dpy, int scrnum, QString &infotext )
{
    const char *serverVendor = glXQueryServerString( dpy, scrnum, GLX_VENDOR );
    const char *serverVersion = glXQueryServerString( dpy, scrnum, GLX_VERSION );
    const char *serverExtensions = glXQueryServerString( dpy, scrnum, GLX_EXTENSIONS );
    const char *clientVendor = glXGetClientString( dpy, GLX_VENDOR );
    const char *clientVersion = glXGetClientString( dpy, GLX_VERSION );
    const char *clientExtensions = glXGetClientString( dpy, GLX_EXTENSIONS );
    const char *glxExtensions = glXQueryExtensionsString( dpy, scrnum );
    const char *glVendor = (const char *) glGetString( GL_VENDOR );
    const char *glRenderer = (const char *) glGetString( GL_RENDERER );
    const char *glVersion = (const char *) glGetString( GL_VERSION );
    const char *glExtensions = (const char *) glGetString( GL_EXTENSIONS );
    const char *gluVersion = (const char *) gluGetString( (GLenum) GLU_VERSION );
    const char *gluExtensions = (const char *) gluGetString( (GLenum) GLU_EXTENSIONS );

    infotext.sprintf( "%sServer GLX vendor string: %s\n", infotext.ascii(), serverVendor );
    infotext.sprintf( "%sServer GLX version string: %s\n", infotext.ascii(), serverVersion );
    infotext.sprintf( "%sServer GLX extensions:\n", infotext.ascii() );

    infotext += QString( serverExtensions ).replace( ' ', '\n' ) + "\n\n";

    infotext.sprintf( "%sClient GLX vendor string: %s\n", infotext.ascii(), clientVendor );
    infotext.sprintf( "%sClient GLX version string: %s\n", infotext.ascii(), clientVersion );
    infotext.sprintf( "%sClient GLX extensions:\n", infotext.ascii() );

    infotext += QString( clientExtensions ).replace( ' ', '\n' ) + "\n\n";

    infotext.sprintf( "%sGLX extensions:\n", infotext.ascii() );

    infotext += QString( glxExtensions ).replace( ' ', '\n' ) + "\n\n";

    infotext.sprintf( "%sOpenGL vendor string: %s\n", infotext.ascii(), glVendor );
    infotext.sprintf( "%sOpenGL renderer string: %s\n", infotext.ascii(), glRenderer );
    infotext.sprintf( "%sOpenGL version string: %s\n", infotext.ascii(), glVersion );
    infotext.sprintf( "%sOpenGL extensions:\n", infotext.ascii() );

    infotext += QString( glExtensions ).replace( ' ', '\n' ) + "\n\n";

    infotext.sprintf( "%sGLU version: %s\n", infotext.ascii(), gluVersion );
    infotext.sprintf( "%sGLU extensions:\n", infotext.ascii() );

    infotext += QString( gluExtensions ).replace( ' ', '\n' ) + "\n\n";
}
Пример #7
0
static bool
test_glx_version(void)
{
    int version = epoxy_glx_version(dpy, 0);
    const char *version_string;
    int ret;
    int server_major, server_minor;
    int client_major, client_minor;
    int server, client, expected;

    if (version < 13) {
        fprintf(stderr,
                "Reported GLX version %d, should be at least 13 "
                "according to Linux GL ABI\n",
                version);
        return false;
    }

    version_string = glXQueryServerString(dpy, 0, GLX_VERSION);
    ret = sscanf(version_string, "%d.%d", &server_major, &server_minor);
    assert(ret == 2);
    server = server_major * 10 + server_minor;

    version_string = glXGetClientString(dpy, GLX_VERSION);
    ret = sscanf(version_string, "%d.%d", &client_major, &client_minor);
    assert(ret == 2);
    client = client_major * 10 + client_minor;

    if (client < server)
        expected = client;
    else
        expected = server;

    if (version != expected) {
        fprintf(stderr,
                "Reported GLX version %d, should be %d (%s)\n",
                version, expected, version_string);
        return false;
    }

    return true;
}
HeadlessDisplay::Impl::Impl() {
    if (!XInitThreads()) {
        throw std::runtime_error("Failed to XInitThreads.");
    }

    xDisplay = XOpenDisplay(nullptr);
    if (xDisplay == nullptr) {
        throw std::runtime_error("Failed to open X display.");
    }

    const auto *extensions = reinterpret_cast<const char *>(glXQueryServerString(xDisplay, DefaultScreen(xDisplay), GLX_EXTENSIONS));
    if (!extensions) {
        throw std::runtime_error("Cannot read GLX extensions.");
    }
    if (!strstr(extensions,"GLX_SGIX_fbconfig")) {
        throw std::runtime_error("Extension GLX_SGIX_fbconfig was not found.");
    }
    if (!strstr(extensions, "GLX_SGIX_pbuffer")) {
        throw std::runtime_error("Cannot find glXCreateContextAttribsARB.");
    }

    // We're creating a dummy pbuffer anyway that we're not using.
    static int pixelFormat[] = {
        GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT,
        None
    };

    int configs = 0;
    fbConfigs = glXChooseFBConfig(xDisplay, DefaultScreen(xDisplay), pixelFormat, &configs);
    if (fbConfigs == nullptr) {
        throw std::runtime_error("Failed to glXChooseFBConfig.");
    }
    if (configs <= 0) {
        throw std::runtime_error("No Framebuffer configurations.");
    }
}
Пример #9
0
int main( int argc, char **argv )
{
   Display *display;
   int err, event, server_major, server_minor, client_major, client_minor;

   if ( argc > 1 )
     display = XOpenDisplay( argv[1] );
   else
     display = XOpenDisplay( "" );

   if ( !display ) 
   {
     fprintf( stderr, "FATAL: Can't connect to X Server\n" );
     fprintf( stdout, "fatal\n" );
     exit(0);
   }

   if ( glXQueryExtension( display, &err, &event ) )
   {
     sscanf( glXQueryServerString( display, 0, GLX_VERSION ),
          "%d.%d", &server_major, &server_minor );

     sscanf( glXGetClientString( display, GLX_VERSION ), 
          "%d.%d", &client_major, &client_minor );

     if ( server_major != client_major || server_minor != client_minor )
     {
        fprintf( stdout, "glx_mismatch\n" );
     } else
        fprintf( stdout, "success\n" );
   } else
     fprintf( stdout, "no_glx_found\n" );

   XCloseDisplay( display );
   return 1;
}
Пример #10
0
static void
print_screen_info(Display *dpy, int scrnum, Bool allowDirect, GLboolean limits)
{
   Window win;
   int attribSingle[] = {
      GLX_RGBA,
      GLX_RED_SIZE, 1,
      GLX_GREEN_SIZE, 1,
      GLX_BLUE_SIZE, 1,
      None };
   int attribDouble[] = {
      GLX_RGBA,
      GLX_RED_SIZE, 1,
      GLX_GREEN_SIZE, 1,
      GLX_BLUE_SIZE, 1,
      GLX_DOUBLEBUFFER,
      None };

   XSetWindowAttributes attr;
   unsigned long mask;
   Window root;
   GLXContext ctx;
   XVisualInfo *visinfo;
   int width = 100, height = 100;

   root = RootWindow(dpy, scrnum);

   visinfo = glXChooseVisual(dpy, scrnum, attribSingle);
   if (!visinfo) {
      visinfo = glXChooseVisual(dpy, scrnum, attribDouble);
      if (!visinfo) {
         fprintf(stderr, "Error: couldn't find RGB GLX visual\n");
         return;
      }
   }

   attr.background_pixel = 0;
   attr.border_pixel = 0;
   attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone);
   attr.event_mask = StructureNotifyMask | ExposureMask;
   mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
   win = XCreateWindow(dpy, root, 0, 0, width, height,
		       0, visinfo->depth, InputOutput,
		       visinfo->visual, mask, &attr);

   ctx = glXCreateContext( dpy, visinfo, NULL, allowDirect );
   if (!ctx) {
      fprintf(stderr, "Error: glXCreateContext failed\n");
      XDestroyWindow(dpy, win);
      return;
   }

   if (glXMakeCurrent(dpy, win, ctx)) {
      const char *serverVendor = glXQueryServerString(dpy, scrnum, GLX_VENDOR);
      const char *serverVersion = glXQueryServerString(dpy, scrnum, GLX_VERSION);
      const char *serverExtensions = glXQueryServerString(dpy, scrnum, GLX_EXTENSIONS);
      const char *clientVendor = glXGetClientString(dpy, GLX_VENDOR);
      const char *clientVersion = glXGetClientString(dpy, GLX_VERSION);
      const char *clientExtensions = glXGetClientString(dpy, GLX_EXTENSIONS);
      const char *glxExtensions = glXQueryExtensionsString(dpy, scrnum);
      const char *glVendor = (const char *) glGetString(GL_VENDOR);
      const char *glRenderer = (const char *) glGetString(GL_RENDERER);
      const char *glVersion = (const char *) glGetString(GL_VERSION);
      const char *glExtensions = (const char *) glGetString(GL_EXTENSIONS);
      int glxVersionMajor;
      int glxVersionMinor;
      char *displayName = NULL;
      char *colon = NULL, *period = NULL;
#ifdef DO_GLU
      const char *gluVersion = (const char *) gluGetString(GLU_VERSION);
      const char *gluExtensions = (const char *) gluGetString(GLU_EXTENSIONS);
#endif
      
      if (! glXQueryVersion( dpy, & glxVersionMajor, & glxVersionMinor )) {
         fprintf(stderr, "Error: glXQueryVersion failed\n");
         exit(1);
      }

      /* Strip the screen number from the display name, if present. */
      if (!(displayName = (char *) malloc(strlen(DisplayString(dpy)) + 1))) {
         fprintf(stderr, "Error: malloc() failed\n");
         exit(1);
      }
      strcpy(displayName, DisplayString(dpy));
      colon = strrchr(displayName, ':');
      if (colon) {
         period = strchr(colon, '.');
         if (period)
            *period = '\0';
      }
      printf("display: %s  screen: %d\n", displayName, scrnum);
      free(displayName);
      printf("direct rendering: %s\n", glXIsDirect(dpy, ctx) ? "Yes" : "No");
      printf("server glx vendor string: %s\n", serverVendor);
      printf("server glx version string: %s\n", serverVersion);
      printf("server glx extensions:\n");
      print_extension_list(serverExtensions);
      printf("client glx vendor string: %s\n", clientVendor);
      printf("client glx version string: %s\n", clientVersion);
      printf("client glx extensions:\n");
      print_extension_list(clientExtensions);
      printf("GLX version: %u.%u\n", glxVersionMajor, glxVersionMinor);
      printf("GLX extensions:\n");
      print_extension_list(glxExtensions);
      printf("OpenGL vendor string: %s\n", glVendor);
      printf("OpenGL renderer string: %s\n", glRenderer);
      printf("OpenGL version string: %s\n", glVersion);
      printf("OpenGL extensions:\n");
      print_extension_list(glExtensions);
      if (limits)
         print_limits();
#ifdef DO_GLU
      printf("glu version: %s\n", gluVersion);
      printf("glu extensions:\n");
      print_extension_list(gluExtensions);
#endif
   }
   else {
      fprintf(stderr, "Error: glXMakeCurrent failed\n");
   }

   glXDestroyContext(dpy, ctx);
   XDestroyWindow(dpy, win);
}
Пример #11
0
static Colormap choose_cmap( Display *dpy, XVisualInfo *vi )
{
    if ( !cmap_dict ) {
	cmap_dict = new QIntDict<CMapEntry>;
	const char *v = glXQueryServerString( dpy, vi->screen, GLX_VERSION );
	if ( v )
	    mesa_gl = strstr(v,"Mesa") != 0;
	qAddPostRoutine( cleanup_cmaps );
    }

    CMapEntry *x = cmap_dict->find( (long) vi->visualid + ( vi->screen * 256 ) );
    if ( x )					// found colormap for visual
	return x->cmap;

    x = new CMapEntry();

    XStandardColormap *c;
    int n, i;

    // qDebug( "Choosing cmap for vID %0x", vi->visualid );

    if ( vi->visualid ==
	 XVisualIDFromVisual( (Visual*)QPaintDevice::x11AppVisual( vi->screen ) ) ) {
	// qDebug( "Using x11AppColormap" );
	return QPaintDevice::x11AppColormap( vi->screen );
    }

    if ( mesa_gl ) {				// we're using MesaGL
	Atom hp_cmaps = XInternAtom( dpy, "_HP_RGB_SMOOTH_MAP_LIST", TRUE );
	if ( hp_cmaps && vi->visual->c_class == TrueColor && vi->depth == 8 ) {
	    if ( XGetRGBColormaps(dpy,RootWindow(dpy,vi->screen),&c,&n,
				  hp_cmaps) ) {
		i = 0;
		while ( i < n && x->cmap == 0 ) {
		    if ( c[i].visualid == vi->visual->visualid ) {
			x->cmap = c[i].colormap;
			x->scmap = c[i];
			//qDebug( "Using HP_RGB scmap" );

		    }
		    i++;
		}
		XFree( (char *)c );
	    }
	}
    }
#if !defined(Q_OS_SOLARIS)
    if ( !x->cmap ) {
#ifdef QT_DLOPEN_OPENGL
	typedef Status (*_XmuLookupStandardColormap)( Display *dpy, int screen, VisualID visualid, unsigned int depth,
						      Atom property, Bool replace, Bool retain );
	_XmuLookupStandardColormap qt_XmuLookupStandardColormap;
	qt_XmuLookupStandardColormap = (_XmuLookupStandardColormap) QLibrary::resolve("Xmu", "XmuLookupStandardColormap");
	if (!qt_XmuLookupStandardColormap)
	    qFatal("Unable to resolve Xmu symbols - please check your Xmu library installation.");
#define XmuLookupStandardColormap qt_XmuLookupStandardColormap

#endif

	if ( XmuLookupStandardColormap(dpy,vi->screen,vi->visualid,vi->depth,
					  XA_RGB_DEFAULT_MAP,FALSE,TRUE) ) {
	    if ( XGetRGBColormaps(dpy,RootWindow(dpy,vi->screen),&c,&n,
				  XA_RGB_DEFAULT_MAP) ) {
		i = 0;
		while ( i < n && x->cmap == 0 ) {
		    if ( c[i].visualid == vi->visualid ) {
			x->cmap = c[i].colormap;
			x->scmap = c[i];
			//qDebug( "Using RGB_DEFAULT scmap" );
		    }
		    i++;
		}
		XFree( (char *)c );
	    }
	}
    }
#endif
    if ( !x->cmap ) {				// no shared cmap found
	x->cmap = XCreateColormap( dpy, RootWindow(dpy,vi->screen), vi->visual,
				   AllocNone );
	x->alloc = TRUE;
	// qDebug( "Allocating cmap" );
    }

    // associate cmap with visualid
    cmap_dict->insert( (long) vi->visualid + ( vi->screen * 256 ), x );
    return x->cmap;
}
Пример #12
0
static Q3ListViewItem *get_gl_info(Display *dpy, int scrnum, Bool allowDirect,Q3ListViewItem *l1, Q3ListViewItem *after)
{
   Window win;
   int attribSingle[] = {
      GLX_RGBA,
      GLX_RED_SIZE, 1,
      GLX_GREEN_SIZE, 1,
      GLX_BLUE_SIZE, 1,
      None };
   int attribDouble[] = {
      GLX_RGBA,
      GLX_RED_SIZE, 1,
      GLX_GREEN_SIZE, 1,
      GLX_BLUE_SIZE, 1,
      GLX_DOUBLEBUFFER,
      None };

   XSetWindowAttributes attr;
   unsigned long mask;
   Window root;
   GLXContext ctx;
   XVisualInfo *visinfo;
   int width = 100, height = 100;
   Q3ListViewItem *result = after;

   root = RootWindow(dpy, scrnum);

   visinfo = glXChooseVisual(dpy, scrnum, attribSingle);
   if (!visinfo) {
      visinfo = glXChooseVisual(dpy, scrnum, attribDouble);
      if (!visinfo) {
		   kDebug() << "Error: couldn't find RGB GLX visual\n";
         return result;
      }
   }

   attr.background_pixel = 0;
   attr.border_pixel = 0;
   attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone);
   attr.event_mask = StructureNotifyMask | ExposureMask;
   mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
   win = XCreateWindow(dpy, root, 0, 0, width, height,
   			0, visinfo->depth, InputOutput,
		       visinfo->visual, mask, &attr);

   ctx = glXCreateContext( dpy, visinfo, NULL, allowDirect );
   if (!ctx) {
		kDebug() << "Error: glXCreateContext failed\n";
      XDestroyWindow(dpy, win);
      return result;
   }

   if (glXMakeCurrent(dpy, win, ctx)) {
      gli.serverVendor = glXQueryServerString(dpy, scrnum, GLX_VENDOR);
      gli.serverVersion = glXQueryServerString(dpy, scrnum, GLX_VERSION);
      gli.serverExtensions = glXQueryServerString(dpy, scrnum, GLX_EXTENSIONS);
      gli.clientVendor = glXGetClientString(dpy, GLX_VENDOR);
      gli.clientVersion = glXGetClientString(dpy, GLX_VERSION);
      gli.clientExtensions = glXGetClientString(dpy, GLX_EXTENSIONS);
      gli.glxExtensions = glXQueryExtensionsString(dpy, scrnum);
      gli.glVendor = (const char *) glGetString(GL_VENDOR);
      gli.glRenderer = (const char *) glGetString(GL_RENDERER);
      gli.glVersion = (const char *) glGetString(GL_VERSION);
      gli.glExtensions = (const char *) glGetString(GL_EXTENSIONS);
      gli.displayName = NULL;
#ifdef KCMGL_DO_GLU
      gli.gluVersion = (const char *) gluGetString(GLU_VERSION);
      gli.gluExtensions = (const char *) gluGetString(GLU_EXTENSIONS);
#endif
      IsDirect = glXIsDirect(dpy, ctx);

      result = print_screen_info(l1, after);
   }
   else {
      kDebug() << "Error: glXMakeCurrent failed\n";
      glXDestroyContext(dpy, ctx);
   }

   glXDestroyContext(dpy, ctx);
   XDestroyWindow(dpy, win);
   return result;

}
Пример #13
0
Colormap qt_gl_choose_cmap(Display *dpy, XVisualInfo *vi)
{
    if (first_time) {
        const char *v = glXQueryServerString(dpy, vi->screen, GLX_VERSION);
        if (v)
            mesa_gl = (strstr(v, "Mesa") != 0);
        first_time = false;
    }

    CMapEntryHash *hash = cmap_handler()->cmap_hash;
    CMapEntryHash::ConstIterator it = hash->constFind((long) vi->visualid + (vi->screen * 256));
    if (it != hash->constEnd())
        return it.value()->cmap; // found colormap for visual

    if (vi->visualid ==
        XVisualIDFromVisual((Visual *) QX11Info::appVisual(vi->screen))) {
        // qDebug("Using x11AppColormap");
        return QX11Info::appColormap(vi->screen);
    }

    QCMapEntry *x = new QCMapEntry();

    XStandardColormap *c;
    int n, i;

    // qDebug("Choosing cmap for vID %0x", vi->visualid);

    if (mesa_gl) {                                // we're using MesaGL
        Atom hp_cmaps = XInternAtom(dpy, "_HP_RGB_SMOOTH_MAP_LIST", true);
        if (hp_cmaps && vi->visual->c_class == TrueColor && vi->depth == 8) {
            if (XGetRGBColormaps(dpy,RootWindow(dpy,vi->screen),&c,&n,
                                 hp_cmaps)) {
                i = 0;
                while (i < n && x->cmap == 0) {
                    if (c[i].visualid == vi->visual->visualid) {
                        x->cmap = c[i].colormap;
                        x->scmap = c[i];
                        //qDebug("Using HP_RGB scmap");

                    }
                    i++;
                }
                XFree((char *)c);
            }
        }
    }
    if (!x->cmap) {
        if (XGetRGBColormaps(dpy,RootWindow(dpy,vi->screen),&c,&n,
                             XA_RGB_DEFAULT_MAP)) {
            for (int i = 0; i < n && x->cmap == 0; ++i) {
                if (!c[i].red_max ||
                    !c[i].green_max ||
                    !c[i].blue_max ||
                    !c[i].red_mult ||
                    !c[i].green_mult ||
                    !c[i].blue_mult)
                    continue; // invalid stdcmap
                if (c[i].visualid == vi->visualid) {
                    x->cmap = c[i].colormap;
                    x->scmap = c[i];
                    //qDebug("Using RGB_DEFAULT scmap");
                }
            }
            XFree((char *)c);
        }
    }
    if (!x->cmap) {                                // no shared cmap found
        x->cmap = XCreateColormap(dpy, RootWindow(dpy,vi->screen), vi->visual,
                                  AllocNone);
        x->alloc = true;
        // qDebug("Allocating cmap");
    }

    // colormap hash should be cleanup only when the QApplication dtor is called
    if (hash->isEmpty())
        qAddPostRoutine(cleanup_cmaps);

    // associate cmap with visualid
    hash->insert((long) vi->visualid + (vi->screen * 256), x);
    return x->cmap;
}
Пример #14
0
static void
print_screen_info(Display *dpy, int scrnum, Bool allowDirect, GLboolean limits)
{
   Window win;
   int attribSingle[] = {
      GLX_RGBA,
      GLX_RED_SIZE, 1,
      GLX_GREEN_SIZE, 1,
      GLX_BLUE_SIZE, 1,
      None };
   int attribDouble[] = {
      GLX_RGBA,
      GLX_RED_SIZE, 1,
      GLX_GREEN_SIZE, 1,
      GLX_BLUE_SIZE, 1,
      GLX_DOUBLEBUFFER,
      None };

   XSetWindowAttributes attr;
   unsigned long mask;
   Window root;
   GLXContext ctx = NULL;
   XVisualInfo *visinfo;
   int width = 100, height = 100;

   root = RootWindow(dpy, scrnum);

   /*
    * Find a basic GLX visual.  We'll then create a rendering context and
    * query various info strings.
    */
   visinfo = glXChooseVisual(dpy, scrnum, attribSingle);
   if (!visinfo)
      visinfo = glXChooseVisual(dpy, scrnum, attribDouble);

   if (visinfo)
      ctx = glXCreateContext( dpy, visinfo, NULL, allowDirect );

#ifdef GLX_VERSION_1_3
   /* Try glXChooseFBConfig() if glXChooseVisual didn't work.
    * XXX when would that happen?
    */
   if (!visinfo) {
      int fbAttribSingle[] = {
	 GLX_RENDER_TYPE,   GLX_RGBA_BIT,
	 GLX_RED_SIZE,      1,
	 GLX_GREEN_SIZE,    1,
	 GLX_BLUE_SIZE,     1,
	 GLX_DOUBLEBUFFER,  GL_FALSE,
	 None };
      int fbAttribDouble[] = {
	 GLX_RENDER_TYPE,   GLX_RGBA_BIT,
	 GLX_RED_SIZE,      1,
	 GLX_GREEN_SIZE,    1,
	 GLX_BLUE_SIZE,     1,
	 GLX_DOUBLEBUFFER,  GL_TRUE,
	 None };
      GLXFBConfig *configs = NULL;
      int nConfigs;

      configs = glXChooseFBConfig(dpy, scrnum, fbAttribSingle, &nConfigs);
      if (!configs)
	 configs = glXChooseFBConfig(dpy, scrnum, fbAttribDouble, &nConfigs);

      if (configs) {
	 visinfo = glXGetVisualFromFBConfig(dpy, configs[0]);
	 ctx = glXCreateNewContext(dpy, configs[0], GLX_RGBA_TYPE, NULL, allowDirect);
	 XFree(configs);
      }
   }
#endif

   if (!visinfo) {
      fprintf(stderr, "Error: couldn't find RGB GLX visual or fbconfig\n");
      return;
   }

   if (!ctx) {
      fprintf(stderr, "Error: glXCreateContext failed\n");
      XFree(visinfo);
      return;
   }

   attr.background_pixel = 0;
   attr.border_pixel = 0;
   attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone);
   attr.event_mask = StructureNotifyMask | ExposureMask;
   mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
   win = XCreateWindow(dpy, root, 0, 0, width, height,
		       0, visinfo->depth, InputOutput,
		       visinfo->visual, mask, &attr);

   if (glXMakeCurrent(dpy, win, ctx)) {
      const char *serverVendor = glXQueryServerString(dpy, scrnum, GLX_VENDOR);
      const char *serverVersion = glXQueryServerString(dpy, scrnum, GLX_VERSION);
      const char *serverExtensions = glXQueryServerString(dpy, scrnum, GLX_EXTENSIONS);
      const char *clientVendor = glXGetClientString(dpy, GLX_VENDOR);
      const char *clientVersion = glXGetClientString(dpy, GLX_VERSION);
      const char *clientExtensions = glXGetClientString(dpy, GLX_EXTENSIONS);
      const char *glxExtensions = glXQueryExtensionsString(dpy, scrnum);
      const char *glVendor = (const char *) glGetString(GL_VENDOR);
      const char *glRenderer = (const char *) glGetString(GL_RENDERER);
      const char *glVersion = (const char *) glGetString(GL_VERSION);
      const char *glExtensions = (const char *) glGetString(GL_EXTENSIONS);
      int glxVersionMajor;
      int glxVersionMinor;
      char *displayName = NULL;
      char *colon = NULL, *period = NULL;
      
      if (! glXQueryVersion( dpy, & glxVersionMajor, & glxVersionMinor )) {
         fprintf(stderr, "Error: glXQueryVersion failed\n");
         exit(1);
      }

      /* Strip the screen number from the display name, if present. */
      if (!(displayName = (char *) malloc(strlen(DisplayString(dpy)) + 1))) {
         fprintf(stderr, "Error: malloc() failed\n");
         exit(1);
      }
      strcpy(displayName, DisplayString(dpy));
      colon = strrchr(displayName, ':');
      if (colon) {
         period = strchr(colon, '.');
         if (period)
            *period = '\0';
      }
      printf("display: %s  screen: %d\n", displayName, scrnum);
      free(displayName);
      printf("direct rendering: ");
      if (glXIsDirect(dpy, ctx)) {
         printf("Yes\n");
      } else {
         if (!allowDirect) {
            printf("No (-i specified)\n");
         } else if (getenv("LIBGL_ALWAYS_INDIRECT")) {
            printf("No (LIBGL_ALWAYS_INDIRECT set)\n");
         } else {
            printf("No (If you want to find out why, try setting "
                   "LIBGL_DEBUG=verbose)\n");
         }
      }
      printf("server glx vendor string: %s\n", serverVendor);
      printf("server glx version string: %s\n", serverVersion);
      printf("server glx extensions:\n");
      print_extension_list(serverExtensions);
      printf("client glx vendor string: %s\n", clientVendor);
      printf("client glx version string: %s\n", clientVersion);
      printf("client glx extensions:\n");
      print_extension_list(clientExtensions);
      printf("GLX version: %u.%u\n", glxVersionMajor, glxVersionMinor);
      printf("GLX extensions:\n");
      print_extension_list(glxExtensions);
      printf("OpenGL vendor string: %s\n", glVendor);
      printf("OpenGL renderer string: %s\n", glRenderer);
      printf("OpenGL version string: %s\n", glVersion);
#ifdef GL_VERSION_2_0
      if (glVersion[0] >= '2' && glVersion[1] == '.') {
         char *v = (char *) glGetString(GL_SHADING_LANGUAGE_VERSION);
         printf("OpenGL shading language version string: %s\n", v);
      }
#endif

      printf("OpenGL extensions:\n");
      print_extension_list(glExtensions);
      if (limits)
         print_limits(glExtensions);
   }
   else {
      fprintf(stderr, "Error: glXMakeCurrent failed\n");
   }

   glXDestroyContext(dpy, ctx);
   XFree(visinfo);
   XDestroyWindow(dpy, win);
}
Пример #15
0
std::string
RenderingDevices::xml()
{
    // We cache the results
    if(m_hasRenderingInformation) {
      std::cout << m_xml<<std::endl;
        return m_xml;
    }
    
    std::stringstream xml;
    xml << "  <renderingDevices>\n";
   
    DIR* dir = opendir( "/tmp/.X11-unix" );
    if( dir == NULL ) {
        if( m_logger != NULL ) {
            m_logger( m_logger_data, 0, package.c_str(),
                      "opendir failed: %s.", strerror( errno ) );
        }
        xml << "    <error>INTERNAL_ERROR</error>\n";
    }
    else {
        struct dirent* entry = NULL;
        while( (entry = readdir( dir )) != NULL ) {
            if( entry->d_name[0] != 'X' ) {
                continue;
            }
            std::string display_id = ":" + std::string( entry->d_name ).substr(1);
    
    
            
            Display* display = XOpenDisplay( display_id.c_str() );
            if( display == NULL ) {
                xml << "    <renderingDevice id=\"" << display_id << "\">\n";
                xml << "      <error>FAILED_TO_OPEN_DISPLAY</error>\n";
                xml << "    </renderingDevice>\n";
                continue;
            }

#ifdef TINIA_AMAZON
            int screen_count = 1;
#else
	    int screen_count = ScreenCount ( display );
#endif
            XCloseDisplay( display );
            
            if( screen_count < 1 ) {
                xml << "    <renderingDevice id=\"" << display_id << "\">\n";
                xml << "      <error>NO_SCREENS</error>\n";
                xml << "    </renderingDevice>\n";
                continue;
            }

            for(int screen=0; screen<screen_count; screen++) {
                std::stringstream screen_id_ss;
                screen_id_ss << display_id << '.' << screen;
                std::string screen_id = screen_id_ss.str();
                
                xml << "    <renderingDevice id=\"" << screen_id << "\">\n";
                OffscreenGL gl( m_logger, m_logger_data );
                if( !gl.setupContext( screen_id ) || !gl.bindContext() ) {
                    switch ( gl.state() ) {
                    case OffscreenGL::STATE_INSUFFICIENT_GLX:
                        xml << "    <error>INSUFFICIENT_GLX</error>\n";
                        break;
                    case OffscreenGL::STATE_X_ERROR:
                        xml << "    <error>X_ERROR</error>\n";
                        break;
                    default:
                        xml << "    <error>INTERNAL_ERROR</error>\n";
                        break;
                    }
                }
                else {
                    
                    int glx_major = 0;
                    int glx_minor = 0;
                    glXQueryVersion( gl.display(), &glx_major, &glx_minor );
                    xml << "      <glx major=\"" << glx_major
                        << "\" minor=\"" << glx_minor
                        << "\" direct=\"" << (glXIsDirect(gl.display(), gl.context())==True?'1':'0')
                        << "\">\n";
                    xml << "        <client>\n";
                    xml << "          <vendor>" << glXGetClientString( gl.display(), GLX_VENDOR ) << "</vendor>\n";
                    xml << "          <version>" << glXGetClientString( gl.display(), GLX_VERSION ) << "</version>\n";
                    xml << "        </client>\n";
                    xml << "        <server>\n";
                    xml << "          <vendor>" << glXQueryServerString( gl.display(), screen, GLX_VENDOR ) << "</vendor>\n";
                    xml << "          <version>" << glXQueryServerString( gl.display(), screen, GLX_VERSION ) << "</version>\n";
                    xml << "        </server>\n";
                    std::list<std::string> glx_extensions = parseExtensions( glXQueryExtensionsString( gl.display(), screen ) );
                    for( std::list<std::string>::iterator it=glx_extensions.begin(); it!=glx_extensions.end(); ++it ) {
                        //xml << "        <extension>" << *it << "</extension>\n";
                    }
                    xml << "      </glx>\n";
                    
                    GLint gl_major = 0;
                    glGetIntegerv( GL_MAJOR_VERSION, &gl_major );
                    GLint gl_minor = 0;
                    glGetIntegerv( GL_MINOR_VERSION, &gl_minor );
                    xml << "      <opengl major=\"" << gl_major
                        << "\" minor=\"" << gl_minor
                        << "\">\n";
                    xml << "        <vendor>" << (const char*)glGetString( GL_VENDOR ) << "</vendor>\n";
                    xml << "        <version>" << (const char*)glGetString( GL_VERSION ) << "</version>\n";
                    xml << "        <renderer>" << (const char*)glGetString( GL_RENDERER) << "</renderer>\n";
                    
                    if( gl_major >= 2 ) {
                        xml << "        <glsl><version>"
                            << (const char*)glGetString( GL_SHADING_LANGUAGE_VERSION )
                            << "</version></glsl>\n";
                        
                    }
                    std::list<std::string> gl_extensions = parseExtensions( (const char*)glGetString( GL_EXTENSIONS ) );
                    for( std::list<std::string>::iterator it=gl_extensions.begin(); it!=gl_extensions.end(); ++it ) {
                        //xml << "        <extension>" << *it << "</extension>\n";
                    }
                    xml << "      </opengl>\n";
                }
                xml << "    </renderingDevice>\n";
            }
        }
        closedir( dir );
    }
    xml << "  </renderingDevices>\n";
    m_hasRenderingInformation = true;
    m_xml = xml.str();
    return xml.str();
}
Пример #16
0
static int
setup(int width, int height)
{
#if USE_OSMESA
    const size_t size = width * height * 4;
    pbuffer = malloc(size);
    memset(pbuffer, 0x21, size);
    context = OSMesaCreateContextExt(GL_RGBA, 24, 0, 0, 0);
    OSMesaMakeCurrent(context, (void *)pbuffer, GL_UNSIGNED_BYTE, width, height);
    return 0;
#elif USE_CGL
    /* OpenGL PBuffer initialization: OSX specific */
    CGLPixelFormatAttribute pfattr[] = {
        kCGLPFAPBuffer,
        (CGLPixelFormatAttribute)0
    };
    CGLPixelFormatObj pixformat;
    GLint npixels;
    int e;

    e = CGLChoosePixelFormat(pfattr, &pixformat, &npixels);
    if (e != kCGLNoError) {
       fprintf(stderr, "CGLChoosePixelFormat failed, err %d\n", e);
       return e;
    }
    e = CGLCreateContext(pixformat, 0, &context);
    if (e != kCGLNoError) {
       fprintf(stderr, "CGLChoosePixelFormat failed, err %d\n", e);
       return e;
    }
    e = CGLDestroyPixelFormat(pixformat);
    if (e != kCGLNoError) {
       fprintf(stderr, "CGLDestroyPixelFormat failed, err %d\n", e);
       return e;
    }
    e = CGLSetCurrentContext(context);
    if (e != kCGLNoError) {
       fprintf(stderr, "CGLSetCurrentContext failed, err %d\n", e);
       return e;
    }
    e = CGLCreatePBuffer(width, height, GL_TEXTURE_2D, GL_RGB, 0, &pbuffer);
    if (e != kCGLNoError) {
       fprintf(stderr, "CGLCreatePBuffer failed, err %d\n", e);
       return e;
    }
    e = CGLSetPBuffer(context, pbuffer, 0, 0, 0);
    if (e != kCGLNoError) {
       fprintf(stderr, "CGLSetPBuffer failed, err %d\n", e);
       return e;
    }
    return (int)kCGLNoError;
#elif USE_GLX
    int result = (-1);
    char *glxversion;
    int screen;
    GLXFBConfig *fbConfigs = NULL;
    GLXFBConfig chosenFBConfig;
    GLXFBConfig fbconfig = 0;
    GLXPbuffer pbuffer = None;
    int nConfigs;
    int fbconfigid;
    int fbAttribs[] = {
       GLX_RENDER_TYPE, GLX_RGBA_BIT,
       GLX_DEPTH_SIZE, 1,
       GLX_DRAWABLE_TYPE, GLX_PIXMAP_BIT | GLX_PBUFFER_BIT,
       None
    };
    int pbAttribs[] = {
       GLX_PBUFFER_WIDTH, 0,
       GLX_PBUFFER_HEIGHT, 0,
       GLX_LARGEST_PBUFFER, False,
       GLX_PRESERVED_CONTENTS, False,
       None
    };

    /* Open the X display */
    display = XOpenDisplay(NULL);
    if (!display) {
       fprintf(stderr, "Error: couldn't open default X display.\n");
       goto end;
    }

    /* Get default screen */
    screen = DefaultScreen(display);
    glxversion = (char *) glXGetClientString(display, GLX_VERSION);
    if (!(strstr(glxversion, "1.3") || strstr(glxversion, "1.4"))) {
       goto end;
    }
    glxversion = (char *) glXQueryServerString(display, screen, GLX_VERSION);
    if (!(strstr(glxversion, "1.3") || strstr(glxversion, "1.4"))) {
       goto end;
    }

    /* Create Pbuffer */
    pbAttribs[1] = width;
    pbAttribs[3] = height;

    fbConfigs = glXChooseFBConfig(display, screen, fbAttribs, &nConfigs);
    if (0 == nConfigs || !fbConfigs) {
       fprintf(stderr, "Error: glxChooseFBConfig failed\n");
       XFree(fbConfigs);
       goto end;
    }
    chosenFBConfig = fbConfigs[0];
    glXGetFBConfigAttrib(display, chosenFBConfig, GLX_FBCONFIG_ID, &fbconfigid);

    /* Create the pbuffer using first fbConfig in the list that works. */
    pbuffer = glXCreatePbuffer(display, chosenFBConfig, pbAttribs);
    if (pbuffer) {
       fbconfig = chosenFBConfig;
    }
    XFree(fbConfigs);
    if (pbuffer == None) {
       fprintf(stderr, "Error: couldn't create pbuffer\n");
       goto end;
    }
    /* Create GLX context */
    context = glXCreateNewContext(display, fbconfig, GLX_RGBA_TYPE, NULL, True);
    if (!context) {
       fprintf(stderr, "Error: Couldn't create GLXContext\n");
       goto end;
    }
    /* Bind context to pbuffer */
    if (!glXMakeCurrent(display, pbuffer, context)) {
       fprintf(stderr, "Error: glXMakeCurrent failed\n");
       goto end;
    }
    result = 0;
end:
    if (fbConfigs)
       XFree(fbConfigs);
    if (display)
       XCloseDisplay(display);
    return result;
#else
    /* TODO: pbuffer initialization */
    return 0;
#endif
}
Пример #17
0
static int init_platform_gl_extensions(lite3d_video_settings *settings)
{
    SDL_SysWMinfo wminfo;
    SDL_VERSION(&wminfo.version);
    if (!SDL_GetWindowWMInfo(gRenderWindow, &wminfo))
    {
        SDL_LogWarn(
            SDL_LOG_CATEGORY_APPLICATION,
            "SDL_GetWindowWMInfo: %s",
            SDL_GetError());

        return LITE3D_FALSE;
    }

#ifndef GLES
# ifdef PLATFORM_Windows

    if (!WGLEW_ARB_extensions_string)
    {
        SDL_LogWarn(
            SDL_LOG_CATEGORY_APPLICATION,
            "SDL_GetWindowWMInfo: %s",
            SDL_GetError());

        return LITE3D_FALSE;
    }

    SDL_LogDebug(
        SDL_LOG_CATEGORY_APPLICATION,
        "%s: WGL Extensions %s",
        LITE3D_CURRENT_FUNCTION,
        (char *) wglGetExtensionsStringARB(GetDC(wminfo.info.win.window)));

# elif defined PLATFORM_Linux

    if (!GLXEW_VERSION_1_3)
    {
        SDL_LogCritical(
            SDL_LOG_CATEGORY_APPLICATION,
            "%s: GLX v1.3 not supported..",
            LITE3D_CURRENT_FUNCTION);

        return LITE3D_FALSE;
    }

    SDL_LogDebug(
        SDL_LOG_CATEGORY_APPLICATION,
        "%s: GLX Client %s",
        LITE3D_CURRENT_FUNCTION,
        (char *) glXGetClientString(wminfo.info.x11.display, 1));

    SDL_LogDebug(
        SDL_LOG_CATEGORY_APPLICATION,
        "%s: GLX Server %s",
        LITE3D_CURRENT_FUNCTION,
        (char *) glXQueryServerString(wminfo.info.x11.display, 0, 1));

    SDL_LogDebug(
        SDL_LOG_CATEGORY_APPLICATION,
        "%s: GLX Extensions %s",
        LITE3D_CURRENT_FUNCTION,
        (char *) glXQueryExtensionsString(wminfo.info.x11.display, 0));

# endif
#endif

    return LITE3D_TRUE;
}
Пример #18
0
void print_screen_info(Display *dpy, int scrnum)
{
   Window win;
   int attribSingle[] = {
      GLX_RGBA,
      GLX_RED_SIZE, 1,
      GLX_GREEN_SIZE, 1,
      GLX_BLUE_SIZE, 1,
      None };
   int attribDouble[] = {
      GLX_RGBA,
      GLX_RED_SIZE, 1,
      GLX_GREEN_SIZE, 1,
      GLX_BLUE_SIZE, 1,
      GLX_DOUBLEBUFFER,
      None };

   XSetWindowAttributes attr;
   unsigned long mask;
   Window root;
   GLXContext ctx;
   XVisualInfo *visinfo;
   int width = 100, height = 100;

   root = RootWindow(dpy, scrnum);

   visinfo = glXChooseVisual(dpy, scrnum, attribSingle);
   if (!visinfo) {
      visinfo = glXChooseVisual(dpy, scrnum, attribDouble);
      if (!visinfo) {
         fprintf(stderr, "Error: couldn't find RGB GLX visual\n");
         return;
      }
   }

   attr.background_pixel = 0;
   attr.border_pixel = 0;
   attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone);
   attr.event_mask = StructureNotifyMask | ExposureMask;
   mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
   win = XCreateWindow(dpy, root, 0, 0, width, height,
		       0, visinfo->depth, InputOutput,
		       visinfo->visual, mask, &attr);

   ctx = glXCreateContext( dpy, visinfo, NULL, True );
   if (!ctx) {
      fprintf(stderr, "Error: glXCreateContext failed\n");
      XDestroyWindow(dpy, win);
      return;
   }

   if (glXMakeCurrent(dpy, win, ctx)) {
      const char *serverVendor = glXQueryServerString(dpy, scrnum, GLX_VENDOR);
      const char *serverVersion = glXQueryServerString(dpy, scrnum, GLX_VERSION);
      const char *serverExtensions = glXQueryServerString(dpy, scrnum, GLX_EXTENSIONS);
      const char *clientVendor = glXGetClientString(dpy, GLX_VENDOR);
      const char *clientVersion = glXGetClientString(dpy, GLX_VERSION);
      const char *clientExtensions = glXGetClientString(dpy, GLX_EXTENSIONS);
      const char *glxExtensions = glXQueryExtensionsString(dpy, scrnum);
      const char *glVendor = (const char *) glGetString(GL_VENDOR);
      const char *glRenderer = (const char *) glGetString(GL_RENDERER);
      const char *glVersion = (const char *) glGetString(GL_VERSION);
      const char *glExtensions = (const char *) glGetString(GL_EXTENSIONS);
      printf("display: %s  screen:%d\n", DisplayString(dpy), scrnum);
      printf("direct rendering: %s\n", glXIsDirect(dpy, ctx) ? "Yes" : "No");
      printf("server glx vendor string: %s\n", serverVendor);
      printf("server glx version string: %s\n", serverVersion);
      printf("server glx extensions:\n");
      print_extension_list(serverExtensions);
      printf("client glx vendor string: %s\n", clientVendor);
      printf("client glx version string: %s\n", clientVersion);
      printf("client glx extensions:\n");
      print_extension_list(clientExtensions);
      printf("GLX extensions:\n");
      print_extension_list(glxExtensions);
      printf("OpenGL vendor string: %s\n", glVendor);
      printf("OpenGL renderer string: %s\n", glRenderer);
      printf("OpenGL version string: %s\n", glVersion);
      printf("OpenGL extensions:\n");
      print_extension_list(glExtensions);
   }
   else {
      fprintf(stderr, "Error: glXMakeCurrent failed\n");
   }

   glXDestroyContext(dpy, ctx);
   XDestroyWindow(dpy, win);
}
Пример #19
0
void GlTraceFilterModel::checkExtensions()
{
	const GLubyte *extensionString, *versionString;
	int supportedMajor, supportedMinor;

	QGLWidget w;

	w.makeCurrent();
	extensionString = glGetString(GL_EXTENSIONS);
	versionString = glGetString(GL_VERSION);
	supportedMajor = versionString[0] - '0';
	supportedMinor = versionString[2] - '0';

	QByteArray extensions = QByteArray(
			reinterpret_cast<const char*>(extensionString));

#ifdef GLSLDB_WIN
	PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = 0;
	wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB");
	if(wglGetExtensionsStringARB) {
		extensions.append(' ');
		extensions.append(QByteArray(reinterpret_cast<const char*>(wglGetExtensionsStringARB(wglGetCurrentDC()))));
	}
#elif defined(GLSLDB_LINUX)
	int supportedXMajor, supportedXMinor;
	const char *versionXString;

	versionXString = glXQueryServerString(XOpenDisplay(NULL), 0, GLX_VERSION);

	supportedXMajor = versionXString[0] - '0';
	supportedXMinor = versionXString[2] - '0';

	extensions.append(' ');
	extensions.append(
			QByteArray(
					reinterpret_cast<const char*>(glXQueryServerString(
							XOpenDisplay(NULL), 0, GLX_EXTENSIONS))));

	extensions.append(' ');
	extensions.append(
			QByteArray(
					reinterpret_cast<const char*>(glXGetClientString(
							XOpenDisplay(NULL), GLX_EXTENSIONS))));

	extensions.append(' ');
	extensions.append(
			QByteArray(
					reinterpret_cast<const char*>(glXQueryExtensionsString(
							XOpenDisplay(NULL), 0))));
#elif defined(GLSLDB_OSX)

#warning "FIXME: any OSX specific extensions wee need to add here?"

#endif

	QList<QByteArray> extList = extensions.split(' ');
	for (int i = 0; i < this->rootItem->childCount(); i++) {
		GlTraceFilterItem *item = this->rootItem->child(i);
		if (strstr(item->function->extname, "GL_VERSION_")
				== item->function->extname) {
			int major, minor;
			major = item->function->extname[11] - '0';
			minor = item->function->extname[13] - '0';
			if (major < supportedMajor
					|| (major == supportedMajor && minor <= supportedMinor)) {
				item->isSupported = true;
			} else {
				item->isSupported = false;
			}
		}
#if defined(_WIN32)
		else if (strstr(item->function->extname, "WGL_VERSION_") == item->function->extname) {
			item->isSupported = true;
		}
#elif defined(GLSLDB_LINUX)
		else if (strstr(item->function->extname, "GLX_VERSION_")
				== item->function->extname) {
			int major, minor;
			major = item->function->extname[12] - '0';
			minor = item->function->extname[14] - '0';
			if (major < supportedXMajor
					|| (major == supportedXMajor && minor <= supportedXMinor)) {
				item->isSupported = true;
			} else {
				item->isSupported = false;
			}
		}
#elif defined(GLSLDB_OSX)
#warning "FIXME: any OSX specific extensions wee need to add here?"
#endif
		else {
			item->isSupported = extList.contains(item->function->extname);
		}
	}
}
Пример #20
0
int main(int argc, char *argv[])
{
	XSetWindowAttributes attr;
	Colormap cmap;
	Pixmap bitmap;
	Cursor cursor;
	XColor bg = { 0 };
	XColor fg = { 0 };
	char data[8] = { 0x01 };
	char *display;
	const char *ext;
	int mask, major, minor, verbose = 0;
	int opt;
	
	while ((opt = getopt(argc, argv, "v")) != -1) {
		switch(opt) {
		case 'v':
			verbose = 1;
			break;
		default:
			fprintf(stderr, "%d (%c) is unknown to me\n", opt, opt);
			break;
		}
	}
	
	if ((argc - optind) != 1) {
		fprintf(stderr, "usage: %s <mac wolf3d resource fork>\n", argv[0]);
		exit(EXIT_FAILURE);
	}
	
	if (InitResources(argv[optind])) {
		fprintf(stderr, "could not load %s\n", argv[optind]);
		exit(EXIT_FAILURE);
	}
	
	display = getenv("DISPLAY");
	dpy = XOpenDisplay(getenv(display));
	if (dpy == NULL) {
		fprintf(stderr, "Unable to open display %s\n", XDisplayName(display));
		exit(EXIT_FAILURE);
	}
	
	screen = DefaultScreen(dpy);
	
	root = RootWindow(dpy, screen);
	
	if (glXQueryExtension(dpy, NULL, NULL) == False) {
		fprintf(stderr, "Display %s does not support the GLX Extension\n", XDisplayName(display));
		exit(EXIT_FAILURE);
	}
	
	if (glXQueryVersion(dpy, &major, &minor) == False) {
		fprintf(stderr, "glXQueryVersion returned False?\n");
		exit(EXIT_FAILURE);
	} else if (verbose) {
		printf("GLX Version %d.%d\n", major, minor);
		printf("GLX Client:\n");
		printf("GLX_VENDOR: %s\n", glXGetClientString(dpy, GLX_VENDOR));
		printf("GLX_VERSION: %s\n", glXGetClientString(dpy, GLX_VERSION));
		printf("GLX_EXTENSIONS: %s\n", glXGetClientString(dpy, GLX_EXTENSIONS));
		printf("GLX Server:\n");
		printf("GLX_VENDOR: %s\n", glXQueryServerString(dpy, screen, GLX_VENDOR));
		printf("GLX_VERSION: %s\n", glXQueryServerString(dpy, screen, GLX_VERSION));
		printf("GLX_EXTENSIONS: %s\n", glXQueryServerString(dpy, screen, GLX_EXTENSIONS));
		printf("Both:\n");
		printf("GLX_EXTENSIONS: %s\n", glXQueryExtensionsString(dpy, screen));
	}
	
	vi = glXChooseVisual(dpy, screen, attrib);
	if (vi == NULL) {
		fprintf(stderr, "No usable GL visual found on %s:%d\n", XDisplayName(display), screen);
		exit(EXIT_FAILURE);
	}
		
	ctx = glXCreateContext(dpy, vi, NULL, True);
	if (ctx == NULL) {
 		fprintf(stderr, "GLX context creation failed\n");
		exit(EXIT_FAILURE);
	}
	
	cmap = XCreateColormap(dpy, root, vi->visual, AllocNone);
	
	attr.colormap = cmap;
	attr.event_mask = KeyPressMask | KeyReleaseMask | ExposureMask |
	                  StructureNotifyMask;
	mask = CWColormap | CWEventMask;
	
	win = XCreateWindow(dpy, root, 0, 0, 640, 480, 0, CopyFromParent,
			    InputOutput, vi->visual, mask, &attr);
	
	if (win == None) {
		fprintf(stderr, "Unable to create window\n");
		exit(EXIT_FAILURE);
	}
	
	XSetWMProperties(dpy, win, NULL, NULL, argv, argc, None, None, None);
	
	XStoreName(dpy, win, "Wolfenstein 3D");
	XSetIconName(dpy, win, "Wolfenstein 3D");
	
	wmDeleteWindow = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
	XSetWMProtocols(dpy, win, &wmDeleteWindow, 1);
	
	bitmap = XCreateBitmapFromData(dpy, win, data, 8, 8);
	cursor = XCreatePixmapCursor(dpy, bitmap, bitmap, &fg, &bg, 0, 0);
	XDefineCursor(dpy, win, cursor);
	
	glXMakeCurrent(dpy, win, ctx);
	
 	if (verbose) {
		printf("GL Library:\n");
		printf("GL_VENDOR: %s\n", glGetString(GL_VENDOR));
		printf("GL_RENDERER: %s\n", glGetString(GL_RENDERER));
		printf("GL_VERSION: %s\n", glGetString(GL_VERSION));
		printf("GL_EXTENSIONS: %s\n", glGetString(GL_EXTENSIONS));
	}
	
	XMapWindow(dpy, win);
	XFlush(dpy);
	
	ext = (const char *)glGetString(GL_EXTENSIONS);
#ifdef GL_EXT_shared_texture_palette
	UseSharedTexturePalette = 0;
	if (CheckToken(ext, "GL_EXT_shared_texture_palette")) {
		pglColorTableEXT = glXGetProcAddressARB((unsigned const char *)"glColorTableEXT");
		if (pglColorTableEXT) {
			UseSharedTexturePalette = 0;
			printf("GL_EXT_shared_texture_palette found...\n");
		}
	}
#endif
	
	glShadeModel(GL_FLAT);
	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
	
	InitData();
	
	SlowDown = 1;
	GameViewSize = 3;	
	NewGameWindow(GameViewSize); 

	ClearTheScreen(BLACK);
	BlastScreen();

	/* NoEnemies = 1; */
		
	return WolfMain(argc, argv);
}
Пример #21
0
void
glxglue_init(cc_glglue * w)
{
  /* SGI's glx.h header file shipped with the NVidia Linux drivers
     identifies glXGetCurrentDisplay() as a GLX 1.3 method, but Sun's
     GL man pages lists it as a GLX 1.2 function, ditto for HP's GL
     man pages, and ditto for AIX's man pages. (See top of this file
     for URL). So we will assume the man pages are correct.
  */
  struct cc_glxglue * g = &(w->glx);
  g->glXGetCurrentDisplay = NULL;
#ifdef GLX_VERSION_1_2
  g->glXGetCurrentDisplay = (COIN_PFNGLXGETCURRENTDISPLAYPROC)PROC(w, glXGetCurrentDisplay);
#endif /* GLX_VERSION_1_2 */

  glxglue_set_version(w, &w->glx.version.major, &w->glx.version.minor);
  w->glx.isdirect = glxglue_isdirect(w);


  w->glx.serverversion = NULL;
  w->glx.servervendor = NULL;
  w->glx.serverextensions = NULL;
  w->glx.clientversion = NULL;
  w->glx.clientvendor = NULL;
  w->glx.clientextensions = NULL;
  w->glx.glxextensions = NULL;

  if (glxglue_get_display(w)) {

    /* Note: be aware that glXQueryServerString(),
       glXGetClientString() and glXQueryExtensionsString() are all
       from GLX 1.1 -- just in case there are ever compile-time,
       link-time or run-time problems with this.  */

    Display * d = glxglue_get_display(w);
    w->glx.serverversion = glXQueryServerString(d, glxglue_screen, GLX_VERSION);
    w->glx.servervendor = glXQueryServerString(d, glxglue_screen, GLX_VENDOR);
    w->glx.serverextensions = glXQueryServerString(d, glxglue_screen, GLX_EXTENSIONS);

    w->glx.clientversion = glXGetClientString(d, GLX_VERSION);
    w->glx.clientvendor = glXGetClientString(d, GLX_VENDOR);
    w->glx.clientextensions = glXGetClientString(d, GLX_EXTENSIONS);

    w->glx.glxextensions = glXQueryExtensionsString(d, glxglue_screen);

    if (coin_glglue_debug()) {
      cc_debugerror_postinfo("glxglue_init",
                             "glXQueryServerString(GLX_VERSION)=='%s'",
                             w->glx.serverversion);
      cc_debugerror_postinfo("glxglue_init",
                             "glXQueryServerString(GLX_VENDOR)=='%s'",
                             w->glx.servervendor);
      cc_debugerror_postinfo("glxglue_init",
                             "glXQueryServerString(GLX_EXTENSIONS)=='%s'",
                             w->glx.serverextensions);

      cc_debugerror_postinfo("glxglue_init",
                             "glXClientString(GLX_VERSION)=='%s'",
                             w->glx.clientversion);
      cc_debugerror_postinfo("glxglue_init",
                             "glXClientString(GLX_VENDOR)=='%s'",
                             w->glx.clientvendor);
      cc_debugerror_postinfo("glxglue_init",
                             "glXClientString(GLX_EXTENSIONS)=='%s'",
                             w->glx.clientextensions);

      cc_debugerror_postinfo("glxglue_init",
                             "glXQueryExtensionsString()=='%s'",
                             w->glx.glxextensions);
    }
  }

  glxglue_resolve_symbols(w);
}
Пример #22
0
void WindowImpl::open() {
	const char *display;
	GLXFBConfig *fbConfigs;
	int nFBConfig;
	XVisualInfo *vInfo;
	XSetWindowAttributes swa;

	display = getenv("DISPLAY");
	if (display == nullptr)
		fail("DISPLAY not set");

	dpy = XOpenDisplay(display);
	if (dpy == nullptr)
		fail("Failed to open display");

	glXExtensions = glXQueryExtensionsString(dpy, DefaultScreen(dpy));
	glXCreateContextAttribsARB = reinterpret_cast<PFNGLXCREATECONTEXTATTRIBSARBPROC>(glXGetProcAddress((const GLubyte *)"glXCreateContextAttribsARB"));

#ifdef DISPLAY_GLX_INFO
	printf("Client version: %s\n", glXGetClientString(dpy, GLX_VERSION));
	printf("Client vendor: %s\n", glXGetClientString(dpy, GLX_VENDOR));
	printf("Client extensions: %s\n", glXGetClientString(dpy, GLX_EXTENSIONS));
	printf("Server version: %s\n", glXQueryServerString(dpy, DefaultScreen(dpy), GLX_VERSION));
	printf("Server vendor: %s\n", glXQueryServerString(dpy, DefaultScreen(dpy), GLX_VENDOR));
	printf("Server extensions: %s\n", glXQueryServerString(dpy, DefaultScreen(dpy), GLX_EXTENSIONS));
	printf("Connection extensions: %s\n", glXExtensions);
#endif

	fbConfigs = glXChooseFBConfig(dpy, DefaultScreen(dpy), framebufferAttribs, &nFBConfig);
	if (fbConfigs == nullptr)
		fail("Failed to find suitable framebuffer config");
#ifdef DISPLAY_GLX_INFO
	{
		int config_id;
		glXGetFBConfigAttrib(dpy, fbConfigs[0], GLX_FBCONFIG_ID, &config_id);
		printf("Chose FBConfig %#x\n", config_id);
	}
#endif

	vInfo = glXGetVisualFromFBConfig(dpy, fbConfigs[0]);
	if (vInfo == nullptr)
		fail("Failed to load framebuffer X visual");
	cmap = XCreateColormap(dpy, RootWindow(dpy, vInfo->screen), vInfo->visual, AllocNone);

	swa.border_pixel = 0;
	swa.event_mask = StructureNotifyMask;
	swa.colormap = cmap;

	win = XCreateWindow(dpy, RootWindow(dpy, vInfo->screen), 0, 0, 640, 480, 0, vInfo->depth, InputOutput, vInfo->visual, CWBorderPixel | CWColormap | CWEventMask, &swa);
	if (glXCreateContextAttribsARB != nullptr)
		ctx = glXCreateContextAttribsARB(dpy, fbConfigs[0], nullptr, True, contextAttribs);
	else
		ctx = glXCreateNewContext(dpy, fbConfigs[0], GLX_RGBA_TYPE, nullptr, True);
	if (ctx == nullptr) {
		fail("Failed to create OpenGL context");
	}
	xWin = glXCreateWindow(dpy, fbConfigs[0], win, nullptr);

	XFree(vInfo);
	XFree(fbConfigs);

	XMapWindow(dpy, win);
	if (!glXMakeContextCurrent(dpy, xWin, xWin, ctx))
		fail("Failed to make context current");

	printf("OpenGL version: %s\n", glGetString(GL_VERSION));

	wm_delete_window = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
	XSetWMProtocols(dpy, win, &wm_delete_window, 1);

	XSync(dpy, False);
}
Пример #23
0
static Colormap choose_cmap( Display *dpy, XVisualInfo *vi )
{
    if ( !cmap_dict ) {
	cmap_dict = new QIntDict<CMapEntry>;
	const char *v = glXQueryServerString( dpy, vi->screen, GLX_VERSION );
	if ( v )
	    mesa_gl = strstr(v,"Mesa") != 0;
	qAddPostRoutine( cleanup_cmaps );
    }

    CMapEntry *x = cmap_dict->find( (long)vi->visualid );
    if ( x )					// found colormap for visual
	return x->cmap;

    x = new CMapEntry();

    XStandardColormap *c;
    int n, i;

    //qDebug( "Choosing cmap for vID %0x", vi->visualid );

    if ( vi->visualid == 
	 XVisualIDFromVisual( (Visual*)QPaintDevice::x11AppVisual() ) ) {
	//qDebug( "Using x11AppColormap" );
	return QPaintDevice::x11AppColormap();
    }

    if ( mesa_gl ) {				// we're using MesaGL
	Atom hp_cmaps = XInternAtom( dpy, "_HP_RGB_SMOOTH_MAP_LIST", TRUE );
	if ( hp_cmaps && vi->visual->c_class == TrueColor && vi->depth == 8 ) {
	    if ( XGetRGBColormaps(dpy,RootWindow(dpy,vi->screen),&c,&n,
				  hp_cmaps) ) {
		i = 0;
		while ( i < n && x->cmap == 0 ) {
		    if ( c[i].visualid == vi->visual->visualid ) {
			x->cmap = c[i].colormap;
			x->scmap = c[i];
			//qDebug( "Using HP_RGB scmap" );

		    }
		    i++;
		}
		XFree( (char *)c );
	    }
	}
    }
#if !defined(_OS_SOLARIS_)
    if ( !x->cmap ) {
	if ( XmuLookupStandardColormap(dpy,vi->screen,vi->visualid,vi->depth,
				       XA_RGB_DEFAULT_MAP,FALSE,TRUE) ) {
	    if ( XGetRGBColormaps(dpy,RootWindow(dpy,vi->screen),&c,&n,
				  XA_RGB_DEFAULT_MAP) ) {
		i = 0;
		while ( i < n && x->cmap == 0 ) {
		    if ( c[i].visualid == vi->visualid ) {
			x->cmap = c[i].colormap;
			x->scmap = c[i];
			//qDebug( "Using RGB_DEFAULT scmap" );
		    }
		    i++;
		}
		XFree( (char *)c );
	    }
	}
    }
#endif
    if ( !x->cmap ) {				// no shared cmap found
	x->cmap = XCreateColormap( dpy, RootWindow(dpy,vi->screen), vi->visual,
				   AllocNone );
	x->alloc = TRUE;
	//qDebug( "Allocating cmap" );

    }

    cmap_dict->insert( (long)vi->visualid, x ); // associate cmap with visualid
    return x->cmap;
}
void GraphicsManager::updatePlanformExtensions()
{
    SDL_SysWMinfo info;
    SDL_VERSION(&info.version);
    if (SDL::getWindowWMInfo(mainGraphics->getWindow(), &info))
    {
#ifdef WIN32
        if (!mwglGetExtensionsString)
            return;

        HDC hdc = GetDC(info.window);
        if (hdc)
        {
            const char *const extensions = mwglGetExtensionsString(hdc);
            if (extensions)
            {
                logger->log1("wGL extensions:");
                logger->log1(extensions);
                splitToStringSet(mPlatformExtensions, extensions, ' ');
            }
        }
#elif defined USE_X11
        Display *const display = info.info.x11.display;
        if (display)
        {
            Screen *const screen = XDefaultScreenOfDisplay(display);
            if (!screen)
                return;

            const int screenNum = XScreenNumberOfScreen(screen);
            const char *const extensions = glXQueryExtensionsString(
                display, screenNum);
            if (extensions)
            {
                logger->log1("glx extensions:");
                logger->log1(extensions);
                splitToStringSet(mPlatformExtensions, extensions, ' ');
            }
            glXQueryVersion(display, &mPlatformMajor, &mPlatformMinor);
            if (checkPlatformVersion(1, 1))
            {
                const char *const vendor1 = glXQueryServerString(
                    display, screenNum, GLX_VENDOR);
                if (vendor1)
                    logger->log("glx server vendor: %s", vendor1);
                const char *const version1 = glXQueryServerString(
                    display, screenNum, GLX_VERSION);
                if (version1)
                    logger->log("glx server version: %s", version1);
                const char *const extensions1 = glXQueryServerString(
                    display, screenNum, GLX_EXTENSIONS);
                if (extensions1)
                {
                    logger->log1("glx server extensions:");
                    logger->log1(extensions1);
                }

                const char *const vendor2 = glXGetClientString(
                    display, GLX_VENDOR);
                if (vendor2)
                    logger->log("glx client vendor: %s", vendor2);
                const char *const version2 = glXGetClientString(
                    display, GLX_VERSION);
                if (version2)
                    logger->log("glx client version: %s", version2);
                const char *const extensions2 = glXGetClientString(
                    display, GLX_EXTENSIONS);
                if (extensions2)
                {
                    logger->log1("glx client extensions:");
                    logger->log1(extensions2);
                }
            }
            logger->log("width=%d", DisplayWidth(display, screenNum));
        }
#endif
    }
}
Пример #25
0
static Bool
print_screen_info(Display *dpy, int scrnum, Bool allowDirect,
                  Bool coreProfile, Bool es2Profile, Bool limits,
                  Bool singleLine, Bool coreWorked)
{
   Window win;
   XSetWindowAttributes attr;
   unsigned long mask;
   Window root;
   GLXContext ctx = NULL;
   XVisualInfo *visinfo;
   int width = 100, height = 100;
   GLXFBConfig *fbconfigs;
   const char *oglstring = coreProfile ? "OpenGL core profile" :
                           es2Profile ? "OpenGL ES profile" : "OpenGL";

   root = RootWindow(dpy, scrnum);

   /*
    * Choose FBConfig or XVisualInfo and create a context.
    */
   fbconfigs = choose_fb_config(dpy, scrnum);
   if (fbconfigs) {
      ctx = create_context_with_config(dpy, fbconfigs[0],
                                       coreProfile, es2Profile, allowDirect);
      if (!ctx && allowDirect && !coreProfile) {
         /* try indirect */
         ctx = create_context_with_config(dpy, fbconfigs[0],
                                          coreProfile, es2Profile, False);
      }

      visinfo = glXGetVisualFromFBConfig(dpy, fbconfigs[0]);
      XFree(fbconfigs);
   }
   else if (!coreProfile && !es2Profile) {
      visinfo = choose_xvisinfo(dpy, scrnum);
      if (visinfo)
	 ctx = glXCreateContext(dpy, visinfo, NULL, allowDirect);
   } else
      visinfo = NULL;

   if (!visinfo && !coreProfile && !es2Profile) {
      fprintf(stderr, "Error: couldn't find RGB GLX visual or fbconfig\n");
      return False;
   }

   if (!ctx) {
      if (!coreProfile && !es2Profile)
	 fprintf(stderr, "Error: glXCreateContext failed\n");
      XFree(visinfo);
      return False;
   }

   /*
    * Create a window so that we can just bind the context.
    */
   attr.background_pixel = 0;
   attr.border_pixel = 0;
   attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone);
   attr.event_mask = StructureNotifyMask | ExposureMask;
   mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
   win = XCreateWindow(dpy, root, 0, 0, width, height,
		       0, visinfo->depth, InputOutput,
		       visinfo->visual, mask, &attr);

   if (glXMakeCurrent(dpy, win, ctx)) {
      const char *serverVendor = glXQueryServerString(dpy, scrnum, GLX_VENDOR);
      const char *serverVersion = glXQueryServerString(dpy, scrnum, GLX_VERSION);
      const char *serverExtensions = glXQueryServerString(dpy, scrnum, GLX_EXTENSIONS);
      const char *clientVendor = glXGetClientString(dpy, GLX_VENDOR);
      const char *clientVersion = glXGetClientString(dpy, GLX_VERSION);
      const char *clientExtensions = glXGetClientString(dpy, GLX_EXTENSIONS);
      const char *glxExtensions = glXQueryExtensionsString(dpy, scrnum);
      const char *glVendor = (const char *) glGetString(GL_VENDOR);
      const char *glRenderer = (const char *) glGetString(GL_RENDERER);
      const char *glVersion = (const char *) glGetString(GL_VERSION);
      char *glExtensions;
      int glxVersionMajor;
      int glxVersionMinor;
      char *displayName = NULL;
      char *colon = NULL, *period = NULL;
      struct ext_functions extfuncs;

      CheckError(__LINE__);

      /* Get some ext functions */
      extfuncs.GetProgramivARB = (GETPROGRAMIVARBPROC)
         glXGetProcAddressARB((GLubyte *) "glGetProgramivARB");
      extfuncs.GetStringi = (GETSTRINGIPROC)
         glXGetProcAddressARB((GLubyte *) "glGetStringi");
      extfuncs.GetConvolutionParameteriv = (GETCONVOLUTIONPARAMETERIVPROC)
         glXGetProcAddressARB((GLubyte *) "glGetConvolutionParameteriv");

      /* Get list of GL extensions */
      if (coreProfile) {
         glExtensions = build_core_profile_extension_list(&extfuncs);
      }
      else {
         glExtensions = (char *) glGetString(GL_EXTENSIONS);
      }

      CheckError(__LINE__);

      if (! glXQueryVersion( dpy, & glxVersionMajor, & glxVersionMinor )) {
         fprintf(stderr, "Error: glXQueryVersion failed\n");
         exit(1);
      }

      if (!coreWorked) {
         /* Strip the screen number from the display name, if present. */
         if (!(displayName = (char *) malloc(strlen(DisplayString(dpy)) + 1))) {
            fprintf(stderr, "Error: malloc() failed\n");
            exit(1);
         }
         strcpy(displayName, DisplayString(dpy));
         colon = strrchr(displayName, ':');
         if (colon) {
            period = strchr(colon, '.');
            if (period)
               *period = '\0';
         }

         printf("display: %s  screen: %d\n", displayName, scrnum);
         free(displayName);
         printf("direct rendering: ");
         if (glXIsDirect(dpy, ctx)) {
            printf("Yes\n");
         }
         else {
            if (!allowDirect) {
               printf("No (-i specified)\n");
            }
            else if (getenv("LIBGL_ALWAYS_INDIRECT")) {
               printf("No (LIBGL_ALWAYS_INDIRECT set)\n");
            }
            else {
               printf("No (If you want to find out why, try setting "
                      "LIBGL_DEBUG=verbose)\n");
            }
         }
         printf("server glx vendor string: %s\n", serverVendor);
         printf("server glx version string: %s\n", serverVersion);
         printf("server glx extensions:\n");
         print_extension_list(serverExtensions, singleLine);
         printf("client glx vendor string: %s\n", clientVendor);
         printf("client glx version string: %s\n", clientVersion);
         printf("client glx extensions:\n");
         print_extension_list(clientExtensions, singleLine);
         printf("GLX version: %u.%u\n", glxVersionMajor, glxVersionMinor);
         printf("GLX extensions:\n");
         print_extension_list(glxExtensions, singleLine);
         printf("OpenGL vendor string: %s\n", glVendor);
         printf("OpenGL renderer string: %s\n", glRenderer);
      } else
         printf("\n");

      printf("%s version string: %s\n", oglstring, glVersion);

      version = (glVersion[0] - '0') * 10 + (glVersion[2] - '0');

      CheckError(__LINE__);

#ifdef GL_VERSION_2_0
      if (version >= 20) {
         char *v = (char *) glGetString(GL_SHADING_LANGUAGE_VERSION);
         printf("%s shading language version string: %s\n", oglstring, v);
      }
#endif
      CheckError(__LINE__);
#ifdef GL_VERSION_3_0
      if (version >= 30 && !es2Profile) {
         GLint flags;
         glGetIntegerv(GL_CONTEXT_FLAGS, &flags);
         printf("%s context flags: %s\n", oglstring, context_flags_string(flags));
      }
#endif
      CheckError(__LINE__);
#ifdef GL_VERSION_3_2
      if (version >= 32 && !es2Profile) {
         GLint mask;
         glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &mask);
         printf("%s profile mask: %s\n", oglstring, profile_mask_string(mask));
      }
#endif

      CheckError(__LINE__);

      printf("%s extensions:\n", oglstring);
      print_extension_list(glExtensions, singleLine);

      CheckError(__LINE__);

      if (limits) {
         print_limits(glExtensions, oglstring, version, &extfuncs);
      }

      if (coreProfile)
         free(glExtensions);
   }
   else {
      fprintf(stderr, "Error: glXMakeCurrent failed\n");
   }

   glXDestroyContext(dpy, ctx);
   XFree(visinfo);
   XDestroyWindow(dpy, win);
   XSync(dpy, 1);
   return True;
}