Merge commit 'origin/gallium-0.1' into gallium-0.2
[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(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(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 visinfo = glXChooseVisual(dpy, scrnum, attribSingle);
405 if (!visinfo)
406 visinfo = glXChooseVisual(dpy, scrnum, attribDouble);
407
408 if (visinfo)
409 ctx = glXCreateContext( dpy, visinfo, NULL, allowDirect );
410
411 #ifdef GLX_VERSION_1_3
412 {
413 int fbAttribSingle[] = {
414 GLX_RENDER_TYPE, GLX_RGBA_BIT,
415 GLX_RED_SIZE, 1,
416 GLX_GREEN_SIZE, 1,
417 GLX_BLUE_SIZE, 1,
418 GLX_DOUBLEBUFFER, GL_TRUE,
419 None };
420 int fbAttribDouble[] = {
421 GLX_RENDER_TYPE, GLX_RGBA_BIT,
422 GLX_RED_SIZE, 1,
423 GLX_GREEN_SIZE, 1,
424 GLX_BLUE_SIZE, 1,
425 None };
426 GLXFBConfig *configs = NULL;
427 int nConfigs;
428
429 if (!visinfo)
430 configs = glXChooseFBConfig(dpy, scrnum, fbAttribSingle, &nConfigs);
431 if (!visinfo)
432 configs = glXChooseFBConfig(dpy, scrnum, fbAttribDouble, &nConfigs);
433
434 if (configs) {
435 visinfo = glXGetVisualFromFBConfig(dpy, configs[0]);
436 ctx = glXCreateNewContext(dpy, configs[0], GLX_RGBA_TYPE, NULL, allowDirect);
437 XFree(configs);
438 }
439 }
440 #endif
441
442 if (!visinfo) {
443 fprintf(stderr, "Error: couldn't find RGB GLX visual or fbconfig\n");
444 return;
445 }
446
447 if (!ctx) {
448 fprintf(stderr, "Error: glXCreateContext failed\n");
449 XFree(visinfo);
450 XDestroyWindow(dpy, win);
451 return;
452 }
453
454 attr.background_pixel = 0;
455 attr.border_pixel = 0;
456 attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone);
457 attr.event_mask = StructureNotifyMask | ExposureMask;
458 mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
459 win = XCreateWindow(dpy, root, 0, 0, width, height,
460 0, visinfo->depth, InputOutput,
461 visinfo->visual, mask, &attr);
462
463 if (glXMakeCurrent(dpy, win, ctx)) {
464 const char *serverVendor = glXQueryServerString(dpy, scrnum, GLX_VENDOR);
465 const char *serverVersion = glXQueryServerString(dpy, scrnum, GLX_VERSION);
466 const char *serverExtensions = glXQueryServerString(dpy, scrnum, GLX_EXTENSIONS);
467 const char *clientVendor = glXGetClientString(dpy, GLX_VENDOR);
468 const char *clientVersion = glXGetClientString(dpy, GLX_VERSION);
469 const char *clientExtensions = glXGetClientString(dpy, GLX_EXTENSIONS);
470 const char *glxExtensions = glXQueryExtensionsString(dpy, scrnum);
471 const char *glVendor = (const char *) glGetString(GL_VENDOR);
472 const char *glRenderer = (const char *) glGetString(GL_RENDERER);
473 const char *glVersion = (const char *) glGetString(GL_VERSION);
474 const char *glExtensions = (const char *) glGetString(GL_EXTENSIONS);
475 int glxVersionMajor;
476 int glxVersionMinor;
477 char *displayName = NULL;
478 char *colon = NULL, *period = NULL;
479
480 if (! glXQueryVersion( dpy, & glxVersionMajor, & glxVersionMinor )) {
481 fprintf(stderr, "Error: glXQueryVersion failed\n");
482 exit(1);
483 }
484
485 /* Strip the screen number from the display name, if present. */
486 if (!(displayName = (char *) malloc(strlen(DisplayString(dpy)) + 1))) {
487 fprintf(stderr, "Error: malloc() failed\n");
488 exit(1);
489 }
490 strcpy(displayName, DisplayString(dpy));
491 colon = strrchr(displayName, ':');
492 if (colon) {
493 period = strchr(colon, '.');
494 if (period)
495 *period = '\0';
496 }
497 printf("display: %s screen: %d\n", displayName, scrnum);
498 free(displayName);
499 printf("direct rendering: ");
500 if (glXIsDirect(dpy, ctx)) {
501 printf("Yes\n");
502 } else {
503 if (!allowDirect) {
504 printf("No (-i specified)\n");
505 } else if (getenv("LIBGL_ALWAYS_INDIRECT")) {
506 printf("No (LIBGL_ALWAYS_INDIRECT set)\n");
507 } else {
508 printf("No (If you want to find out why, try setting "
509 "LIBGL_DEBUG=verbose)\n");
510 }
511 }
512 printf("server glx vendor string: %s\n", serverVendor);
513 printf("server glx version string: %s\n", serverVersion);
514 printf("server glx extensions:\n");
515 print_extension_list(serverExtensions);
516 printf("client glx vendor string: %s\n", clientVendor);
517 printf("client glx version string: %s\n", clientVersion);
518 printf("client glx extensions:\n");
519 print_extension_list(clientExtensions);
520 printf("GLX version: %u.%u\n", glxVersionMajor, glxVersionMinor);
521 printf("GLX extensions:\n");
522 print_extension_list(glxExtensions);
523 printf("OpenGL vendor string: %s\n", glVendor);
524 printf("OpenGL renderer string: %s\n", glRenderer);
525 printf("OpenGL version string: %s\n", glVersion);
526 #ifdef GL_VERSION_2_0
527 if (glVersion[0] >= '2' && glVersion[1] == '.') {
528 char *v = (char *) glGetString(GL_SHADING_LANGUAGE_VERSION);
529 printf("OpenGL shading language version string: %s\n", v);
530 }
531 #endif
532
533 printf("OpenGL extensions:\n");
534 print_extension_list(glExtensions);
535 if (limits)
536 print_limits(glExtensions);
537 }
538 else {
539 fprintf(stderr, "Error: glXMakeCurrent failed\n");
540 }
541
542 glXDestroyContext(dpy, ctx);
543 XFree(visinfo);
544 XDestroyWindow(dpy, win);
545 }
546
547
548 static const char *
549 visual_class_name(int cls)
550 {
551 switch (cls) {
552 case StaticColor:
553 return "StaticColor";
554 case PseudoColor:
555 return "PseudoColor";
556 case StaticGray:
557 return "StaticGray";
558 case GrayScale:
559 return "GrayScale";
560 case TrueColor:
561 return "TrueColor";
562 case DirectColor:
563 return "DirectColor";
564 default:
565 return "";
566 }
567 }
568
569
570 static const char *
571 visual_class_abbrev(int cls)
572 {
573 switch (cls) {
574 case StaticColor:
575 return "sc";
576 case PseudoColor:
577 return "pc";
578 case StaticGray:
579 return "sg";
580 case GrayScale:
581 return "gs";
582 case TrueColor:
583 return "tc";
584 case DirectColor:
585 return "dc";
586 default:
587 return "";
588 }
589 }
590
591 static const char *
592 visual_render_type_name(int type)
593 {
594 switch (type) {
595 case GLX_RGBA_BIT:
596 return "rgba";
597 case GLX_COLOR_INDEX_BIT:
598 return "ci";
599 case GLX_RGBA_BIT | GLX_COLOR_INDEX_BIT:
600 return "rgba|ci";
601 default:
602 return "";
603 }
604 }
605
606 static GLboolean
607 get_visual_attribs(Display *dpy, XVisualInfo *vInfo,
608 struct visual_attribs *attribs)
609 {
610 const char *ext = glXQueryExtensionsString(dpy, vInfo->screen);
611 int rgba;
612
613 memset(attribs, 0, sizeof(struct visual_attribs));
614
615 attribs->id = vInfo->visualid;
616 #if defined(__cplusplus) || defined(c_plusplus)
617 attribs->klass = vInfo->c_class;
618 #else
619 attribs->klass = vInfo->class;
620 #endif
621 attribs->depth = vInfo->depth;
622 attribs->redMask = vInfo->red_mask;
623 attribs->greenMask = vInfo->green_mask;
624 attribs->blueMask = vInfo->blue_mask;
625 attribs->colormapSize = vInfo->colormap_size;
626 attribs->bitsPerRGB = vInfo->bits_per_rgb;
627
628 if (glXGetConfig(dpy, vInfo, GLX_USE_GL, &attribs->supportsGL) != 0 ||
629 !attribs->supportsGL)
630 return GL_FALSE;
631 glXGetConfig(dpy, vInfo, GLX_BUFFER_SIZE, &attribs->bufferSize);
632 glXGetConfig(dpy, vInfo, GLX_LEVEL, &attribs->level);
633 glXGetConfig(dpy, vInfo, GLX_RGBA, &rgba);
634 if (rgba)
635 attribs->render_type = GLX_RGBA_BIT;
636 else
637 attribs->render_type = GLX_COLOR_INDEX_BIT;
638
639 glXGetConfig(dpy, vInfo, GLX_DOUBLEBUFFER, &attribs->doubleBuffer);
640 glXGetConfig(dpy, vInfo, GLX_STEREO, &attribs->stereo);
641 glXGetConfig(dpy, vInfo, GLX_AUX_BUFFERS, &attribs->auxBuffers);
642 glXGetConfig(dpy, vInfo, GLX_RED_SIZE, &attribs->redSize);
643 glXGetConfig(dpy, vInfo, GLX_GREEN_SIZE, &attribs->greenSize);
644 glXGetConfig(dpy, vInfo, GLX_BLUE_SIZE, &attribs->blueSize);
645 glXGetConfig(dpy, vInfo, GLX_ALPHA_SIZE, &attribs->alphaSize);
646 glXGetConfig(dpy, vInfo, GLX_DEPTH_SIZE, &attribs->depthSize);
647 glXGetConfig(dpy, vInfo, GLX_STENCIL_SIZE, &attribs->stencilSize);
648 glXGetConfig(dpy, vInfo, GLX_ACCUM_RED_SIZE, &attribs->accumRedSize);
649 glXGetConfig(dpy, vInfo, GLX_ACCUM_GREEN_SIZE, &attribs->accumGreenSize);
650 glXGetConfig(dpy, vInfo, GLX_ACCUM_BLUE_SIZE, &attribs->accumBlueSize);
651 glXGetConfig(dpy, vInfo, GLX_ACCUM_ALPHA_SIZE, &attribs->accumAlphaSize);
652
653 /* get transparent pixel stuff */
654 glXGetConfig(dpy, vInfo,GLX_TRANSPARENT_TYPE, &attribs->transparentType);
655 if (attribs->transparentType == GLX_TRANSPARENT_RGB) {
656 glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_RED_VALUE, &attribs->transparentRedValue);
657 glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_GREEN_VALUE, &attribs->transparentGreenValue);
658 glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_BLUE_VALUE, &attribs->transparentBlueValue);
659 glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_ALPHA_VALUE, &attribs->transparentAlphaValue);
660 }
661 else if (attribs->transparentType == GLX_TRANSPARENT_INDEX) {
662 glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_INDEX_VALUE, &attribs->transparentIndexValue);
663 }
664
665 /* multisample attribs */
666 #ifdef GLX_ARB_multisample
667 if (ext && strstr(ext, "GLX_ARB_multisample")) {
668 glXGetConfig(dpy, vInfo, GLX_SAMPLE_BUFFERS_ARB, &attribs->numMultisample);
669 glXGetConfig(dpy, vInfo, GLX_SAMPLES_ARB, &attribs->numSamples);
670 }
671 #endif
672 else {
673 attribs->numSamples = 0;
674 attribs->numMultisample = 0;
675 }
676
677 #if defined(GLX_EXT_visual_rating)
678 if (ext && strstr(ext, "GLX_EXT_visual_rating")) {
679 glXGetConfig(dpy, vInfo, GLX_VISUAL_CAVEAT_EXT, &attribs->visualCaveat);
680 }
681 else {
682 attribs->visualCaveat = GLX_NONE_EXT;
683 }
684 #else
685 attribs->visualCaveat = 0;
686 #endif
687
688 return GL_TRUE;
689 }
690
691 #ifdef GLX_VERSION_1_3
692
693 static int
694 glx_token_to_visual_class(int visual_type)
695 {
696 switch (visual_type) {
697 case GLX_TRUE_COLOR:
698 return TrueColor;
699 case GLX_DIRECT_COLOR:
700 return DirectColor;
701 case GLX_PSEUDO_COLOR:
702 return PseudoColor;
703 case GLX_STATIC_COLOR:
704 return StaticColor;
705 case GLX_GRAY_SCALE:
706 return GrayScale;
707 case GLX_STATIC_GRAY:
708 return StaticGray;
709 case GLX_NONE:
710 default:
711 return None;
712 }
713 }
714
715 static GLboolean
716 get_fbconfig_attribs(Display *dpy, GLXFBConfig fbconfig,
717 struct visual_attribs *attribs)
718 {
719 int visual_type;
720
721 memset(attribs, 0, sizeof(struct visual_attribs));
722
723 glXGetFBConfigAttrib(dpy, fbconfig, GLX_FBCONFIG_ID, &attribs->id);
724
725 #if 0
726 attribs->depth = vInfo->depth;
727 attribs->redMask = vInfo->red_mask;
728 attribs->greenMask = vInfo->green_mask;
729 attribs->blueMask = vInfo->blue_mask;
730 attribs->colormapSize = vInfo->colormap_size;
731 attribs->bitsPerRGB = vInfo->bits_per_rgb;
732 #endif
733
734 glXGetFBConfigAttrib(dpy, fbconfig, GLX_X_VISUAL_TYPE, &visual_type);
735 attribs->klass = glx_token_to_visual_class(visual_type);
736
737 glXGetFBConfigAttrib(dpy, fbconfig, GLX_BUFFER_SIZE, &attribs->bufferSize);
738 glXGetFBConfigAttrib(dpy, fbconfig, GLX_LEVEL, &attribs->level);
739 glXGetFBConfigAttrib(dpy, fbconfig, GLX_RENDER_TYPE, &attribs->render_type);
740 glXGetFBConfigAttrib(dpy, fbconfig, GLX_DOUBLEBUFFER, &attribs->doubleBuffer);
741 glXGetFBConfigAttrib(dpy, fbconfig, GLX_STEREO, &attribs->stereo);
742 glXGetFBConfigAttrib(dpy, fbconfig, GLX_AUX_BUFFERS, &attribs->auxBuffers);
743
744 glXGetFBConfigAttrib(dpy, fbconfig, GLX_RED_SIZE, &attribs->redSize);
745 glXGetFBConfigAttrib(dpy, fbconfig, GLX_GREEN_SIZE, &attribs->greenSize);
746 glXGetFBConfigAttrib(dpy, fbconfig, GLX_BLUE_SIZE, &attribs->blueSize);
747 glXGetFBConfigAttrib(dpy, fbconfig, GLX_ALPHA_SIZE, &attribs->alphaSize);
748 glXGetFBConfigAttrib(dpy, fbconfig, GLX_DEPTH_SIZE, &attribs->depthSize);
749 glXGetFBConfigAttrib(dpy, fbconfig, GLX_STENCIL_SIZE, &attribs->stencilSize);
750
751 glXGetFBConfigAttrib(dpy, fbconfig, GLX_ACCUM_RED_SIZE, &attribs->accumRedSize);
752 glXGetFBConfigAttrib(dpy, fbconfig, GLX_ACCUM_GREEN_SIZE, &attribs->accumGreenSize);
753 glXGetFBConfigAttrib(dpy, fbconfig, GLX_ACCUM_BLUE_SIZE, &attribs->accumBlueSize);
754 glXGetFBConfigAttrib(dpy, fbconfig, GLX_ACCUM_ALPHA_SIZE, &attribs->accumAlphaSize);
755
756 /* get transparent pixel stuff */
757 glXGetFBConfigAttrib(dpy, fbconfig,GLX_TRANSPARENT_TYPE, &attribs->transparentType);
758 if (attribs->transparentType == GLX_TRANSPARENT_RGB) {
759 glXGetFBConfigAttrib(dpy, fbconfig, GLX_TRANSPARENT_RED_VALUE, &attribs->transparentRedValue);
760 glXGetFBConfigAttrib(dpy, fbconfig, GLX_TRANSPARENT_GREEN_VALUE, &attribs->transparentGreenValue);
761 glXGetFBConfigAttrib(dpy, fbconfig, GLX_TRANSPARENT_BLUE_VALUE, &attribs->transparentBlueValue);
762 glXGetFBConfigAttrib(dpy, fbconfig, GLX_TRANSPARENT_ALPHA_VALUE, &attribs->transparentAlphaValue);
763 }
764 else if (attribs->transparentType == GLX_TRANSPARENT_INDEX) {
765 glXGetFBConfigAttrib(dpy, fbconfig, GLX_TRANSPARENT_INDEX_VALUE, &attribs->transparentIndexValue);
766 }
767
768 glXGetFBConfigAttrib(dpy, fbconfig, GLX_SAMPLE_BUFFERS, &attribs->numMultisample);
769 glXGetFBConfigAttrib(dpy, fbconfig, GLX_SAMPLES, &attribs->numSamples);
770 glXGetFBConfigAttrib(dpy, fbconfig, GLX_CONFIG_CAVEAT, &attribs->visualCaveat);
771
772 return GL_TRUE;
773 }
774
775 #endif
776
777
778
779 static void
780 print_visual_attribs_verbose(const struct visual_attribs *attribs)
781 {
782 printf("Visual ID: %x depth=%d class=%s\n",
783 attribs->id, attribs->depth, visual_class_name(attribs->klass));
784 printf(" bufferSize=%d level=%d renderType=%s doubleBuffer=%d stereo=%d\n",
785 attribs->bufferSize, attribs->level,
786 visual_render_type_name(attribs->render_type),
787 attribs->doubleBuffer, attribs->stereo);
788 printf(" rgba: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n",
789 attribs->redSize, attribs->greenSize,
790 attribs->blueSize, attribs->alphaSize);
791 printf(" auxBuffers=%d depthSize=%d stencilSize=%d\n",
792 attribs->auxBuffers, attribs->depthSize, attribs->stencilSize);
793 printf(" accum: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n",
794 attribs->accumRedSize, attribs->accumGreenSize,
795 attribs->accumBlueSize, attribs->accumAlphaSize);
796 printf(" multiSample=%d multiSampleBuffers=%d\n",
797 attribs->numSamples, attribs->numMultisample);
798 #ifdef GLX_EXT_visual_rating
799 if (attribs->visualCaveat == GLX_NONE_EXT || attribs->visualCaveat == 0)
800 printf(" visualCaveat=None\n");
801 else if (attribs->visualCaveat == GLX_SLOW_VISUAL_EXT)
802 printf(" visualCaveat=Slow\n");
803 else if (attribs->visualCaveat == GLX_NON_CONFORMANT_VISUAL_EXT)
804 printf(" visualCaveat=Nonconformant\n");
805 #endif
806 if (attribs->transparentType == GLX_NONE) {
807 printf(" Opaque.\n");
808 }
809 else if (attribs->transparentType == GLX_TRANSPARENT_RGB) {
810 printf(" Transparent RGB: Red=%d Green=%d Blue=%d Alpha=%d\n",attribs->transparentRedValue,attribs->transparentGreenValue,attribs->transparentBlueValue,attribs->transparentAlphaValue);
811 }
812 else if (attribs->transparentType == GLX_TRANSPARENT_INDEX) {
813 printf(" Transparent index=%d\n",attribs->transparentIndexValue);
814 }
815 }
816
817
818 static void
819 print_visual_attribs_short_header(void)
820 {
821 printf(" visual x bf lv rg d st colorbuffer ax dp st accumbuffer ms cav\n");
822 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");
823 printf("----------------------------------------------------------------------\n");
824 }
825
826
827 static void
828 print_visual_attribs_short(const struct visual_attribs *attribs)
829 {
830 char *caveat = NULL;
831 #ifdef GLX_EXT_visual_rating
832 if (attribs->visualCaveat == GLX_NONE_EXT || attribs->visualCaveat == 0)
833 caveat = "None";
834 else if (attribs->visualCaveat == GLX_SLOW_VISUAL_EXT)
835 caveat = "Slow";
836 else if (attribs->visualCaveat == GLX_NON_CONFORMANT_VISUAL_EXT)
837 caveat = "Ncon";
838 else
839 caveat = "None";
840 #else
841 caveat = "None";
842 #endif
843
844 printf("0x%02x %2d %2s %2d %2d %2d %c%c %c %c %2d %2d %2d %2d %2d %2d %2d",
845 attribs->id,
846 attribs->depth,
847 visual_class_abbrev(attribs->klass),
848 attribs->transparentType != GLX_NONE,
849 attribs->bufferSize,
850 attribs->level,
851 (attribs->render_type & GLX_RGBA_BIT) ? 'r' : ' ',
852 (attribs->render_type & GLX_COLOR_INDEX_BIT) ? 'c' : ' ',
853 attribs->doubleBuffer ? 'y' : '.',
854 attribs->stereo ? 'y' : '.',
855 attribs->redSize, attribs->greenSize,
856 attribs->blueSize, attribs->alphaSize,
857 attribs->auxBuffers,
858 attribs->depthSize,
859 attribs->stencilSize
860 );
861
862 printf(" %2d %2d %2d %2d %2d %1d %s\n",
863 attribs->accumRedSize, attribs->accumGreenSize,
864 attribs->accumBlueSize, attribs->accumAlphaSize,
865 attribs->numSamples, attribs->numMultisample,
866 caveat
867 );
868 }
869
870
871 static void
872 print_visual_attribs_long_header(void)
873 {
874 printf("Vis Vis Visual Trans buff lev render DB ste r g b a aux dep ste accum buffers MS MS\n");
875 printf(" ID Depth Type parent size el type reo sz sz sz sz buf th ncl r g b a num bufs\n");
876 printf("----------------------------------------------------------------------------------------------------\n");
877 }
878
879
880 static void
881 print_visual_attribs_long(const struct visual_attribs *attribs)
882 {
883 printf("0x%2x %2d %-11s %2d %2d %2d %4s %3d %3d %3d %3d %3d %3d",
884 attribs->id,
885 attribs->depth,
886 visual_class_name(attribs->klass),
887 attribs->transparentType != GLX_NONE,
888 attribs->bufferSize,
889 attribs->level,
890 visual_render_type_name(attribs->render_type),
891 attribs->doubleBuffer,
892 attribs->stereo,
893 attribs->redSize, attribs->greenSize,
894 attribs->blueSize, attribs->alphaSize
895 );
896
897 printf(" %3d %4d %2d %3d %3d %3d %3d %2d %2d\n",
898 attribs->auxBuffers,
899 attribs->depthSize,
900 attribs->stencilSize,
901 attribs->accumRedSize, attribs->accumGreenSize,
902 attribs->accumBlueSize, attribs->accumAlphaSize,
903 attribs->numSamples, attribs->numMultisample
904 );
905 }
906
907
908 static void
909 print_visual_info(Display *dpy, int scrnum, InfoMode mode)
910 {
911 XVisualInfo theTemplate;
912 XVisualInfo *visuals;
913 int numVisuals, numGlxVisuals;
914 long mask;
915 int i;
916 struct visual_attribs attribs;
917
918 /* get list of all visuals on this screen */
919 theTemplate.screen = scrnum;
920 mask = VisualScreenMask;
921 visuals = XGetVisualInfo(dpy, mask, &theTemplate, &numVisuals);
922
923 numGlxVisuals = 0;
924 for (i = 0; i < numVisuals; i++) {
925 if (get_visual_attribs(dpy, &visuals[i], &attribs))
926 numGlxVisuals++;
927 }
928
929 if (numGlxVisuals == 0)
930 return;
931
932 printf("%d GLX Visuals\n", numGlxVisuals);
933
934 if (mode == Normal)
935 print_visual_attribs_short_header();
936 else if (mode == Wide)
937 print_visual_attribs_long_header();
938
939 for (i = 0; i < numVisuals; i++) {
940 if (!get_visual_attribs(dpy, &visuals[i], &attribs))
941 continue;
942
943 if (mode == Verbose)
944 print_visual_attribs_verbose(&attribs);
945 else if (mode == Normal)
946 print_visual_attribs_short(&attribs);
947 else if (mode == Wide)
948 print_visual_attribs_long(&attribs);
949 }
950 printf("\n");
951
952 XFree(visuals);
953 }
954
955 #ifdef GLX_VERSION_1_3
956
957 static void
958 print_fbconfig_info(Display *dpy, int scrnum, InfoMode mode)
959 {
960 int numFBConfigs;
961 struct visual_attribs attribs;
962 GLXFBConfig *fbconfigs;
963 int i;
964
965 /* get list of all fbconfigs on this screen */
966 fbconfigs = glXGetFBConfigs(dpy, scrnum, &numFBConfigs);
967
968 if (numFBConfigs == 0)
969 return;
970
971 printf("%d GLXFBConfigs:\n", numFBConfigs);
972 if (mode == Normal)
973 print_visual_attribs_short_header();
974 else if (mode == Wide)
975 print_visual_attribs_long_header();
976
977 for (i = 0; i < numFBConfigs; i++) {
978 get_fbconfig_attribs(dpy, fbconfigs[i], &attribs);
979
980 if (mode == Verbose)
981 print_visual_attribs_verbose(&attribs);
982 else if (mode == Normal)
983 print_visual_attribs_short(&attribs);
984 else if (mode == Wide)
985 print_visual_attribs_long(&attribs);
986 }
987 printf("\n");
988
989 XFree(fbconfigs);
990 }
991
992 #endif
993
994 /*
995 * Stand-alone Mesa doesn't really implement the GLX protocol so it
996 * doesn't really know the GLX attributes associated with an X visual.
997 * The first time a visual is presented to Mesa's pseudo-GLX it
998 * attaches ancilliary buffers to it (like depth and stencil).
999 * But that usually only works if glXChooseVisual is used.
1000 * This function calls glXChooseVisual() to sort of "prime the pump"
1001 * for Mesa's GLX so that the visuals that get reported actually
1002 * reflect what applications will see.
1003 * This has no effect when using true GLX.
1004 */
1005 static void
1006 mesa_hack(Display *dpy, int scrnum)
1007 {
1008 static int attribs[] = {
1009 GLX_RGBA,
1010 GLX_RED_SIZE, 1,
1011 GLX_GREEN_SIZE, 1,
1012 GLX_BLUE_SIZE, 1,
1013 GLX_DEPTH_SIZE, 1,
1014 GLX_STENCIL_SIZE, 1,
1015 GLX_ACCUM_RED_SIZE, 1,
1016 GLX_ACCUM_GREEN_SIZE, 1,
1017 GLX_ACCUM_BLUE_SIZE, 1,
1018 GLX_ACCUM_ALPHA_SIZE, 1,
1019 GLX_DOUBLEBUFFER,
1020 None
1021 };
1022 XVisualInfo *visinfo;
1023
1024 visinfo = glXChooseVisual(dpy, scrnum, attribs);
1025 if (visinfo)
1026 XFree(visinfo);
1027 }
1028
1029
1030 /*
1031 * Examine all visuals to find the so-called best one.
1032 * We prefer deepest RGBA buffer with depth, stencil and accum
1033 * that has no caveats.
1034 */
1035 static int
1036 find_best_visual(Display *dpy, int scrnum)
1037 {
1038 XVisualInfo theTemplate;
1039 XVisualInfo *visuals;
1040 int numVisuals;
1041 long mask;
1042 int i;
1043 struct visual_attribs bestVis;
1044
1045 /* get list of all visuals on this screen */
1046 theTemplate.screen = scrnum;
1047 mask = VisualScreenMask;
1048 visuals = XGetVisualInfo(dpy, mask, &theTemplate, &numVisuals);
1049
1050 /* init bestVis with first visual info */
1051 get_visual_attribs(dpy, &visuals[0], &bestVis);
1052
1053 /* try to find a "better" visual */
1054 for (i = 1; i < numVisuals; i++) {
1055 struct visual_attribs vis;
1056
1057 get_visual_attribs(dpy, &visuals[i], &vis);
1058
1059 /* always skip visuals with caveats */
1060 if (vis.visualCaveat != GLX_NONE_EXT)
1061 continue;
1062
1063 /* see if this vis is better than bestVis */
1064 if ((!bestVis.supportsGL && vis.supportsGL) ||
1065 (bestVis.visualCaveat != GLX_NONE_EXT) ||
1066 (!(bestVis.render_type & GLX_RGBA_BIT) && (vis.render_type & GLX_RGBA_BIT)) ||
1067 (!bestVis.doubleBuffer && vis.doubleBuffer) ||
1068 (bestVis.redSize < vis.redSize) ||
1069 (bestVis.greenSize < vis.greenSize) ||
1070 (bestVis.blueSize < vis.blueSize) ||
1071 (bestVis.alphaSize < vis.alphaSize) ||
1072 (bestVis.depthSize < vis.depthSize) ||
1073 (bestVis.stencilSize < vis.stencilSize) ||
1074 (bestVis.accumRedSize < vis.accumRedSize)) {
1075 /* found a better visual */
1076 bestVis = vis;
1077 }
1078 }
1079
1080 XFree(visuals);
1081
1082 return bestVis.id;
1083 }
1084
1085
1086 static void
1087 usage(void)
1088 {
1089 printf("Usage: glxinfo [-v] [-t] [-h] [-i] [-b] [-display <dname>]\n");
1090 printf("\t-v: Print visuals info in verbose form.\n");
1091 printf("\t-t: Print verbose table.\n");
1092 printf("\t-display <dname>: Print GLX visuals on specified server.\n");
1093 printf("\t-h: This information.\n");
1094 printf("\t-i: Force an indirect rendering context.\n");
1095 printf("\t-b: Find the 'best' visual and print it's number.\n");
1096 printf("\t-l: Print interesting OpenGL limits.\n");
1097 }
1098
1099
1100 int
1101 main(int argc, char *argv[])
1102 {
1103 char *displayName = NULL;
1104 Display *dpy;
1105 int numScreens, scrnum;
1106 InfoMode mode = Normal;
1107 GLboolean findBest = GL_FALSE;
1108 GLboolean limits = GL_FALSE;
1109 Bool allowDirect = True;
1110 int i;
1111
1112 for (i = 1; i < argc; i++) {
1113 if (strcmp(argv[i], "-display") == 0 && i + 1 < argc) {
1114 displayName = argv[i + 1];
1115 i++;
1116 }
1117 else if (strcmp(argv[i], "-t") == 0) {
1118 mode = Wide;
1119 }
1120 else if (strcmp(argv[i], "-v") == 0) {
1121 mode = Verbose;
1122 }
1123 else if (strcmp(argv[i], "-b") == 0) {
1124 findBest = GL_TRUE;
1125 }
1126 else if (strcmp(argv[i], "-i") == 0) {
1127 allowDirect = False;
1128 }
1129 else if (strcmp(argv[i], "-l") == 0) {
1130 limits = GL_TRUE;
1131 }
1132 else if (strcmp(argv[i], "-h") == 0) {
1133 usage();
1134 return 0;
1135 }
1136 else {
1137 printf("Unknown option `%s'\n", argv[i]);
1138 usage();
1139 return 0;
1140 }
1141 }
1142
1143 dpy = XOpenDisplay(displayName);
1144 if (!dpy) {
1145 fprintf(stderr, "Error: unable to open display %s\n", XDisplayName(displayName));
1146 return -1;
1147 }
1148
1149 if (findBest) {
1150 int b;
1151 mesa_hack(dpy, 0);
1152 b = find_best_visual(dpy, 0);
1153 printf("%d\n", b);
1154 }
1155 else {
1156 numScreens = ScreenCount(dpy);
1157 print_display_info(dpy);
1158 for (scrnum = 0; scrnum < numScreens; scrnum++) {
1159 mesa_hack(dpy, scrnum);
1160 print_screen_info(dpy, scrnum, allowDirect, limits);
1161 printf("\n");
1162 print_visual_info(dpy, scrnum, mode);
1163 #ifdef GLX_VERSION_1_3
1164 print_fbconfig_info(dpy, scrnum, mode);
1165 #endif
1166 if (scrnum + 1 < numScreens)
1167 printf("\n\n");
1168 }
1169 }
1170
1171 XCloseDisplay(dpy);
1172
1173 return 0;
1174 }