blob: 21a9a60331f2dca8cbdb3a585f584c4cb25d656f [file] [log] [blame]
Brian Paul39557c32001-03-23 21:41:44 +00001/* $Id: glxinfo.c,v 1.12 2001/03/23 21:41:44 brianp Exp $ */
Brian Pauld2bfe1e1999-09-16 16:40:46 +00002
3/*
Brian Paul39557c32001-03-23 21:41:44 +00004 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
Brian Paul76bc4402000-01-27 16:43:56 +00005 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Brian Pauld2bfe1e1999-09-16 16:40:46 +000022 */
23
24
Brian Paul76bc4402000-01-27 16:43:56 +000025/*
26 * This program is a work-alike of the IRIX glxinfo program.
27 * Command line options:
28 * -t print wide table
29 * -v print verbose information
30 * -display DisplayName specify the X display to interogate
Brian Paul39557c32001-03-23 21:41:44 +000031 * -b only print ID of "best" visual on screen 0
Brian Paul76bc4402000-01-27 16:43:56 +000032 *
33 * Brian Paul 26 January 2000
34 */
Brian Pauld2bfe1e1999-09-16 16:40:46 +000035
Brian Paul39557c32001-03-23 21:41:44 +000036#define DO_GLU /* may want to remove this for easier XFree86 building? */
Brian Paul76bc4402000-01-27 16:43:56 +000037
38#include <X11/Xlib.h>
39#include <X11/Xutil.h>
Brian Pauld2bfe1e1999-09-16 16:40:46 +000040#include <GL/gl.h>
Brian Paul39557c32001-03-23 21:41:44 +000041#ifdef DO_GLU
Brian Pauld2bfe1e1999-09-16 16:40:46 +000042#include <GL/glu.h>
Brian Paul39557c32001-03-23 21:41:44 +000043#endif
Brian Paul76bc4402000-01-27 16:43:56 +000044#include <GL/glx.h>
Brian Pauld2bfe1e1999-09-16 16:40:46 +000045#include <stdio.h>
Brian Paul76bc4402000-01-27 16:43:56 +000046#include <string.h>
Brian Pauld2bfe1e1999-09-16 16:40:46 +000047
48
Brian Paul39557c32001-03-23 21:41:44 +000049#ifndef GLX_NONE_EXT
50#define GLX_NONE_EXT 0x8000
51#endif
52
53
Brian Paul76bc4402000-01-27 16:43:56 +000054typedef enum
Brian Pauld2bfe1e1999-09-16 16:40:46 +000055{
Brian Paul76bc4402000-01-27 16:43:56 +000056 Normal,
57 Wide,
58 Verbose
59} InfoMode;
Brian Pauld2bfe1e1999-09-16 16:40:46 +000060
Brian Pauld2bfe1e1999-09-16 16:40:46 +000061
Brian Paul76bc4402000-01-27 16:43:56 +000062struct visual_attribs
63{
64 /* X visual attribs */
65 int id;
66 int klass;
67 int depth;
68 int redMask, greenMask, blueMask;
69 int colormapSize;
70 int bitsPerRGB;
Brian Pauld2bfe1e1999-09-16 16:40:46 +000071
Brian Paul76bc4402000-01-27 16:43:56 +000072 /* GL visual attribs */
73 int supportsGL;
74 int transparent;
75 int bufferSize;
76 int level;
77 int rgba;
78 int doubleBuffer;
79 int stereo;
80 int auxBuffers;
81 int redSize, greenSize, blueSize, alphaSize;
82 int depthSize;
83 int stencilSize;
84 int accumRedSize, accumGreenSize, accumBlueSize, accumAlphaSize;
85 int numSamples, numMultisample;
Brian Paul25673f02000-03-31 18:17:51 +000086 int visualCaveat;
Brian Paul76bc4402000-01-27 16:43:56 +000087};
88
89
90/*
91 * Print a list of extensions, with word-wrapping.
92 */
93static void
94print_extension_list(const char *ext)
95{
96 const char *indentString = " ";
97 const int indent = 4;
98 const int max = 79;
99 int width, i, j;
100
101 if (!ext || !ext[0])
102 return;
103
104 width = indent;
105 printf(indentString);
106 i = j = 0;
107 while (1) {
108 if (ext[j] == ' ' || ext[j] == 0) {
109 /* found end of an extension name */
110 const int len = j - i;
111 if (width + len > max) {
112 /* start a new line */
113 printf("\n");
114 width = indent;
115 printf(indentString);
116 }
117 /* print the extension name between ext[i] and ext[j] */
118 while (i < j) {
119 printf("%c", ext[i]);
120 i++;
121 }
122 /* either we're all done, or we'll continue with next extension */
123 width += len + 1;
124 if (ext[j] == 0) {
125 break;
126 }
127 else {
128 i++;
129 j++;
Brian Paul7ac43502000-02-23 22:50:35 +0000130 if (ext[j] == 0)
131 break;
Brian Paul76bc4402000-01-27 16:43:56 +0000132 printf(", ");
133 width += 2;
134 }
135 }
136 j++;
137 }
138 printf("\n");
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000139}
140
141
Brian Paul76bc4402000-01-27 16:43:56 +0000142static void
143print_screen_info(Display *dpy, int scrnum)
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000144{
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000145 Window win;
Brian Paul8460cc92000-02-02 20:57:51 +0000146 int attribSingle[] = {
147 GLX_RGBA,
148 GLX_RED_SIZE, 1,
149 GLX_GREEN_SIZE, 1,
150 GLX_BLUE_SIZE, 1,
151 None };
152 int attribDouble[] = {
153 GLX_RGBA,
154 GLX_RED_SIZE, 1,
155 GLX_GREEN_SIZE, 1,
156 GLX_BLUE_SIZE, 1,
157 GLX_DOUBLEBUFFER,
158 None };
159
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000160 XSetWindowAttributes attr;
161 unsigned long mask;
162 Window root;
163 GLXContext ctx;
164 XVisualInfo *visinfo;
165 int width = 100, height = 100;
166
Brian Paul76bc4402000-01-27 16:43:56 +0000167 root = RootWindow(dpy, scrnum);
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000168
Brian Paul8460cc92000-02-02 20:57:51 +0000169 visinfo = glXChooseVisual(dpy, scrnum, attribSingle);
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000170 if (!visinfo) {
Brian Paul8460cc92000-02-02 20:57:51 +0000171 visinfo = glXChooseVisual(dpy, scrnum, attribDouble);
172 if (!visinfo) {
Brian Paul9cff5582000-05-07 18:07:23 +0000173 fprintf(stderr, "Error: couldn't find RGB GLX visual\n");
Brian Paul8460cc92000-02-02 20:57:51 +0000174 return;
175 }
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000176 }
177
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000178 attr.background_pixel = 0;
179 attr.border_pixel = 0;
Brian Paul9cff5582000-05-07 18:07:23 +0000180 attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone);
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000181 attr.event_mask = StructureNotifyMask | ExposureMask;
182 mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
Brian Paul76bc4402000-01-27 16:43:56 +0000183 win = XCreateWindow(dpy, root, 0, 0, width, height,
184 0, visinfo->depth, InputOutput,
185 visinfo->visual, mask, &attr);
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000186
187 ctx = glXCreateContext( dpy, visinfo, NULL, True );
Brian Paul34fb5db2000-04-22 20:31:23 +0000188 if (!ctx) {
Brian Paul9cff5582000-05-07 18:07:23 +0000189 fprintf(stderr, "Error: glXCreateContext failed\n");
Brian Paul34fb5db2000-04-22 20:31:23 +0000190 XDestroyWindow(dpy, win);
191 return;
192 }
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000193
Brian Paul9cff5582000-05-07 18:07:23 +0000194 if (glXMakeCurrent(dpy, win, ctx)) {
Brian Paul76bc4402000-01-27 16:43:56 +0000195 const char *serverVendor = glXQueryServerString(dpy, scrnum, GLX_VENDOR);
196 const char *serverVersion = glXQueryServerString(dpy, scrnum, GLX_VERSION);
197 const char *serverExtensions = glXQueryServerString(dpy, scrnum, GLX_EXTENSIONS);
Brian Paul34fb5db2000-04-22 20:31:23 +0000198 const char *clientVendor = glXGetClientString(dpy, GLX_VENDOR);
Brian Paul76bc4402000-01-27 16:43:56 +0000199 const char *clientVersion = glXGetClientString(dpy, GLX_VERSION);
200 const char *clientExtensions = glXGetClientString(dpy, GLX_EXTENSIONS);
201 const char *glxExtensions = glXQueryExtensionsString(dpy, scrnum);
202 const char *glVendor = (const char *) glGetString(GL_VENDOR);
203 const char *glRenderer = (const char *) glGetString(GL_RENDERER);
204 const char *glVersion = (const char *) glGetString(GL_VERSION);
205 const char *glExtensions = (const char *) glGetString(GL_EXTENSIONS);
Brian Paul39557c32001-03-23 21:41:44 +0000206#ifdef DO_GLU
Brian Paul76bc4402000-01-27 16:43:56 +0000207 const char *gluVersion = (const char *) gluGetString(GLU_VERSION);
208 const char *gluExtensions = (const char *) gluGetString(GLU_EXTENSIONS);
Brian Paul39557c32001-03-23 21:41:44 +0000209#endif
Brian Paul76bc4402000-01-27 16:43:56 +0000210 printf("display: %s screen:%d\n", DisplayString(dpy), scrnum);
Brian Paule691ee22000-05-08 14:53:57 +0000211 printf("direct rendering: %s\n", glXIsDirect(dpy, ctx) ? "Yes" : "No");
Brian Paul76bc4402000-01-27 16:43:56 +0000212 printf("server glx vendor string: %s\n", serverVendor);
213 printf("server glx version string: %s\n", serverVersion);
214 printf("server glx extensions:\n");
215 print_extension_list(serverExtensions);
Brian Paul34fb5db2000-04-22 20:31:23 +0000216 printf("client glx vendor string: %s\n", clientVendor);
217 printf("client glx version string: %s\n", clientVersion);
Brian Paul76bc4402000-01-27 16:43:56 +0000218 printf("client glx extensions:\n");
219 print_extension_list(clientExtensions);
220 printf("GLX extensions:\n");
221 print_extension_list(glxExtensions);
222 printf("OpenGL vendor string: %s\n", glVendor);
223 printf("OpenGL renderer string: %s\n", glRenderer);
224 printf("OpenGL version string: %s\n", glVersion);
225 printf("OpenGL extensions:\n");
226 print_extension_list(glExtensions);
Brian Paul39557c32001-03-23 21:41:44 +0000227#ifdef DO_GLU
Brian Paul76bc4402000-01-27 16:43:56 +0000228 printf("glu version: %s\n", gluVersion);
229 printf("glu extensions:\n");
230 print_extension_list(gluExtensions);
Brian Paul39557c32001-03-23 21:41:44 +0000231#endif
Brian Paul76bc4402000-01-27 16:43:56 +0000232 }
Brian Paul9cff5582000-05-07 18:07:23 +0000233 else {
234 fprintf(stderr, "Error: glXMakeCurrent failed\n");
235 }
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000236
237 glXDestroyContext(dpy, ctx);
238 XDestroyWindow(dpy, win);
Brian Paul76bc4402000-01-27 16:43:56 +0000239}
240
241
242static const char *
243visual_class_name(int cls)
244{
245 switch (cls) {
246 case StaticColor:
247 return "StaticColor";
248 case PseudoColor:
249 return "PseudoColor";
250 case StaticGray:
251 return "StaticGray";
252 case GrayScale:
253 return "GrayScale";
254 case TrueColor:
255 return "TrueColor";
256 case DirectColor:
257 return "DirectColor";
258 default:
259 return "";
260 }
261}
262
263
264static const char *
265visual_class_abbrev(int cls)
266{
267 switch (cls) {
268 case StaticColor:
269 return "sc";
270 case PseudoColor:
271 return "pc";
272 case StaticGray:
273 return "sg";
274 case GrayScale:
275 return "gs";
276 case TrueColor:
277 return "tc";
278 case DirectColor:
279 return "dc";
280 default:
281 return "";
282 }
283}
284
285
286static void
287get_visual_attribs(Display *dpy, XVisualInfo *vInfo,
288 struct visual_attribs *attribs)
289{
Brian Paul25673f02000-03-31 18:17:51 +0000290 const char *ext = glXQueryExtensionsString(dpy, vInfo->screen);
291
Brian Paula9c53fa2000-04-03 15:45:34 +0000292 memset(attribs, 0, sizeof(struct visual_attribs));
293
Brian Paul76bc4402000-01-27 16:43:56 +0000294 attribs->id = vInfo->visualid;
295#if defined(__cplusplus) || defined(c_plusplus)
296 attribs->klass = vInfo->c_class;
297#else
298 attribs->klass = vInfo->class;
299#endif
300 attribs->depth = vInfo->depth;
301 attribs->redMask = vInfo->red_mask;
302 attribs->greenMask = vInfo->green_mask;
303 attribs->blueMask = vInfo->blue_mask;
304 attribs->colormapSize = vInfo->colormap_size;
305 attribs->bitsPerRGB = vInfo->bits_per_rgb;
306
Brian Paula9c53fa2000-04-03 15:45:34 +0000307 if (glXGetConfig(dpy, vInfo, GLX_USE_GL, &attribs->supportsGL) != 0)
308 return;
Brian Paul76bc4402000-01-27 16:43:56 +0000309 glXGetConfig(dpy, vInfo, GLX_BUFFER_SIZE, &attribs->bufferSize);
310 glXGetConfig(dpy, vInfo, GLX_LEVEL, &attribs->level);
311 glXGetConfig(dpy, vInfo, GLX_RGBA, &attribs->rgba);
312 glXGetConfig(dpy, vInfo, GLX_DOUBLEBUFFER, &attribs->doubleBuffer);
313 glXGetConfig(dpy, vInfo, GLX_STEREO, &attribs->stereo);
314 glXGetConfig(dpy, vInfo, GLX_AUX_BUFFERS, &attribs->auxBuffers);
315 glXGetConfig(dpy, vInfo, GLX_RED_SIZE, &attribs->redSize);
316 glXGetConfig(dpy, vInfo, GLX_GREEN_SIZE, &attribs->greenSize);
317 glXGetConfig(dpy, vInfo, GLX_BLUE_SIZE, &attribs->blueSize);
318 glXGetConfig(dpy, vInfo, GLX_ALPHA_SIZE, &attribs->alphaSize);
319 glXGetConfig(dpy, vInfo, GLX_DEPTH_SIZE, &attribs->depthSize);
320 glXGetConfig(dpy, vInfo, GLX_STENCIL_SIZE, &attribs->stencilSize);
321 glXGetConfig(dpy, vInfo, GLX_ACCUM_RED_SIZE, &attribs->accumRedSize);
322 glXGetConfig(dpy, vInfo, GLX_ACCUM_GREEN_SIZE, &attribs->accumGreenSize);
323 glXGetConfig(dpy, vInfo, GLX_ACCUM_BLUE_SIZE, &attribs->accumBlueSize);
324 glXGetConfig(dpy, vInfo, GLX_ACCUM_ALPHA_SIZE, &attribs->accumAlphaSize);
325
Brian Paule06c7f32000-01-27 16:53:55 +0000326 /* transparent pixel value not implemented yet */
327 attribs->transparent = 0;
328
329 /* multisample tests not implemented yet */
Brian Paul76bc4402000-01-27 16:43:56 +0000330 attribs->numSamples = 0;
331 attribs->numMultisample = 0;
Brian Paul25673f02000-03-31 18:17:51 +0000332
333#if defined(GLX_EXT_visual_rating)
334 if (ext && strstr(ext, "GLX_EXT_visual_rating")) {
335 glXGetConfig(dpy, vInfo, GLX_VISUAL_CAVEAT_EXT, &attribs->visualCaveat);
336 }
337 else {
338 attribs->visualCaveat = GLX_NONE_EXT;
339 }
340#else
341 attribs->visualCaveat = 0;
342#endif
Brian Paul76bc4402000-01-27 16:43:56 +0000343}
344
345
346static void
347print_visual_attribs_verbose(const struct visual_attribs *attribs)
348{
349 printf("Visual ID: %x depth=%d class=%s\n",
350 attribs->id, attribs->depth, visual_class_name(attribs->klass));
351 printf(" bufferSize=%d level=%d renderType=%s doubleBuffer=%d stereo=%d\n",
352 attribs->bufferSize, attribs->level, attribs->rgba ? "rgba" : "ci",
353 attribs->doubleBuffer, attribs->stereo);
354 printf(" rgba: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n",
355 attribs->redSize, attribs->greenSize,
356 attribs->blueSize, attribs->alphaSize);
357 printf(" auxBuffers=%d depthSize=%d stencilSize=%d\n",
358 attribs->auxBuffers, attribs->depthSize, attribs->stencilSize);
359 printf(" accum: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n",
360 attribs->accumRedSize, attribs->accumGreenSize,
361 attribs->accumBlueSize, attribs->accumAlphaSize);
362 printf(" multiSample=%d multiSampleBuffers=%d\n",
363 attribs->numSamples, attribs->numMultisample);
Brian Paul25673f02000-03-31 18:17:51 +0000364#ifdef GLX_EXT_visual_rating
365 if (attribs->visualCaveat == GLX_NONE_EXT || attribs->visualCaveat == 0)
Brian Paula9c53fa2000-04-03 15:45:34 +0000366 printf(" visualCaveat=None\n");
Brian Paul25673f02000-03-31 18:17:51 +0000367 else if (attribs->visualCaveat == GLX_SLOW_VISUAL_EXT)
Brian Paula9c53fa2000-04-03 15:45:34 +0000368 printf(" visualCaveat=Slow\n");
Brian Paul25673f02000-03-31 18:17:51 +0000369 else if (attribs->visualCaveat == GLX_NON_CONFORMANT_VISUAL_EXT)
Brian Paula9c53fa2000-04-03 15:45:34 +0000370 printf(" visualCaveat=Nonconformant\n");
Brian Paul25673f02000-03-31 18:17:51 +0000371#endif
Brian Paula9c53fa2000-04-03 15:45:34 +0000372 printf(" %s\n", attribs->transparent ? "Transparent." : "Opaque.");
Brian Paul76bc4402000-01-27 16:43:56 +0000373}
374
375
376static void
377print_visual_attribs_short_header(void)
378{
Brian Paula9c53fa2000-04-03 15:45:34 +0000379 printf(" visual x bf lv rg d st colorbuffer ax dp st accumbuffer ms cav\n");
380 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");
Brian Paul25673f02000-03-31 18:17:51 +0000381 printf("----------------------------------------------------------------------\n");
Brian Paul76bc4402000-01-27 16:43:56 +0000382}
383
384
385static void
386print_visual_attribs_short(const struct visual_attribs *attribs)
387{
Brian Paul25673f02000-03-31 18:17:51 +0000388 char *caveat;
389#ifdef GLX_EXT_visual_rating
390 if (attribs->visualCaveat == GLX_NONE_EXT || attribs->visualCaveat == 0)
391 caveat = "None";
392 else if (attribs->visualCaveat == GLX_SLOW_VISUAL_EXT)
393 caveat = "Slow";
394 else if (attribs->visualCaveat == GLX_NON_CONFORMANT_VISUAL_EXT)
395 caveat = "Ncon";
396#else
397 caveat = "None";
398#endif
399
Brian Paul76bc4402000-01-27 16:43:56 +0000400 printf("0x%2x %2d %2s %2d %2d %2d %1s %2s %2s %2d %2d %2d %2d %2d %2d %2d",
401 attribs->id,
402 attribs->depth,
403 visual_class_abbrev(attribs->klass),
404 attribs->transparent,
405 attribs->bufferSize,
406 attribs->level,
407 attribs->rgba ? "r" : "c",
408 attribs->doubleBuffer ? "y" : ".",
409 attribs->stereo ? "y" : ".",
410 attribs->redSize, attribs->greenSize,
411 attribs->blueSize, attribs->alphaSize,
412 attribs->auxBuffers,
413 attribs->depthSize,
414 attribs->stencilSize
415 );
416
Brian Paul25673f02000-03-31 18:17:51 +0000417 printf(" %2d %2d %2d %2d %2d %1d %s\n",
Brian Paul76bc4402000-01-27 16:43:56 +0000418 attribs->accumRedSize, attribs->accumGreenSize,
419 attribs->accumBlueSize, attribs->accumAlphaSize,
Brian Paul25673f02000-03-31 18:17:51 +0000420 attribs->numSamples, attribs->numMultisample,
421 caveat
Brian Paul76bc4402000-01-27 16:43:56 +0000422 );
423}
424
425
426static void
427print_visual_attribs_long_header(void)
428{
429 printf("Vis Vis Visual Trans buff lev render DB ste r g b a aux dep ste accum buffers MS MS\n");
430 printf(" ID Depth Type parent size el type reo sz sz sz sz buf th ncl r g b a num bufs\n");
431 printf("----------------------------------------------------------------------------------------------------\n");
432}
433
434
435static void
436print_visual_attribs_long(const struct visual_attribs *attribs)
437{
438 printf("0x%2x %2d %-11s %2d %2d %2d %4s %3d %3d %3d %3d %3d %3d",
439 attribs->id,
440 attribs->depth,
441 visual_class_name(attribs->klass),
442 attribs->transparent,
443 attribs->bufferSize,
444 attribs->level,
445 attribs->rgba ? "rgba" : "ci ",
446 attribs->doubleBuffer,
447 attribs->stereo,
448 attribs->redSize, attribs->greenSize,
449 attribs->blueSize, attribs->alphaSize
450 );
451
452 printf(" %3d %4d %2d %3d %3d %3d %3d %2d %2d\n",
453 attribs->auxBuffers,
454 attribs->depthSize,
455 attribs->stencilSize,
456 attribs->accumRedSize, attribs->accumGreenSize,
457 attribs->accumBlueSize, attribs->accumAlphaSize,
458 attribs->numSamples, attribs->numMultisample
459 );
460}
461
462
463static void
464print_visual_info(Display *dpy, int scrnum, InfoMode mode)
465{
466 XVisualInfo template;
467 XVisualInfo *visuals;
468 int numVisuals;
469 long mask;
470 int i;
471
472 /* get list of all visuals on this screen */
473 template.screen = scrnum;
474 mask = VisualScreenMask;
475 visuals = XGetVisualInfo(dpy, mask, &template, &numVisuals);
476
477 if (mode == Verbose) {
478 for (i = 0; i < numVisuals; i++) {
479 struct visual_attribs attribs;
480 get_visual_attribs(dpy, &visuals[i], &attribs);
481 print_visual_attribs_verbose(&attribs);
482 }
483 }
484 else if (mode == Normal) {
485 print_visual_attribs_short_header();
486 for (i = 0; i < numVisuals; i++) {
487 struct visual_attribs attribs;
488 get_visual_attribs(dpy, &visuals[i], &attribs);
489 print_visual_attribs_short(&attribs);
490 }
491 }
492 else if (mode == Wide) {
493 print_visual_attribs_long_header();
494 for (i = 0; i < numVisuals; i++) {
495 struct visual_attribs attribs;
496 get_visual_attribs(dpy, &visuals[i], &attribs);
497 print_visual_attribs_long(&attribs);
498 }
499 }
500
501 XFree(visuals);
502}
503
504
Brian Paul39557c32001-03-23 21:41:44 +0000505/*
506 * Stand-alone Mesa doesn't really implement the GLX protocol so it
507 * doesn't really know the GLX attributes associated with an X visual.
508 * The first time a visual is presented to Mesa's pseudo-GLX it
509 * attaches ancilliary buffers to it (like depth and stencil).
510 * But that usually only works if glXChooseVisual is used.
511 * This function calls glXChooseVisual() to sort of "prime the pump"
512 * for Mesa's GLX so that the visuals that get reported actually
513 * reflect what applications will see.
514 * This has no effect when using true GLX.
515 */
516static void
517mesa_hack(Display *dpy, int scrnum)
518{
519 static int attribs[] = {
520 GLX_RGBA,
521 GLX_RED_SIZE, 1,
522 GLX_GREEN_SIZE, 1,
523 GLX_BLUE_SIZE, 1,
524 GLX_DEPTH_SIZE, 1,
525 GLX_STENCIL_SIZE, 1,
526 GLX_ACCUM_RED_SIZE, 1,
527 GLX_ACCUM_GREEN_SIZE, 1,
528 GLX_ACCUM_BLUE_SIZE, 1,
529 GLX_ACCUM_ALPHA_SIZE, 1,
530 GLX_DOUBLEBUFFER,
531 None
532 };
533 XVisualInfo *visinfo;
534
535 visinfo = glXChooseVisual(dpy, scrnum, attribs);
536 if (visinfo)
537 XFree(visinfo);
538}
539
540
541/*
542 * Examine all visuals to find the so-called best one.
543 * We prefer deepest RGBA buffer with depth, stencil and accum
544 * that has no caveats.
545 */
546static int
547find_best_visual(Display *dpy, int scrnum)
548{
549 XVisualInfo template;
550 XVisualInfo *visuals;
551 int numVisuals;
552 long mask;
553 int i;
554 struct visual_attribs bestVis;
555
556 /* get list of all visuals on this screen */
557 template.screen = scrnum;
558 mask = VisualScreenMask;
559 visuals = XGetVisualInfo(dpy, mask, &template, &numVisuals);
560
561 /* init bestVis with first visual info */
562 get_visual_attribs(dpy, &visuals[0], &bestVis);
563
564 /* try to find a "better" visual */
565 for (i = 1; i < numVisuals; i++) {
566 struct visual_attribs vis;
567
568 get_visual_attribs(dpy, &visuals[i], &vis);
569
570 /* always skip visuals with caveats */
571 if (vis.visualCaveat != GLX_NONE_EXT)
572 continue;
573
574 /* see if this vis is better than bestVis */
575 if ((!bestVis.supportsGL && vis.supportsGL) ||
576 (bestVis.visualCaveat != GLX_NONE_EXT) ||
577 (!bestVis.rgba && vis.rgba) ||
578 (!bestVis.doubleBuffer && vis.doubleBuffer) ||
579 (bestVis.redSize < vis.redSize) ||
580 (bestVis.greenSize < vis.greenSize) ||
581 (bestVis.blueSize < vis.blueSize) ||
582 (bestVis.alphaSize < vis.alphaSize) ||
583 (bestVis.depthSize < vis.depthSize) ||
584 (bestVis.stencilSize < vis.stencilSize) ||
585 (bestVis.accumRedSize < vis.accumRedSize)) {
586 /* found a better visual */
587 bestVis = vis;
588 }
589 }
590
591 XFree(visuals);
592
593 return bestVis.id;
594}
595
596
Brian Paul76bc4402000-01-27 16:43:56 +0000597int
598main(int argc, char *argv[])
599{
Alan Hourihanee18599a2001-03-19 13:58:45 +0000600 char *displayName = NULL;
Brian Paul76bc4402000-01-27 16:43:56 +0000601 Display *dpy;
602 int numScreens, scrnum;
603 InfoMode mode = Normal;
Brian Paul39557c32001-03-23 21:41:44 +0000604 GLboolean findBest = GL_FALSE;
Brian Paul76bc4402000-01-27 16:43:56 +0000605 int i;
606
607 for (i = 1; i < argc; i++) {
608 if (strcmp(argv[i], "-display") == 0 && i + 1 < argc) {
609 displayName = argv[i + 1];
610 i++;
611 }
612 else if (strcmp(argv[i], "-t") == 0) {
613 mode = Wide;
614 }
615 else if (strcmp(argv[i], "-v") == 0) {
616 mode = Verbose;
617 }
Brian Paul39557c32001-03-23 21:41:44 +0000618 else if (strcmp(argv[i], "-b") == 0) {
619 findBest = GL_TRUE;
620 }
Brian Paul76bc4402000-01-27 16:43:56 +0000621 }
622
623 dpy = XOpenDisplay(displayName);
624 if (!dpy) {
625 fprintf(stderr, "Error: unable to open display %s\n", displayName);
626 return -1;
627 }
628
Brian Paul39557c32001-03-23 21:41:44 +0000629 if (findBest) {
630 int b;
631 mesa_hack(dpy, 0);
632 b = find_best_visual(dpy, 0);
633 printf("%d\n", b);
634 }
635 else {
636 numScreens = ScreenCount(dpy);
637 for (scrnum = 0; scrnum < numScreens; scrnum++) {
638 mesa_hack(dpy, scrnum);
639 print_screen_info(dpy, scrnum);
640 printf("\n");
641 print_visual_info(dpy, scrnum, mode);
642 if (scrnum + 1 < numScreens)
643 printf("\n\n");
644 }
Brian Paul76bc4402000-01-27 16:43:56 +0000645 }
646
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000647 XCloseDisplay(dpy);
648
649 return 0;
650}