Merge branch '7.8' into master
[mesa.git] / progs / xdemos / glxinfo.c
1 /*
2 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 */
21
22
23 /*
24 * This program is a work-alike of the IRIX glxinfo program.
25 * Command line options:
26 * -t print wide table
27 * -v print verbose information
28 * -display DisplayName specify the X display to interogate
29 * -b only print ID of "best" visual on screen 0
30 * -i use indirect rendering connection only
31 * -l print interesting OpenGL limits (added 5 Sep 2002)
32 *
33 * Brian Paul 26 January 2000
34 */
35
36 #define GLX_GLXEXT_PROTOTYPES
37
38 #include <X11/Xlib.h>
39 #include <X11/Xutil.h>
40 #include <GL/gl.h>
41 #include <GL/glx.h>
42 #include <stdio.h>
43 #include <string.h>
44 #include <stdlib.h>
45
46
47 #ifndef GLX_NONE_EXT
48 #define GLX_NONE_EXT 0x8000
49 #endif
50
51 #ifndef GLX_TRANSPARENT_RGB
52 #define GLX_TRANSPARENT_RGB 0x8008
53 #endif
54
55 #ifndef GLX_RGBA_BIT
56 #define GLX_RGBA_BIT 0x00000001
57 #endif
58
59 #ifndef GLX_COLOR_INDEX_BIT
60 #define GLX_COLOR_INDEX_BIT 0x00000002
61 #endif
62
63 typedef enum
64 {
65 Normal,
66 Wide,
67 Verbose
68 } InfoMode;
69
70
71 struct visual_attribs
72 {
73 /* X visual attribs */
74 int id;
75 int klass;
76 int depth;
77 int redMask, greenMask, blueMask;
78 int colormapSize;
79 int bitsPerRGB;
80
81 /* GL visual attribs */
82 int supportsGL;
83 int transparentType;
84 int transparentRedValue;
85 int transparentGreenValue;
86 int transparentBlueValue;
87 int transparentAlphaValue;
88 int transparentIndexValue;
89 int bufferSize;
90 int level;
91 int render_type;
92 int doubleBuffer;
93 int stereo;
94 int auxBuffers;
95 int redSize, greenSize, blueSize, alphaSize;
96 int depthSize;
97 int stencilSize;
98 int accumRedSize, accumGreenSize, accumBlueSize, accumAlphaSize;
99 int numSamples, numMultisample;
100 int visualCaveat;
101 };
102
103
104 /*
105 * Print a list of extensions, with word-wrapping.
106 */
107 static void
108 print_extension_list(const char *ext)
109 {
110 const char *indentString = " ";
111 const int indent = 4;
112 const int max = 79;
113 int width, i, j;
114
115 if (!ext || !ext[0])
116 return;
117
118 width = indent;
119 printf("%s", indentString);
120 i = j = 0;
121 while (1) {
122 if (ext[j] == ' ' || ext[j] == 0) {
123 /* found end of an extension name */
124 const int len = j - i;
125 if (width + len > max) {
126 /* start a new line */
127 printf("\n");
128 width = indent;
129 printf("%s", indentString);
130 }
131 /* print the extension name between ext[i] and ext[j] */
132 while (i < j) {
133 printf("%c", ext[i]);
134 i++;
135 }
136 /* either we're all done, or we'll continue with next extension */
137 width += len + 1;
138 if (ext[j] == 0) {
139 break;
140 }
141 else {
142 i++;
143 j++;
144 if (ext[j] == 0)
145 break;
146 printf(", ");
147 width += 2;
148 }
149 }
150 j++;
151 }
152 printf("\n");
153 }
154
155
156 static void
157 print_display_info(Display *dpy)
158 {
159 printf("name of display: %s\n", DisplayString(dpy));
160 }
161
162
163 /**
164 * Print interesting limits for vertex/fragment programs.
165 */
166 static void
167 print_program_limits(GLenum target)
168 {
169 #if defined(GL_ARB_vertex_program) || defined(GL_ARB_fragment_program)
170 struct token_name {
171 GLenum token;
172 const char *name;
173 };
174 static const struct token_name common_limits[] = {
175 { GL_MAX_PROGRAM_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_INSTRUCTIONS_ARB" },
176 { GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB" },
177 { GL_MAX_PROGRAM_TEMPORARIES_ARB, "GL_MAX_PROGRAM_TEMPORARIES_ARB" },
178 { GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB, "GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB" },
179 { GL_MAX_PROGRAM_PARAMETERS_ARB, "GL_MAX_PROGRAM_PARAMETERS_ARB" },
180 { GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB, "GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB" },
181 { GL_MAX_PROGRAM_ATTRIBS_ARB, "GL_MAX_PROGRAM_ATTRIBS_ARB" },
182 { GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB, "GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB" },
183 { GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB, "GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB" },
184 { GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB, "GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB" },
185 { GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB, "GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB" },
186 { GL_MAX_PROGRAM_ENV_PARAMETERS_ARB, "GL_MAX_PROGRAM_ENV_PARAMETERS_ARB" },
187 { (GLenum) 0, NULL }
188 };
189 static const struct token_name fragment_limits[] = {
190 { GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB" },
191 { GL_MAX_PROGRAM_TEX_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_TEX_INSTRUCTIONS_ARB" },
192 { GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB, "GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB" },
193 { GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB" },
194 { GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB" },
195 { GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB, "GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB" },
196 { (GLenum) 0, NULL }
197 };
198
199 PFNGLGETPROGRAMIVARBPROC GetProgramivARB_func = (PFNGLGETPROGRAMIVARBPROC)
200 glXGetProcAddressARB((GLubyte *) "glGetProgramivARB");
201
202 GLint max[1];
203 int i;
204
205 if (target == GL_VERTEX_PROGRAM_ARB) {
206 printf(" GL_VERTEX_PROGRAM_ARB:\n");
207 }
208 else if (target == GL_FRAGMENT_PROGRAM_ARB) {
209 printf(" GL_FRAGMENT_PROGRAM_ARB:\n");
210 }
211 else {
212 return; /* something's wrong */
213 }
214
215 for (i = 0; common_limits[i].token; i++) {
216 GetProgramivARB_func(target, common_limits[i].token, max);
217 if (glGetError() == GL_NO_ERROR) {
218 printf(" %s = %d\n", common_limits[i].name, max[0]);
219 }
220 }
221 if (target == GL_FRAGMENT_PROGRAM_ARB) {
222 for (i = 0; fragment_limits[i].token; i++) {
223 GetProgramivARB_func(target, fragment_limits[i].token, max);
224 if (glGetError() == GL_NO_ERROR) {
225 printf(" %s = %d\n", fragment_limits[i].name, max[0]);
226 }
227 }
228 }
229 #endif /* GL_ARB_vertex_program / GL_ARB_fragment_program */
230 }
231
232
233 /**
234 * Print interesting limits for vertex/fragment shaders.
235 */
236 static void
237 print_shader_limits(GLenum target)
238 {
239 struct token_name {
240 GLenum token;
241 const char *name;
242 };
243 #if defined(GL_ARB_vertex_shader)
244 static const struct token_name vertex_limits[] = {
245 { GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB, "GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB" },
246 { GL_MAX_VARYING_FLOATS_ARB, "GL_MAX_VARYING_FLOATS_ARB" },
247 { GL_MAX_VERTEX_ATTRIBS_ARB, "GL_MAX_VERTEX_ATTRIBS_ARB" },
248 { GL_MAX_TEXTURE_IMAGE_UNITS_ARB, "GL_MAX_TEXTURE_IMAGE_UNITS_ARB" },
249 { GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB, "GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB" },
250 { GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB, "GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB" },
251 { GL_MAX_TEXTURE_COORDS_ARB, "GL_MAX_TEXTURE_COORDS_ARB" },
252 { (GLenum) 0, NULL }
253 };
254 #endif
255 #if defined(GL_ARB_fragment_shader)
256 static const struct token_name fragment_limits[] = {
257 { GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB, "GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB" },
258 { GL_MAX_TEXTURE_COORDS_ARB, "GL_MAX_TEXTURE_COORDS_ARB" },
259 { GL_MAX_TEXTURE_IMAGE_UNITS_ARB, "GL_MAX_TEXTURE_IMAGE_UNITS_ARB" },
260 { (GLenum) 0, NULL }
261 };
262 #endif
263 GLint max[1];
264 int i;
265
266 #if defined(GL_ARB_vertex_shader)
267 if (target == GL_VERTEX_SHADER_ARB) {
268 printf(" GL_VERTEX_SHADER_ARB:\n");
269 for (i = 0; vertex_limits[i].token; i++) {
270 glGetIntegerv(vertex_limits[i].token, max);
271 if (glGetError() == GL_NO_ERROR) {
272 printf(" %s = %d\n", vertex_limits[i].name, max[0]);
273 }
274 }
275 }
276 #endif
277 #if defined(GL_ARB_fragment_shader)
278 if (target == GL_FRAGMENT_SHADER_ARB) {
279 printf(" GL_FRAGMENT_SHADER_ARB:\n");
280 for (i = 0; fragment_limits[i].token; i++) {
281 glGetIntegerv(fragment_limits[i].token, max);
282 if (glGetError() == GL_NO_ERROR) {
283 printf(" %s = %d\n", fragment_limits[i].name, max[0]);
284 }
285 }
286 }
287 #endif
288 }
289
290
291 /**
292 * Print interesting OpenGL implementation limits.
293 */
294 static void
295 print_limits(const char *extensions)
296 {
297 struct token_name {
298 GLuint count;
299 GLenum token;
300 const char *name;
301 };
302 static const struct token_name limits[] = {
303 { 1, GL_MAX_ATTRIB_STACK_DEPTH, "GL_MAX_ATTRIB_STACK_DEPTH" },
304 { 1, GL_MAX_CLIENT_ATTRIB_STACK_DEPTH, "GL_MAX_CLIENT_ATTRIB_STACK_DEPTH" },
305 { 1, GL_MAX_CLIP_PLANES, "GL_MAX_CLIP_PLANES" },
306 { 1, GL_MAX_COLOR_MATRIX_STACK_DEPTH, "GL_MAX_COLOR_MATRIX_STACK_DEPTH" },
307 { 1, GL_MAX_ELEMENTS_VERTICES, "GL_MAX_ELEMENTS_VERTICES" },
308 { 1, GL_MAX_ELEMENTS_INDICES, "GL_MAX_ELEMENTS_INDICES" },
309 { 1, GL_MAX_EVAL_ORDER, "GL_MAX_EVAL_ORDER" },
310 { 1, GL_MAX_LIGHTS, "GL_MAX_LIGHTS" },
311 { 1, GL_MAX_LIST_NESTING, "GL_MAX_LIST_NESTING" },
312 { 1, GL_MAX_MODELVIEW_STACK_DEPTH, "GL_MAX_MODELVIEW_STACK_DEPTH" },
313 { 1, GL_MAX_NAME_STACK_DEPTH, "GL_MAX_NAME_STACK_DEPTH" },
314 { 1, GL_MAX_PIXEL_MAP_TABLE, "GL_MAX_PIXEL_MAP_TABLE" },
315 { 1, GL_MAX_PROJECTION_STACK_DEPTH, "GL_MAX_PROJECTION_STACK_DEPTH" },
316 { 1, GL_MAX_TEXTURE_STACK_DEPTH, "GL_MAX_TEXTURE_STACK_DEPTH" },
317 { 1, GL_MAX_TEXTURE_SIZE, "GL_MAX_TEXTURE_SIZE" },
318 { 1, GL_MAX_3D_TEXTURE_SIZE, "GL_MAX_3D_TEXTURE_SIZE" },
319 { 2, GL_MAX_VIEWPORT_DIMS, "GL_MAX_VIEWPORT_DIMS" },
320 { 2, GL_ALIASED_LINE_WIDTH_RANGE, "GL_ALIASED_LINE_WIDTH_RANGE" },
321 { 2, GL_SMOOTH_LINE_WIDTH_RANGE, "GL_SMOOTH_LINE_WIDTH_RANGE" },
322 { 2, GL_ALIASED_POINT_SIZE_RANGE, "GL_ALIASED_POINT_SIZE_RANGE" },
323 { 2, GL_SMOOTH_POINT_SIZE_RANGE, "GL_SMOOTH_POINT_SIZE_RANGE" },
324 #if defined(GL_ARB_texture_cube_map)
325 { 1, GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB, "GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB" },
326 #endif
327 #if defined(GLX_NV_texture_rectangle)
328 { 1, GL_MAX_RECTANGLE_TEXTURE_SIZE_NV, "GL_MAX_RECTANGLE_TEXTURE_SIZE_NV" },
329 #endif
330 #if defined(GL_ARB_texture_compression)
331 { 1, GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB, "GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB" },
332 #endif
333 #if defined(GL_ARB_multitexture)
334 { 1, GL_MAX_TEXTURE_UNITS_ARB, "GL_MAX_TEXTURE_UNITS_ARB" },
335 #endif
336 #if defined(GL_EXT_texture_lod_bias)
337 { 1, GL_MAX_TEXTURE_LOD_BIAS_EXT, "GL_MAX_TEXTURE_LOD_BIAS_EXT" },
338 #endif
339 #if defined(GL_EXT_texture_filter_anisotropic)
340 { 1, GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, "GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT" },
341 #endif
342 #if defined(GL_ARB_draw_buffers)
343 { 1, GL_MAX_DRAW_BUFFERS_ARB, "GL_MAX_DRAW_BUFFERS_ARB" },
344 #endif
345 { 0, (GLenum) 0, NULL }
346 };
347 GLint i, max[2];
348
349 printf("OpenGL limits:\n");
350 for (i = 0; limits[i].count; i++) {
351 glGetIntegerv(limits[i].token, max);
352 if (glGetError() == GL_NO_ERROR) {
353 if (limits[i].count == 1)
354 printf(" %s = %d\n", limits[i].name, max[0]);
355 else /* XXX fix if we ever query something with more than 2 values */
356 printf(" %s = %d, %d\n", limits[i].name, max[0], max[1]);
357 }
358 }
359
360 /* these don't fit into the above mechanism, unfortunately */
361 glGetConvolutionParameteriv(GL_CONVOLUTION_2D, GL_MAX_CONVOLUTION_WIDTH, max);
362 glGetConvolutionParameteriv(GL_CONVOLUTION_2D, GL_MAX_CONVOLUTION_HEIGHT, max+1);
363 if (glGetError() == GL_NONE) {
364 printf(" GL_MAX_CONVOLUTION_WIDTH/HEIGHT = %d, %d\n", max[0], max[1]);
365 }
366
367 #if defined(GL_ARB_vertex_program)
368 if (strstr(extensions, "GL_ARB_vertex_program")) {
369 print_program_limits(GL_VERTEX_PROGRAM_ARB);
370 }
371 #endif
372 #if defined(GL_ARB_fragment_program)
373 if (strstr(extensions, "GL_ARB_fragment_program")) {
374 print_program_limits(GL_FRAGMENT_PROGRAM_ARB);
375 }
376 #endif
377 #if defined(GL_ARB_vertex_shader)
378 if (strstr(extensions, "GL_ARB_vertex_shader")) {
379 print_shader_limits(GL_VERTEX_SHADER_ARB);
380 }
381 #endif
382 #if defined(GL_ARB_fragment_shader)
383 if (strstr(extensions, "GL_ARB_fragment_shader")) {
384 print_shader_limits(GL_FRAGMENT_SHADER_ARB);
385 }
386 #endif
387 }
388
389
390 static void
391 print_screen_info(Display *dpy, int scrnum, Bool allowDirect, GLboolean limits)
392 {
393 Window win;
394 int attribSingle[] = {
395 GLX_RGBA,
396 GLX_RED_SIZE, 1,
397 GLX_GREEN_SIZE, 1,
398 GLX_BLUE_SIZE, 1,
399 None };
400 int attribDouble[] = {
401 GLX_RGBA,
402 GLX_RED_SIZE, 1,
403 GLX_GREEN_SIZE, 1,
404 GLX_BLUE_SIZE, 1,
405 GLX_DOUBLEBUFFER,
406 None };
407
408 XSetWindowAttributes attr;
409 unsigned long mask;
410 Window root;
411 GLXContext ctx = NULL;
412 XVisualInfo *visinfo;
413 int width = 100, height = 100;
414
415 root = RootWindow(dpy, scrnum);
416
417 /*
418 * Find a basic GLX visual. We'll then create a rendering context and
419 * query various info strings.
420 */
421 visinfo = glXChooseVisual(dpy, scrnum, attribSingle);
422 if (!visinfo)
423 visinfo = glXChooseVisual(dpy, scrnum, attribDouble);
424
425 if (visinfo)
426 ctx = glXCreateContext( dpy, visinfo, NULL, allowDirect );
427
428 #ifdef GLX_VERSION_1_3
429 /* Try glXChooseFBConfig() if glXChooseVisual didn't work.
430 * XXX when would that happen?
431 */
432 if (!visinfo) {
433 int fbAttribSingle[] = {
434 GLX_RENDER_TYPE, GLX_RGBA_BIT,
435 GLX_RED_SIZE, 1,
436 GLX_GREEN_SIZE, 1,
437 GLX_BLUE_SIZE, 1,
438 GLX_DOUBLEBUFFER, GL_FALSE,
439 None };
440 int fbAttribDouble[] = {
441 GLX_RENDER_TYPE, GLX_RGBA_BIT,
442 GLX_RED_SIZE, 1,
443 GLX_GREEN_SIZE, 1,
444 GLX_BLUE_SIZE, 1,
445 GLX_DOUBLEBUFFER, GL_TRUE,
446 None };
447 GLXFBConfig *configs = NULL;
448 int nConfigs;
449
450 configs = glXChooseFBConfig(dpy, scrnum, fbAttribSingle, &nConfigs);
451 if (!configs)
452 configs = glXChooseFBConfig(dpy, scrnum, fbAttribDouble, &nConfigs);
453
454 if (configs) {
455 visinfo = glXGetVisualFromFBConfig(dpy, configs[0]);
456 ctx = glXCreateNewContext(dpy, configs[0], GLX_RGBA_TYPE, NULL, allowDirect);
457 XFree(configs);
458 }
459 }
460 #endif
461
462 if (!visinfo) {
463 fprintf(stderr, "Error: couldn't find RGB GLX visual or fbconfig\n");
464 return;
465 }
466
467 if (!ctx) {
468 fprintf(stderr, "Error: glXCreateContext failed\n");
469 XFree(visinfo);
470 return;
471 }
472
473 attr.background_pixel = 0;
474 attr.border_pixel = 0;
475 attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone);
476 attr.event_mask = StructureNotifyMask | ExposureMask;
477 mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
478 win = XCreateWindow(dpy, root, 0, 0, width, height,
479 0, visinfo->depth, InputOutput,
480 visinfo->visual, mask, &attr);
481
482 if (glXMakeCurrent(dpy, win, ctx)) {
483 const char *serverVendor = glXQueryServerString(dpy, scrnum, GLX_VENDOR);
484 const char *serverVersion = glXQueryServerString(dpy, scrnum, GLX_VERSION);
485 const char *serverExtensions = glXQueryServerString(dpy, scrnum, GLX_EXTENSIONS);
486 const char *clientVendor = glXGetClientString(dpy, GLX_VENDOR);
487 const char *clientVersion = glXGetClientString(dpy, GLX_VERSION);
488 const char *clientExtensions = glXGetClientString(dpy, GLX_EXTENSIONS);
489 const char *glxExtensions = glXQueryExtensionsString(dpy, scrnum);
490 const char *glVendor = (const char *) glGetString(GL_VENDOR);
491 const char *glRenderer = (const char *) glGetString(GL_RENDERER);
492 const char *glVersion = (const char *) glGetString(GL_VERSION);
493 const char *glExtensions = (const char *) glGetString(GL_EXTENSIONS);
494 int glxVersionMajor;
495 int glxVersionMinor;
496 char *displayName = NULL;
497 char *colon = NULL, *period = NULL;
498
499 if (! glXQueryVersion( dpy, & glxVersionMajor, & glxVersionMinor )) {
500 fprintf(stderr, "Error: glXQueryVersion failed\n");
501 exit(1);
502 }
503
504 /* Strip the screen number from the display name, if present. */
505 if (!(displayName = (char *) malloc(strlen(DisplayString(dpy)) + 1))) {
506 fprintf(stderr, "Error: malloc() failed\n");
507 exit(1);
508 }
509 strcpy(displayName, DisplayString(dpy));
510 colon = strrchr(displayName, ':');
511 if (colon) {
512 period = strchr(colon, '.');
513 if (period)
514 *period = '\0';
515 }
516 printf("display: %s screen: %d\n", displayName, scrnum);
517 free(displayName);
518 printf("direct rendering: ");
519 if (glXIsDirect(dpy, ctx)) {
520 printf("Yes\n");
521 } else {
522 if (!allowDirect) {
523 printf("No (-i specified)\n");
524 } else if (getenv("LIBGL_ALWAYS_INDIRECT")) {
525 printf("No (LIBGL_ALWAYS_INDIRECT set)\n");
526 } else {
527 printf("No (If you want to find out why, try setting "
528 "LIBGL_DEBUG=verbose)\n");
529 }
530 }
531 printf("server glx vendor string: %s\n", serverVendor);
532 printf("server glx version string: %s\n", serverVersion);
533 printf("server glx extensions:\n");
534 print_extension_list(serverExtensions);
535 printf("client glx vendor string: %s\n", clientVendor);
536 printf("client glx version string: %s\n", clientVersion);
537 printf("client glx extensions:\n");
538 print_extension_list(clientExtensions);
539 printf("GLX version: %u.%u\n", glxVersionMajor, glxVersionMinor);
540 printf("GLX extensions:\n");
541 print_extension_list(glxExtensions);
542 printf("OpenGL vendor string: %s\n", glVendor);
543 printf("OpenGL renderer string: %s\n", glRenderer);
544 printf("OpenGL version string: %s\n", glVersion);
545 #ifdef GL_VERSION_2_0
546 if (glVersion[0] >= '2' && glVersion[1] == '.') {
547 char *v = (char *) glGetString(GL_SHADING_LANGUAGE_VERSION);
548 printf("OpenGL shading language version string: %s\n", v);
549 }
550 #endif
551
552 printf("OpenGL extensions:\n");
553 print_extension_list(glExtensions);
554 if (limits)
555 print_limits(glExtensions);
556 }
557 else {
558 fprintf(stderr, "Error: glXMakeCurrent failed\n");
559 }
560
561 glXDestroyContext(dpy, ctx);
562 XFree(visinfo);
563 XDestroyWindow(dpy, win);
564 }
565
566
567 static const char *
568 visual_class_name(int cls)
569 {
570 switch (cls) {
571 case StaticColor:
572 return "StaticColor";
573 case PseudoColor:
574 return "PseudoColor";
575 case StaticGray:
576 return "StaticGray";
577 case GrayScale:
578 return "GrayScale";
579 case TrueColor:
580 return "TrueColor";
581 case DirectColor:
582 return "DirectColor";
583 default:
584 return "";
585 }
586 }
587
588
589 static const char *
590 visual_class_abbrev(int cls)
591 {
592 switch (cls) {
593 case StaticColor:
594 return "sc";
595 case PseudoColor:
596 return "pc";
597 case StaticGray:
598 return "sg";
599 case GrayScale:
600 return "gs";
601 case TrueColor:
602 return "tc";
603 case DirectColor:
604 return "dc";
605 default:
606 return "";
607 }
608 }
609
610 static const char *
611 visual_render_type_name(int type)
612 {
613 switch (type) {
614 case GLX_RGBA_BIT:
615 return "rgba";
616 case GLX_COLOR_INDEX_BIT:
617 return "ci";
618 case GLX_RGBA_BIT | GLX_COLOR_INDEX_BIT:
619 return "rgba|ci";
620 default:
621 return "";
622 }
623 }
624
625 static GLboolean
626 get_visual_attribs(Display *dpy, XVisualInfo *vInfo,
627 struct visual_attribs *attribs)
628 {
629 const char *ext = glXQueryExtensionsString(dpy, vInfo->screen);
630 int rgba;
631
632 memset(attribs, 0, sizeof(struct visual_attribs));
633
634 attribs->id = vInfo->visualid;
635 #if defined(__cplusplus) || defined(c_plusplus)
636 attribs->klass = vInfo->c_class;
637 #else
638 attribs->klass = vInfo->class;
639 #endif
640 attribs->depth = vInfo->depth;
641 attribs->redMask = vInfo->red_mask;
642 attribs->greenMask = vInfo->green_mask;
643 attribs->blueMask = vInfo->blue_mask;
644 attribs->colormapSize = vInfo->colormap_size;
645 attribs->bitsPerRGB = vInfo->bits_per_rgb;
646
647 if (glXGetConfig(dpy, vInfo, GLX_USE_GL, &attribs->supportsGL) != 0 ||
648 !attribs->supportsGL)
649 return GL_FALSE;
650 glXGetConfig(dpy, vInfo, GLX_BUFFER_SIZE, &attribs->bufferSize);
651 glXGetConfig(dpy, vInfo, GLX_LEVEL, &attribs->level);
652 glXGetConfig(dpy, vInfo, GLX_RGBA, &rgba);
653 if (rgba)
654 attribs->render_type = GLX_RGBA_BIT;
655 else
656 attribs->render_type = GLX_COLOR_INDEX_BIT;
657
658 glXGetConfig(dpy, vInfo, GLX_DOUBLEBUFFER, &attribs->doubleBuffer);
659 glXGetConfig(dpy, vInfo, GLX_STEREO, &attribs->stereo);
660 glXGetConfig(dpy, vInfo, GLX_AUX_BUFFERS, &attribs->auxBuffers);
661 glXGetConfig(dpy, vInfo, GLX_RED_SIZE, &attribs->redSize);
662 glXGetConfig(dpy, vInfo, GLX_GREEN_SIZE, &attribs->greenSize);
663 glXGetConfig(dpy, vInfo, GLX_BLUE_SIZE, &attribs->blueSize);
664 glXGetConfig(dpy, vInfo, GLX_ALPHA_SIZE, &attribs->alphaSize);
665 glXGetConfig(dpy, vInfo, GLX_DEPTH_SIZE, &attribs->depthSize);
666 glXGetConfig(dpy, vInfo, GLX_STENCIL_SIZE, &attribs->stencilSize);
667 glXGetConfig(dpy, vInfo, GLX_ACCUM_RED_SIZE, &attribs->accumRedSize);
668 glXGetConfig(dpy, vInfo, GLX_ACCUM_GREEN_SIZE, &attribs->accumGreenSize);
669 glXGetConfig(dpy, vInfo, GLX_ACCUM_BLUE_SIZE, &attribs->accumBlueSize);
670 glXGetConfig(dpy, vInfo, GLX_ACCUM_ALPHA_SIZE, &attribs->accumAlphaSize);
671
672 /* get transparent pixel stuff */
673 glXGetConfig(dpy, vInfo,GLX_TRANSPARENT_TYPE, &attribs->transparentType);
674 if (attribs->transparentType == GLX_TRANSPARENT_RGB) {
675 glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_RED_VALUE, &attribs->transparentRedValue);
676 glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_GREEN_VALUE, &attribs->transparentGreenValue);
677 glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_BLUE_VALUE, &attribs->transparentBlueValue);
678 glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_ALPHA_VALUE, &attribs->transparentAlphaValue);
679 }
680 else if (attribs->transparentType == GLX_TRANSPARENT_INDEX) {
681 glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_INDEX_VALUE, &attribs->transparentIndexValue);
682 }
683
684 /* multisample attribs */
685 #ifdef GLX_ARB_multisample
686 if (ext && strstr(ext, "GLX_ARB_multisample")) {
687 glXGetConfig(dpy, vInfo, GLX_SAMPLE_BUFFERS_ARB, &attribs->numMultisample);
688 glXGetConfig(dpy, vInfo, GLX_SAMPLES_ARB, &attribs->numSamples);
689 }
690 #endif
691 else {
692 attribs->numSamples = 0;
693 attribs->numMultisample = 0;
694 }
695
696 #if defined(GLX_EXT_visual_rating)
697 if (ext && strstr(ext, "GLX_EXT_visual_rating")) {
698 glXGetConfig(dpy, vInfo, GLX_VISUAL_CAVEAT_EXT, &attribs->visualCaveat);
699 }
700 else {
701 attribs->visualCaveat = GLX_NONE_EXT;
702 }
703 #else
704 attribs->visualCaveat = 0;
705 #endif
706
707 return GL_TRUE;
708 }
709
710 #ifdef GLX_VERSION_1_3
711
712 static int
713 glx_token_to_visual_class(int visual_type)
714 {
715 switch (visual_type) {
716 case GLX_TRUE_COLOR:
717 return TrueColor;
718 case GLX_DIRECT_COLOR:
719 return DirectColor;
720 case GLX_PSEUDO_COLOR:
721 return PseudoColor;
722 case GLX_STATIC_COLOR:
723 return StaticColor;
724 case GLX_GRAY_SCALE:
725 return GrayScale;
726 case GLX_STATIC_GRAY:
727 return StaticGray;
728 case GLX_NONE:
729 default:
730 return None;
731 }
732 }
733
734 static GLboolean
735 get_fbconfig_attribs(Display *dpy, GLXFBConfig fbconfig,
736 struct visual_attribs *attribs)
737 {
738 int visual_type;
739
740 memset(attribs, 0, sizeof(struct visual_attribs));
741
742 glXGetFBConfigAttrib(dpy, fbconfig, GLX_FBCONFIG_ID, &attribs->id);
743
744 #if 0
745 attribs->depth = vInfo->depth;
746 attribs->redMask = vInfo->red_mask;
747 attribs->greenMask = vInfo->green_mask;
748 attribs->blueMask = vInfo->blue_mask;
749 attribs->colormapSize = vInfo->colormap_size;
750 attribs->bitsPerRGB = vInfo->bits_per_rgb;
751 #endif
752
753 glXGetFBConfigAttrib(dpy, fbconfig, GLX_X_VISUAL_TYPE, &visual_type);
754 attribs->klass = glx_token_to_visual_class(visual_type);
755
756 glXGetFBConfigAttrib(dpy, fbconfig, GLX_BUFFER_SIZE, &attribs->bufferSize);
757 glXGetFBConfigAttrib(dpy, fbconfig, GLX_LEVEL, &attribs->level);
758 glXGetFBConfigAttrib(dpy, fbconfig, GLX_RENDER_TYPE, &attribs->render_type);
759 glXGetFBConfigAttrib(dpy, fbconfig, GLX_DOUBLEBUFFER, &attribs->doubleBuffer);
760 glXGetFBConfigAttrib(dpy, fbconfig, GLX_STEREO, &attribs->stereo);
761 glXGetFBConfigAttrib(dpy, fbconfig, GLX_AUX_BUFFERS, &attribs->auxBuffers);
762
763 glXGetFBConfigAttrib(dpy, fbconfig, GLX_RED_SIZE, &attribs->redSize);
764 glXGetFBConfigAttrib(dpy, fbconfig, GLX_GREEN_SIZE, &attribs->greenSize);
765 glXGetFBConfigAttrib(dpy, fbconfig, GLX_BLUE_SIZE, &attribs->blueSize);
766 glXGetFBConfigAttrib(dpy, fbconfig, GLX_ALPHA_SIZE, &attribs->alphaSize);
767 glXGetFBConfigAttrib(dpy, fbconfig, GLX_DEPTH_SIZE, &attribs->depthSize);
768 glXGetFBConfigAttrib(dpy, fbconfig, GLX_STENCIL_SIZE, &attribs->stencilSize);
769
770 glXGetFBConfigAttrib(dpy, fbconfig, GLX_ACCUM_RED_SIZE, &attribs->accumRedSize);
771 glXGetFBConfigAttrib(dpy, fbconfig, GLX_ACCUM_GREEN_SIZE, &attribs->accumGreenSize);
772 glXGetFBConfigAttrib(dpy, fbconfig, GLX_ACCUM_BLUE_SIZE, &attribs->accumBlueSize);
773 glXGetFBConfigAttrib(dpy, fbconfig, GLX_ACCUM_ALPHA_SIZE, &attribs->accumAlphaSize);
774
775 /* get transparent pixel stuff */
776 glXGetFBConfigAttrib(dpy, fbconfig,GLX_TRANSPARENT_TYPE, &attribs->transparentType);
777 if (attribs->transparentType == GLX_TRANSPARENT_RGB) {
778 glXGetFBConfigAttrib(dpy, fbconfig, GLX_TRANSPARENT_RED_VALUE, &attribs->transparentRedValue);
779 glXGetFBConfigAttrib(dpy, fbconfig, GLX_TRANSPARENT_GREEN_VALUE, &attribs->transparentGreenValue);
780 glXGetFBConfigAttrib(dpy, fbconfig, GLX_TRANSPARENT_BLUE_VALUE, &attribs->transparentBlueValue);
781 glXGetFBConfigAttrib(dpy, fbconfig, GLX_TRANSPARENT_ALPHA_VALUE, &attribs->transparentAlphaValue);
782 }
783 else if (attribs->transparentType == GLX_TRANSPARENT_INDEX) {
784 glXGetFBConfigAttrib(dpy, fbconfig, GLX_TRANSPARENT_INDEX_VALUE, &attribs->transparentIndexValue);
785 }
786
787 glXGetFBConfigAttrib(dpy, fbconfig, GLX_SAMPLE_BUFFERS, &attribs->numMultisample);
788 glXGetFBConfigAttrib(dpy, fbconfig, GLX_SAMPLES, &attribs->numSamples);
789 glXGetFBConfigAttrib(dpy, fbconfig, GLX_CONFIG_CAVEAT, &attribs->visualCaveat);
790
791 return GL_TRUE;
792 }
793
794 #endif
795
796
797
798 static void
799 print_visual_attribs_verbose(const struct visual_attribs *attribs)
800 {
801 printf("Visual ID: %x depth=%d class=%s\n",
802 attribs->id, attribs->depth, visual_class_name(attribs->klass));
803 printf(" bufferSize=%d level=%d renderType=%s doubleBuffer=%d stereo=%d\n",
804 attribs->bufferSize, attribs->level,
805 visual_render_type_name(attribs->render_type),
806 attribs->doubleBuffer, attribs->stereo);
807 printf(" rgba: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n",
808 attribs->redSize, attribs->greenSize,
809 attribs->blueSize, attribs->alphaSize);
810 printf(" auxBuffers=%d depthSize=%d stencilSize=%d\n",
811 attribs->auxBuffers, attribs->depthSize, attribs->stencilSize);
812 printf(" accum: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n",
813 attribs->accumRedSize, attribs->accumGreenSize,
814 attribs->accumBlueSize, attribs->accumAlphaSize);
815 printf(" multiSample=%d multiSampleBuffers=%d\n",
816 attribs->numSamples, attribs->numMultisample);
817 #ifdef GLX_EXT_visual_rating
818 if (attribs->visualCaveat == GLX_NONE_EXT || attribs->visualCaveat == 0)
819 printf(" visualCaveat=None\n");
820 else if (attribs->visualCaveat == GLX_SLOW_VISUAL_EXT)
821 printf(" visualCaveat=Slow\n");
822 else if (attribs->visualCaveat == GLX_NON_CONFORMANT_VISUAL_EXT)
823 printf(" visualCaveat=Nonconformant\n");
824 #endif
825 if (attribs->transparentType == GLX_NONE) {
826 printf(" Opaque.\n");
827 }
828 else if (attribs->transparentType == GLX_TRANSPARENT_RGB) {
829 printf(" Transparent RGB: Red=%d Green=%d Blue=%d Alpha=%d\n",attribs->transparentRedValue,attribs->transparentGreenValue,attribs->transparentBlueValue,attribs->transparentAlphaValue);
830 }
831 else if (attribs->transparentType == GLX_TRANSPARENT_INDEX) {
832 printf(" Transparent index=%d\n",attribs->transparentIndexValue);
833 }
834 }
835
836
837 static void
838 print_visual_attribs_short_header(void)
839 {
840 printf(" visual x bf lv rg d st colorbuffer ax dp st accumbuffer ms cav\n");
841 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");
842 printf("----------------------------------------------------------------------\n");
843 }
844
845
846 static void
847 print_visual_attribs_short(const struct visual_attribs *attribs)
848 {
849 char *caveat = NULL;
850 #ifdef GLX_EXT_visual_rating
851 if (attribs->visualCaveat == GLX_NONE_EXT || attribs->visualCaveat == 0)
852 caveat = "None";
853 else if (attribs->visualCaveat == GLX_SLOW_VISUAL_EXT)
854 caveat = "Slow";
855 else if (attribs->visualCaveat == GLX_NON_CONFORMANT_VISUAL_EXT)
856 caveat = "Ncon";
857 else
858 caveat = "None";
859 #else
860 caveat = "None";
861 #endif
862
863 printf("0x%02x %2d %2s %2d %2d %2d %c%c %c %c %2d %2d %2d %2d %2d %2d %2d",
864 attribs->id,
865 attribs->depth,
866 visual_class_abbrev(attribs->klass),
867 attribs->transparentType != GLX_NONE,
868 attribs->bufferSize,
869 attribs->level,
870 (attribs->render_type & GLX_RGBA_BIT) ? 'r' : ' ',
871 (attribs->render_type & GLX_COLOR_INDEX_BIT) ? 'c' : ' ',
872 attribs->doubleBuffer ? 'y' : '.',
873 attribs->stereo ? 'y' : '.',
874 attribs->redSize, attribs->greenSize,
875 attribs->blueSize, attribs->alphaSize,
876 attribs->auxBuffers,
877 attribs->depthSize,
878 attribs->stencilSize
879 );
880
881 printf(" %2d %2d %2d %2d %2d %1d %s\n",
882 attribs->accumRedSize, attribs->accumGreenSize,
883 attribs->accumBlueSize, attribs->accumAlphaSize,
884 attribs->numSamples, attribs->numMultisample,
885 caveat
886 );
887 }
888
889
890 static void
891 print_visual_attribs_long_header(void)
892 {
893 printf("Vis Vis Visual Trans buff lev render DB ste r g b a aux dep ste accum buffers MS MS\n");
894 printf(" ID Depth Type parent size el type reo sz sz sz sz buf th ncl r g b a num bufs\n");
895 printf("----------------------------------------------------------------------------------------------------\n");
896 }
897
898
899 static void
900 print_visual_attribs_long(const struct visual_attribs *attribs)
901 {
902 printf("0x%2x %2d %-11s %2d %2d %2d %4s %3d %3d %3d %3d %3d %3d",
903 attribs->id,
904 attribs->depth,
905 visual_class_name(attribs->klass),
906 attribs->transparentType != GLX_NONE,
907 attribs->bufferSize,
908 attribs->level,
909 visual_render_type_name(attribs->render_type),
910 attribs->doubleBuffer,
911 attribs->stereo,
912 attribs->redSize, attribs->greenSize,
913 attribs->blueSize, attribs->alphaSize
914 );
915
916 printf(" %3d %4d %2d %3d %3d %3d %3d %2d %2d\n",
917 attribs->auxBuffers,
918 attribs->depthSize,
919 attribs->stencilSize,
920 attribs->accumRedSize, attribs->accumGreenSize,
921 attribs->accumBlueSize, attribs->accumAlphaSize,
922 attribs->numSamples, attribs->numMultisample
923 );
924 }
925
926
927 static void
928 print_visual_info(Display *dpy, int scrnum, InfoMode mode)
929 {
930 XVisualInfo theTemplate;
931 XVisualInfo *visuals;
932 int numVisuals, numGlxVisuals;
933 long mask;
934 int i;
935 struct visual_attribs attribs;
936
937 /* get list of all visuals on this screen */
938 theTemplate.screen = scrnum;
939 mask = VisualScreenMask;
940 visuals = XGetVisualInfo(dpy, mask, &theTemplate, &numVisuals);
941
942 numGlxVisuals = 0;
943 for (i = 0; i < numVisuals; i++) {
944 if (get_visual_attribs(dpy, &visuals[i], &attribs))
945 numGlxVisuals++;
946 }
947
948 if (numGlxVisuals == 0)
949 return;
950
951 printf("%d GLX Visuals\n", numGlxVisuals);
952
953 if (mode == Normal)
954 print_visual_attribs_short_header();
955 else if (mode == Wide)
956 print_visual_attribs_long_header();
957
958 for (i = 0; i < numVisuals; i++) {
959 if (!get_visual_attribs(dpy, &visuals[i], &attribs))
960 continue;
961
962 if (mode == Verbose)
963 print_visual_attribs_verbose(&attribs);
964 else if (mode == Normal)
965 print_visual_attribs_short(&attribs);
966 else if (mode == Wide)
967 print_visual_attribs_long(&attribs);
968 }
969 printf("\n");
970
971 XFree(visuals);
972 }
973
974 #ifdef GLX_VERSION_1_3
975
976 static void
977 print_fbconfig_info(Display *dpy, int scrnum, InfoMode mode)
978 {
979 int numFBConfigs = 0;
980 struct visual_attribs attribs;
981 GLXFBConfig *fbconfigs;
982 int i;
983
984 /* get list of all fbconfigs on this screen */
985 fbconfigs = glXGetFBConfigs(dpy, scrnum, &numFBConfigs);
986
987 if (numFBConfigs == 0) {
988 XFree(fbconfigs);
989 return;
990 }
991
992 printf("%d GLXFBConfigs:\n", numFBConfigs);
993 if (mode == Normal)
994 print_visual_attribs_short_header();
995 else if (mode == Wide)
996 print_visual_attribs_long_header();
997
998 for (i = 0; i < numFBConfigs; i++) {
999 get_fbconfig_attribs(dpy, fbconfigs[i], &attribs);
1000
1001 if (mode == Verbose)
1002 print_visual_attribs_verbose(&attribs);
1003 else if (mode == Normal)
1004 print_visual_attribs_short(&attribs);
1005 else if (mode == Wide)
1006 print_visual_attribs_long(&attribs);
1007 }
1008 printf("\n");
1009
1010 XFree(fbconfigs);
1011 }
1012
1013 #endif
1014
1015 /*
1016 * Stand-alone Mesa doesn't really implement the GLX protocol so it
1017 * doesn't really know the GLX attributes associated with an X visual.
1018 * The first time a visual is presented to Mesa's pseudo-GLX it
1019 * attaches ancilliary buffers to it (like depth and stencil).
1020 * But that usually only works if glXChooseVisual is used.
1021 * This function calls glXChooseVisual() to sort of "prime the pump"
1022 * for Mesa's GLX so that the visuals that get reported actually
1023 * reflect what applications will see.
1024 * This has no effect when using true GLX.
1025 */
1026 static void
1027 mesa_hack(Display *dpy, int scrnum)
1028 {
1029 static int attribs[] = {
1030 GLX_RGBA,
1031 GLX_RED_SIZE, 1,
1032 GLX_GREEN_SIZE, 1,
1033 GLX_BLUE_SIZE, 1,
1034 GLX_DEPTH_SIZE, 1,
1035 GLX_STENCIL_SIZE, 1,
1036 GLX_ACCUM_RED_SIZE, 1,
1037 GLX_ACCUM_GREEN_SIZE, 1,
1038 GLX_ACCUM_BLUE_SIZE, 1,
1039 GLX_ACCUM_ALPHA_SIZE, 1,
1040 GLX_DOUBLEBUFFER,
1041 None
1042 };
1043 XVisualInfo *visinfo;
1044
1045 visinfo = glXChooseVisual(dpy, scrnum, attribs);
1046 if (visinfo)
1047 XFree(visinfo);
1048 }
1049
1050
1051 /*
1052 * Examine all visuals to find the so-called best one.
1053 * We prefer deepest RGBA buffer with depth, stencil and accum
1054 * that has no caveats.
1055 */
1056 static int
1057 find_best_visual(Display *dpy, int scrnum)
1058 {
1059 XVisualInfo theTemplate;
1060 XVisualInfo *visuals;
1061 int numVisuals;
1062 long mask;
1063 int i;
1064 struct visual_attribs bestVis;
1065
1066 /* get list of all visuals on this screen */
1067 theTemplate.screen = scrnum;
1068 mask = VisualScreenMask;
1069 visuals = XGetVisualInfo(dpy, mask, &theTemplate, &numVisuals);
1070
1071 /* init bestVis with first visual info */
1072 get_visual_attribs(dpy, &visuals[0], &bestVis);
1073
1074 /* try to find a "better" visual */
1075 for (i = 1; i < numVisuals; i++) {
1076 struct visual_attribs vis;
1077
1078 get_visual_attribs(dpy, &visuals[i], &vis);
1079
1080 /* always skip visuals with caveats */
1081 if (vis.visualCaveat != GLX_NONE_EXT)
1082 continue;
1083
1084 /* see if this vis is better than bestVis */
1085 if ((!bestVis.supportsGL && vis.supportsGL) ||
1086 (bestVis.visualCaveat != GLX_NONE_EXT) ||
1087 (!(bestVis.render_type & GLX_RGBA_BIT) && (vis.render_type & GLX_RGBA_BIT)) ||
1088 (!bestVis.doubleBuffer && vis.doubleBuffer) ||
1089 (bestVis.redSize < vis.redSize) ||
1090 (bestVis.greenSize < vis.greenSize) ||
1091 (bestVis.blueSize < vis.blueSize) ||
1092 (bestVis.alphaSize < vis.alphaSize) ||
1093 (bestVis.depthSize < vis.depthSize) ||
1094 (bestVis.stencilSize < vis.stencilSize) ||
1095 (bestVis.accumRedSize < vis.accumRedSize)) {
1096 /* found a better visual */
1097 bestVis = vis;
1098 }
1099 }
1100
1101 XFree(visuals);
1102
1103 return bestVis.id;
1104 }
1105
1106
1107 static void
1108 usage(void)
1109 {
1110 printf("Usage: glxinfo [-v] [-t] [-h] [-i] [-b] [-display <dname>]\n");
1111 printf("\t-v: Print visuals info in verbose form.\n");
1112 printf("\t-t: Print verbose table.\n");
1113 printf("\t-display <dname>: Print GLX visuals on specified server.\n");
1114 printf("\t-h: This information.\n");
1115 printf("\t-i: Force an indirect rendering context.\n");
1116 printf("\t-b: Find the 'best' visual and print its number.\n");
1117 printf("\t-l: Print interesting OpenGL limits.\n");
1118 }
1119
1120
1121 int
1122 main(int argc, char *argv[])
1123 {
1124 char *displayName = NULL;
1125 Display *dpy;
1126 int numScreens, scrnum;
1127 InfoMode mode = Normal;
1128 GLboolean findBest = GL_FALSE;
1129 GLboolean limits = GL_FALSE;
1130 Bool allowDirect = True;
1131 int i;
1132
1133 for (i = 1; i < argc; i++) {
1134 if (strcmp(argv[i], "-display") == 0 && i + 1 < argc) {
1135 displayName = argv[i + 1];
1136 i++;
1137 }
1138 else if (strcmp(argv[i], "-t") == 0) {
1139 mode = Wide;
1140 }
1141 else if (strcmp(argv[i], "-v") == 0) {
1142 mode = Verbose;
1143 }
1144 else if (strcmp(argv[i], "-b") == 0) {
1145 findBest = GL_TRUE;
1146 }
1147 else if (strcmp(argv[i], "-i") == 0) {
1148 allowDirect = False;
1149 }
1150 else if (strcmp(argv[i], "-l") == 0) {
1151 limits = GL_TRUE;
1152 }
1153 else if (strcmp(argv[i], "-h") == 0) {
1154 usage();
1155 return 0;
1156 }
1157 else {
1158 printf("Unknown option `%s'\n", argv[i]);
1159 usage();
1160 return 0;
1161 }
1162 }
1163
1164 dpy = XOpenDisplay(displayName);
1165 if (!dpy) {
1166 fprintf(stderr, "Error: unable to open display %s\n", XDisplayName(displayName));
1167 return -1;
1168 }
1169
1170 if (findBest) {
1171 int b;
1172 mesa_hack(dpy, 0);
1173 b = find_best_visual(dpy, 0);
1174 printf("%d\n", b);
1175 }
1176 else {
1177 numScreens = ScreenCount(dpy);
1178 print_display_info(dpy);
1179 for (scrnum = 0; scrnum < numScreens; scrnum++) {
1180 mesa_hack(dpy, scrnum);
1181 print_screen_info(dpy, scrnum, allowDirect, limits);
1182 printf("\n");
1183 print_visual_info(dpy, scrnum, mode);
1184 #ifdef GLX_VERSION_1_3
1185 print_fbconfig_info(dpy, scrnum, mode);
1186 #endif
1187 if (scrnum + 1 < numScreens)
1188 printf("\n\n");
1189 }
1190 }
1191
1192 XCloseDisplay(dpy);
1193
1194 return 0;
1195 }