Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

glxinfo.c 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. /* $Id: glxinfo.c,v 1.12 2001/03/23 21:41:44 brianp Exp $ */
  2. /*
  3. * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included
  13. * in all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  16. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  19. * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  20. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. */
  22. /*
  23. * This program is a work-alike of the IRIX glxinfo program.
  24. * Command line options:
  25. * -t print wide table
  26. * -v print verbose information
  27. * -display DisplayName specify the X display to interogate
  28. * -b only print ID of "best" visual on screen 0
  29. *
  30. * Brian Paul 26 January 2000
  31. */
  32. #define DO_GLU /* may want to remove this for easier XFree86 building? */
  33. #include <X11/Xlib.h>
  34. #include <X11/Xutil.h>
  35. #include <GL/gl.h>
  36. #ifdef DO_GLU
  37. #include <GL/glu.h>
  38. #endif
  39. #include <GL/glx.h>
  40. #include <stdio.h>
  41. #include <string.h>
  42. #ifndef GLX_NONE_EXT
  43. #define GLX_NONE_EXT 0x8000
  44. #endif
  45. typedef enum
  46. {
  47. Normal,
  48. Wide,
  49. Verbose
  50. } InfoMode;
  51. struct visual_attribs
  52. {
  53. /* X visual attribs */
  54. int id;
  55. int klass;
  56. int depth;
  57. int redMask, greenMask, blueMask;
  58. int colormapSize;
  59. int bitsPerRGB;
  60. /* GL visual attribs */
  61. int supportsGL;
  62. int transparent;
  63. int bufferSize;
  64. int level;
  65. int rgba;
  66. int doubleBuffer;
  67. int stereo;
  68. int auxBuffers;
  69. int redSize, greenSize, blueSize, alphaSize;
  70. int depthSize;
  71. int stencilSize;
  72. int accumRedSize, accumGreenSize, accumBlueSize, accumAlphaSize;
  73. int numSamples, numMultisample;
  74. int visualCaveat;
  75. };
  76. /*
  77. * Print a list of extensions, with word-wrapping.
  78. */
  79. static void
  80. print_extension_list(const char *ext)
  81. {
  82. const char *indentString = " ";
  83. const int indent = 4;
  84. const int max = 79;
  85. int width, i, j;
  86. if (!ext || !ext[0])
  87. return;
  88. width = indent;
  89. printf(indentString);
  90. i = j = 0;
  91. while (1) {
  92. if (ext[j] == ' ' || ext[j] == 0) {
  93. /* found end of an extension name */
  94. const int len = j - i;
  95. if (width + len > max) {
  96. /* start a new line */
  97. printf("\n");
  98. width = indent;
  99. printf(indentString);
  100. }
  101. /* print the extension name between ext[i] and ext[j] */
  102. while (i < j) {
  103. printf("%c", ext[i]);
  104. i++;
  105. }
  106. /* either we're all done, or we'll continue with next extension */
  107. width += len + 1;
  108. if (ext[j] == 0) {
  109. break;
  110. }
  111. else {
  112. i++;
  113. j++;
  114. if (ext[j] == 0)
  115. break;
  116. printf(", ");
  117. width += 2;
  118. }
  119. }
  120. j++;
  121. }
  122. printf("\n");
  123. }
  124. static void
  125. print_screen_info(Display *dpy, int scrnum)
  126. {
  127. Window win;
  128. int attribSingle[] = {
  129. GLX_RGBA,
  130. GLX_RED_SIZE, 1,
  131. GLX_GREEN_SIZE, 1,
  132. GLX_BLUE_SIZE, 1,
  133. None };
  134. int attribDouble[] = {
  135. GLX_RGBA,
  136. GLX_RED_SIZE, 1,
  137. GLX_GREEN_SIZE, 1,
  138. GLX_BLUE_SIZE, 1,
  139. GLX_DOUBLEBUFFER,
  140. None };
  141. XSetWindowAttributes attr;
  142. unsigned long mask;
  143. Window root;
  144. GLXContext ctx;
  145. XVisualInfo *visinfo;
  146. int width = 100, height = 100;
  147. root = RootWindow(dpy, scrnum);
  148. visinfo = glXChooseVisual(dpy, scrnum, attribSingle);
  149. if (!visinfo) {
  150. visinfo = glXChooseVisual(dpy, scrnum, attribDouble);
  151. if (!visinfo) {
  152. fprintf(stderr, "Error: couldn't find RGB GLX visual\n");
  153. return;
  154. }
  155. }
  156. attr.background_pixel = 0;
  157. attr.border_pixel = 0;
  158. attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone);
  159. attr.event_mask = StructureNotifyMask | ExposureMask;
  160. mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
  161. win = XCreateWindow(dpy, root, 0, 0, width, height,
  162. 0, visinfo->depth, InputOutput,
  163. visinfo->visual, mask, &attr);
  164. ctx = glXCreateContext( dpy, visinfo, NULL, True );
  165. if (!ctx) {
  166. fprintf(stderr, "Error: glXCreateContext failed\n");
  167. XDestroyWindow(dpy, win);
  168. return;
  169. }
  170. if (glXMakeCurrent(dpy, win, ctx)) {
  171. const char *serverVendor = glXQueryServerString(dpy, scrnum, GLX_VENDOR);
  172. const char *serverVersion = glXQueryServerString(dpy, scrnum, GLX_VERSION);
  173. const char *serverExtensions = glXQueryServerString(dpy, scrnum, GLX_EXTENSIONS);
  174. const char *clientVendor = glXGetClientString(dpy, GLX_VENDOR);
  175. const char *clientVersion = glXGetClientString(dpy, GLX_VERSION);
  176. const char *clientExtensions = glXGetClientString(dpy, GLX_EXTENSIONS);
  177. const char *glxExtensions = glXQueryExtensionsString(dpy, scrnum);
  178. const char *glVendor = (const char *) glGetString(GL_VENDOR);
  179. const char *glRenderer = (const char *) glGetString(GL_RENDERER);
  180. const char *glVersion = (const char *) glGetString(GL_VERSION);
  181. const char *glExtensions = (const char *) glGetString(GL_EXTENSIONS);
  182. #ifdef DO_GLU
  183. const char *gluVersion = (const char *) gluGetString(GLU_VERSION);
  184. const char *gluExtensions = (const char *) gluGetString(GLU_EXTENSIONS);
  185. #endif
  186. printf("display: %s screen:%d\n", DisplayString(dpy), scrnum);
  187. printf("direct rendering: %s\n", glXIsDirect(dpy, ctx) ? "Yes" : "No");
  188. printf("server glx vendor string: %s\n", serverVendor);
  189. printf("server glx version string: %s\n", serverVersion);
  190. printf("server glx extensions:\n");
  191. print_extension_list(serverExtensions);
  192. printf("client glx vendor string: %s\n", clientVendor);
  193. printf("client glx version string: %s\n", clientVersion);
  194. printf("client glx extensions:\n");
  195. print_extension_list(clientExtensions);
  196. printf("GLX extensions:\n");
  197. print_extension_list(glxExtensions);
  198. printf("OpenGL vendor string: %s\n", glVendor);
  199. printf("OpenGL renderer string: %s\n", glRenderer);
  200. printf("OpenGL version string: %s\n", glVersion);
  201. printf("OpenGL extensions:\n");
  202. print_extension_list(glExtensions);
  203. #ifdef DO_GLU
  204. printf("glu version: %s\n", gluVersion);
  205. printf("glu extensions:\n");
  206. print_extension_list(gluExtensions);
  207. #endif
  208. }
  209. else {
  210. fprintf(stderr, "Error: glXMakeCurrent failed\n");
  211. }
  212. glXDestroyContext(dpy, ctx);
  213. XDestroyWindow(dpy, win);
  214. }
  215. static const char *
  216. visual_class_name(int cls)
  217. {
  218. switch (cls) {
  219. case StaticColor:
  220. return "StaticColor";
  221. case PseudoColor:
  222. return "PseudoColor";
  223. case StaticGray:
  224. return "StaticGray";
  225. case GrayScale:
  226. return "GrayScale";
  227. case TrueColor:
  228. return "TrueColor";
  229. case DirectColor:
  230. return "DirectColor";
  231. default:
  232. return "";
  233. }
  234. }
  235. static const char *
  236. visual_class_abbrev(int cls)
  237. {
  238. switch (cls) {
  239. case StaticColor:
  240. return "sc";
  241. case PseudoColor:
  242. return "pc";
  243. case StaticGray:
  244. return "sg";
  245. case GrayScale:
  246. return "gs";
  247. case TrueColor:
  248. return "tc";
  249. case DirectColor:
  250. return "dc";
  251. default:
  252. return "";
  253. }
  254. }
  255. static void
  256. get_visual_attribs(Display *dpy, XVisualInfo *vInfo,
  257. struct visual_attribs *attribs)
  258. {
  259. const char *ext = glXQueryExtensionsString(dpy, vInfo->screen);
  260. memset(attribs, 0, sizeof(struct visual_attribs));
  261. attribs->id = vInfo->visualid;
  262. #if defined(__cplusplus) || defined(c_plusplus)
  263. attribs->klass = vInfo->c_class;
  264. #else
  265. attribs->klass = vInfo->class;
  266. #endif
  267. attribs->depth = vInfo->depth;
  268. attribs->redMask = vInfo->red_mask;
  269. attribs->greenMask = vInfo->green_mask;
  270. attribs->blueMask = vInfo->blue_mask;
  271. attribs->colormapSize = vInfo->colormap_size;
  272. attribs->bitsPerRGB = vInfo->bits_per_rgb;
  273. if (glXGetConfig(dpy, vInfo, GLX_USE_GL, &attribs->supportsGL) != 0)
  274. return;
  275. glXGetConfig(dpy, vInfo, GLX_BUFFER_SIZE, &attribs->bufferSize);
  276. glXGetConfig(dpy, vInfo, GLX_LEVEL, &attribs->level);
  277. glXGetConfig(dpy, vInfo, GLX_RGBA, &attribs->rgba);
  278. glXGetConfig(dpy, vInfo, GLX_DOUBLEBUFFER, &attribs->doubleBuffer);
  279. glXGetConfig(dpy, vInfo, GLX_STEREO, &attribs->stereo);
  280. glXGetConfig(dpy, vInfo, GLX_AUX_BUFFERS, &attribs->auxBuffers);
  281. glXGetConfig(dpy, vInfo, GLX_RED_SIZE, &attribs->redSize);
  282. glXGetConfig(dpy, vInfo, GLX_GREEN_SIZE, &attribs->greenSize);
  283. glXGetConfig(dpy, vInfo, GLX_BLUE_SIZE, &attribs->blueSize);
  284. glXGetConfig(dpy, vInfo, GLX_ALPHA_SIZE, &attribs->alphaSize);
  285. glXGetConfig(dpy, vInfo, GLX_DEPTH_SIZE, &attribs->depthSize);
  286. glXGetConfig(dpy, vInfo, GLX_STENCIL_SIZE, &attribs->stencilSize);
  287. glXGetConfig(dpy, vInfo, GLX_ACCUM_RED_SIZE, &attribs->accumRedSize);
  288. glXGetConfig(dpy, vInfo, GLX_ACCUM_GREEN_SIZE, &attribs->accumGreenSize);
  289. glXGetConfig(dpy, vInfo, GLX_ACCUM_BLUE_SIZE, &attribs->accumBlueSize);
  290. glXGetConfig(dpy, vInfo, GLX_ACCUM_ALPHA_SIZE, &attribs->accumAlphaSize);
  291. /* transparent pixel value not implemented yet */
  292. attribs->transparent = 0;
  293. /* multisample tests not implemented yet */
  294. attribs->numSamples = 0;
  295. attribs->numMultisample = 0;
  296. #if defined(GLX_EXT_visual_rating)
  297. if (ext && strstr(ext, "GLX_EXT_visual_rating")) {
  298. glXGetConfig(dpy, vInfo, GLX_VISUAL_CAVEAT_EXT, &attribs->visualCaveat);
  299. }
  300. else {
  301. attribs->visualCaveat = GLX_NONE_EXT;
  302. }
  303. #else
  304. attribs->visualCaveat = 0;
  305. #endif
  306. }
  307. static void
  308. print_visual_attribs_verbose(const struct visual_attribs *attribs)
  309. {
  310. printf("Visual ID: %x depth=%d class=%s\n",
  311. attribs->id, attribs->depth, visual_class_name(attribs->klass));
  312. printf(" bufferSize=%d level=%d renderType=%s doubleBuffer=%d stereo=%d\n",
  313. attribs->bufferSize, attribs->level, attribs->rgba ? "rgba" : "ci",
  314. attribs->doubleBuffer, attribs->stereo);
  315. printf(" rgba: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n",
  316. attribs->redSize, attribs->greenSize,
  317. attribs->blueSize, attribs->alphaSize);
  318. printf(" auxBuffers=%d depthSize=%d stencilSize=%d\n",
  319. attribs->auxBuffers, attribs->depthSize, attribs->stencilSize);
  320. printf(" accum: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n",
  321. attribs->accumRedSize, attribs->accumGreenSize,
  322. attribs->accumBlueSize, attribs->accumAlphaSize);
  323. printf(" multiSample=%d multiSampleBuffers=%d\n",
  324. attribs->numSamples, attribs->numMultisample);
  325. #ifdef GLX_EXT_visual_rating
  326. if (attribs->visualCaveat == GLX_NONE_EXT || attribs->visualCaveat == 0)
  327. printf(" visualCaveat=None\n");
  328. else if (attribs->visualCaveat == GLX_SLOW_VISUAL_EXT)
  329. printf(" visualCaveat=Slow\n");
  330. else if (attribs->visualCaveat == GLX_NON_CONFORMANT_VISUAL_EXT)
  331. printf(" visualCaveat=Nonconformant\n");
  332. #endif
  333. printf(" %s\n", attribs->transparent ? "Transparent." : "Opaque.");
  334. }
  335. static void
  336. print_visual_attribs_short_header(void)
  337. {
  338. printf(" visual x bf lv rg d st colorbuffer ax dp st accumbuffer ms cav\n");
  339. printf(" id dep cl sp sz l ci b ro r g b a bf th cl r g b a ns b eat\n");
  340. printf("----------------------------------------------------------------------\n");
  341. }
  342. static void
  343. print_visual_attribs_short(const struct visual_attribs *attribs)
  344. {
  345. char *caveat;
  346. #ifdef GLX_EXT_visual_rating
  347. if (attribs->visualCaveat == GLX_NONE_EXT || attribs->visualCaveat == 0)
  348. caveat = "None";
  349. else if (attribs->visualCaveat == GLX_SLOW_VISUAL_EXT)
  350. caveat = "Slow";
  351. else if (attribs->visualCaveat == GLX_NON_CONFORMANT_VISUAL_EXT)
  352. caveat = "Ncon";
  353. #else
  354. caveat = "None";
  355. #endif
  356. printf("0x%2x %2d %2s %2d %2d %2d %1s %2s %2s %2d %2d %2d %2d %2d %2d %2d",
  357. attribs->id,
  358. attribs->depth,
  359. visual_class_abbrev(attribs->klass),
  360. attribs->transparent,
  361. attribs->bufferSize,
  362. attribs->level,
  363. attribs->rgba ? "r" : "c",
  364. attribs->doubleBuffer ? "y" : ".",
  365. attribs->stereo ? "y" : ".",
  366. attribs->redSize, attribs->greenSize,
  367. attribs->blueSize, attribs->alphaSize,
  368. attribs->auxBuffers,
  369. attribs->depthSize,
  370. attribs->stencilSize
  371. );
  372. printf(" %2d %2d %2d %2d %2d %1d %s\n",
  373. attribs->accumRedSize, attribs->accumGreenSize,
  374. attribs->accumBlueSize, attribs->accumAlphaSize,
  375. attribs->numSamples, attribs->numMultisample,
  376. caveat
  377. );
  378. }
  379. static void
  380. print_visual_attribs_long_header(void)
  381. {
  382. printf("Vis Vis Visual Trans buff lev render DB ste r g b a aux dep ste accum buffers MS MS\n");
  383. printf(" ID Depth Type parent size el type reo sz sz sz sz buf th ncl r g b a num bufs\n");
  384. printf("----------------------------------------------------------------------------------------------------\n");
  385. }
  386. static void
  387. print_visual_attribs_long(const struct visual_attribs *attribs)
  388. {
  389. printf("0x%2x %2d %-11s %2d %2d %2d %4s %3d %3d %3d %3d %3d %3d",
  390. attribs->id,
  391. attribs->depth,
  392. visual_class_name(attribs->klass),
  393. attribs->transparent,
  394. attribs->bufferSize,
  395. attribs->level,
  396. attribs->rgba ? "rgba" : "ci ",
  397. attribs->doubleBuffer,
  398. attribs->stereo,
  399. attribs->redSize, attribs->greenSize,
  400. attribs->blueSize, attribs->alphaSize
  401. );
  402. printf(" %3d %4d %2d %3d %3d %3d %3d %2d %2d\n",
  403. attribs->auxBuffers,
  404. attribs->depthSize,
  405. attribs->stencilSize,
  406. attribs->accumRedSize, attribs->accumGreenSize,
  407. attribs->accumBlueSize, attribs->accumAlphaSize,
  408. attribs->numSamples, attribs->numMultisample
  409. );
  410. }
  411. static void
  412. print_visual_info(Display *dpy, int scrnum, InfoMode mode)
  413. {
  414. XVisualInfo template;
  415. XVisualInfo *visuals;
  416. int numVisuals;
  417. long mask;
  418. int i;
  419. /* get list of all visuals on this screen */
  420. template.screen = scrnum;
  421. mask = VisualScreenMask;
  422. visuals = XGetVisualInfo(dpy, mask, &template, &numVisuals);
  423. if (mode == Verbose) {
  424. for (i = 0; i < numVisuals; i++) {
  425. struct visual_attribs attribs;
  426. get_visual_attribs(dpy, &visuals[i], &attribs);
  427. print_visual_attribs_verbose(&attribs);
  428. }
  429. }
  430. else if (mode == Normal) {
  431. print_visual_attribs_short_header();
  432. for (i = 0; i < numVisuals; i++) {
  433. struct visual_attribs attribs;
  434. get_visual_attribs(dpy, &visuals[i], &attribs);
  435. print_visual_attribs_short(&attribs);
  436. }
  437. }
  438. else if (mode == Wide) {
  439. print_visual_attribs_long_header();
  440. for (i = 0; i < numVisuals; i++) {
  441. struct visual_attribs attribs;
  442. get_visual_attribs(dpy, &visuals[i], &attribs);
  443. print_visual_attribs_long(&attribs);
  444. }
  445. }
  446. XFree(visuals);
  447. }
  448. /*
  449. * Stand-alone Mesa doesn't really implement the GLX protocol so it
  450. * doesn't really know the GLX attributes associated with an X visual.
  451. * The first time a visual is presented to Mesa's pseudo-GLX it
  452. * attaches ancilliary buffers to it (like depth and stencil).
  453. * But that usually only works if glXChooseVisual is used.
  454. * This function calls glXChooseVisual() to sort of "prime the pump"
  455. * for Mesa's GLX so that the visuals that get reported actually
  456. * reflect what applications will see.
  457. * This has no effect when using true GLX.
  458. */
  459. static void
  460. mesa_hack(Display *dpy, int scrnum)
  461. {
  462. static int attribs[] = {
  463. GLX_RGBA,
  464. GLX_RED_SIZE, 1,
  465. GLX_GREEN_SIZE, 1,
  466. GLX_BLUE_SIZE, 1,
  467. GLX_DEPTH_SIZE, 1,
  468. GLX_STENCIL_SIZE, 1,
  469. GLX_ACCUM_RED_SIZE, 1,
  470. GLX_ACCUM_GREEN_SIZE, 1,
  471. GLX_ACCUM_BLUE_SIZE, 1,
  472. GLX_ACCUM_ALPHA_SIZE, 1,
  473. GLX_DOUBLEBUFFER,
  474. None
  475. };
  476. XVisualInfo *visinfo;
  477. visinfo = glXChooseVisual(dpy, scrnum, attribs);
  478. if (visinfo)
  479. XFree(visinfo);
  480. }
  481. /*
  482. * Examine all visuals to find the so-called best one.
  483. * We prefer deepest RGBA buffer with depth, stencil and accum
  484. * that has no caveats.
  485. */
  486. static int
  487. find_best_visual(Display *dpy, int scrnum)
  488. {
  489. XVisualInfo template;
  490. XVisualInfo *visuals;
  491. int numVisuals;
  492. long mask;
  493. int i;
  494. struct visual_attribs bestVis;
  495. /* get list of all visuals on this screen */
  496. template.screen = scrnum;
  497. mask = VisualScreenMask;
  498. visuals = XGetVisualInfo(dpy, mask, &template, &numVisuals);
  499. /* init bestVis with first visual info */
  500. get_visual_attribs(dpy, &visuals[0], &bestVis);
  501. /* try to find a "better" visual */
  502. for (i = 1; i < numVisuals; i++) {
  503. struct visual_attribs vis;
  504. get_visual_attribs(dpy, &visuals[i], &vis);
  505. /* always skip visuals with caveats */
  506. if (vis.visualCaveat != GLX_NONE_EXT)
  507. continue;
  508. /* see if this vis is better than bestVis */
  509. if ((!bestVis.supportsGL && vis.supportsGL) ||
  510. (bestVis.visualCaveat != GLX_NONE_EXT) ||
  511. (!bestVis.rgba && vis.rgba) ||
  512. (!bestVis.doubleBuffer && vis.doubleBuffer) ||
  513. (bestVis.redSize < vis.redSize) ||
  514. (bestVis.greenSize < vis.greenSize) ||
  515. (bestVis.blueSize < vis.blueSize) ||
  516. (bestVis.alphaSize < vis.alphaSize) ||
  517. (bestVis.depthSize < vis.depthSize) ||
  518. (bestVis.stencilSize < vis.stencilSize) ||
  519. (bestVis.accumRedSize < vis.accumRedSize)) {
  520. /* found a better visual */
  521. bestVis = vis;
  522. }
  523. }
  524. XFree(visuals);
  525. return bestVis.id;
  526. }
  527. int
  528. main(int argc, char *argv[])
  529. {
  530. char *displayName = NULL;
  531. Display *dpy;
  532. int numScreens, scrnum;
  533. InfoMode mode = Normal;
  534. GLboolean findBest = GL_FALSE;
  535. int i;
  536. for (i = 1; i < argc; i++) {
  537. if (strcmp(argv[i], "-display") == 0 && i + 1 < argc) {
  538. displayName = argv[i + 1];
  539. i++;
  540. }
  541. else if (strcmp(argv[i], "-t") == 0) {
  542. mode = Wide;
  543. }
  544. else if (strcmp(argv[i], "-v") == 0) {
  545. mode = Verbose;
  546. }
  547. else if (strcmp(argv[i], "-b") == 0) {
  548. findBest = GL_TRUE;
  549. }
  550. }
  551. dpy = XOpenDisplay(displayName);
  552. if (!dpy) {
  553. fprintf(stderr, "Error: unable to open display %s\n", displayName);
  554. return -1;
  555. }
  556. if (findBest) {
  557. int b;
  558. mesa_hack(dpy, 0);
  559. b = find_best_visual(dpy, 0);
  560. printf("%d\n", b);
  561. }
  562. else {
  563. numScreens = ScreenCount(dpy);
  564. for (scrnum = 0; scrnum < numScreens; scrnum++) {
  565. mesa_hack(dpy, scrnum);
  566. print_screen_info(dpy, scrnum);
  567. printf("\n");
  568. print_visual_info(dpy, scrnum, mode);
  569. if (scrnum + 1 < numScreens)
  570. printf("\n\n");
  571. }
  572. }
  573. XCloseDisplay(dpy);
  574. return 0;
  575. }