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