2 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
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:
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
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.
24 * This program is a work-alike of the IRIX glxinfo program.
25 * Command line options:
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)
33 * Brian Paul 26 January 2000
36 #define GLX_GLXEXT_PROTOTYPES
39 #include <X11/Xutil.h>
48 #define GLX_NONE_EXT 0x8000
51 #ifndef GLX_TRANSPARENT_RGB
52 #define GLX_TRANSPARENT_RGB 0x8008
66 /* X visual attribs */
70 int redMask
, greenMask
, blueMask
;
74 /* GL visual attribs */
77 int transparentRedValue
;
78 int transparentGreenValue
;
79 int transparentBlueValue
;
80 int transparentAlphaValue
;
81 int transparentIndexValue
;
88 int redSize
, greenSize
, blueSize
, alphaSize
;
91 int accumRedSize
, accumGreenSize
, accumBlueSize
, accumAlphaSize
;
92 int numSamples
, numMultisample
;
98 * Print a list of extensions, with word-wrapping.
101 print_extension_list(const char *ext
)
103 const char *indentString
= " ";
104 const int indent
= 4;
112 printf(indentString
);
115 if (ext
[j
] == ' ' || ext
[j
] == 0) {
116 /* found end of an extension name */
117 const int len
= j
- i
;
118 if (width
+ len
> max
) {
119 /* start a new line */
122 printf(indentString
);
124 /* print the extension name between ext[i] and ext[j] */
126 printf("%c", ext
[i
]);
129 /* either we're all done, or we'll continue with next extension */
150 print_display_info(Display
*dpy
)
152 printf("name of display: %s\n", DisplayString(dpy
));
157 * Print interesting limits for vertex/fragment programs.
160 print_program_limits(GLenum target
)
162 #if defined(GL_ARB_vertex_program) || defined(GL_ARB_fragment_program)
167 static const struct token_name limits
[] = {
168 { GL_MAX_PROGRAM_INSTRUCTIONS_ARB
, "GL_MAX_PROGRAM_INSTRUCTIONS_ARB" },
169 { GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB
, "GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB" },
170 { GL_MAX_PROGRAM_TEMPORARIES_ARB
, "GL_MAX_PROGRAM_TEMPORARIES_ARB" },
171 { GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB
, "GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB" },
172 { GL_MAX_PROGRAM_PARAMETERS_ARB
, "GL_MAX_PROGRAM_PARAMETERS_ARB" },
173 { GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB
, "GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB" },
174 { GL_MAX_PROGRAM_ATTRIBS_ARB
, "GL_MAX_PROGRAM_ATTRIBS_ARB" },
175 { GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB
, "GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB" },
176 { GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB
, "GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB" },
177 { GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB
, "GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB" },
178 { GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB
, "GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB" },
179 { GL_MAX_PROGRAM_ENV_PARAMETERS_ARB
, "GL_MAX_PROGRAM_ENV_PARAMETERS_ARB" },
180 { GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB
, "GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB" },
181 { GL_MAX_PROGRAM_TEX_INSTRUCTIONS_ARB
, "GL_MAX_PROGRAM_TEX_INSTRUCTIONS_ARB" },
182 { GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB
, "GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB" },
183 { GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB
, "GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB" },
184 { GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB
, "GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB" },
185 { GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB
, "GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB" },
188 PFNGLGETPROGRAMIVARBPROC GetProgramivARB_func
= (PFNGLGETPROGRAMIVARBPROC
)
189 glXGetProcAddressARB((GLubyte
*) "glGetProgramivARB");
193 if (target
== GL_VERTEX_PROGRAM_ARB
) {
194 printf(" GL_VERTEX_PROGRAM_ARB:\n");
196 else if (target
== GL_FRAGMENT_PROGRAM_ARB
) {
197 printf(" GL_FRAGMENT_PROGRAM_ARB:\n");
200 return; /* something's wrong */
203 for (i
= 0; limits
[i
].token
; i
++) {
204 GetProgramivARB_func(target
, limits
[i
].token
, max
);
205 if (glGetError() == GL_NO_ERROR
) {
206 printf(" %s = %d\n", limits
[i
].name
, max
[0]);
209 #endif /* GL_ARB_vertex_program / GL_ARB_fragment_program */
214 * Print interesting limits for vertex/fragment shaders.
217 print_shader_limits(GLenum target
)
223 #if defined(GL_ARB_vertex_shader)
224 static const struct token_name vertex_limits
[] = {
225 { GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB
, "GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB" },
226 { GL_MAX_VARYING_FLOATS_ARB
, "GL_MAX_VARYING_FLOATS_ARB" },
227 { GL_MAX_VERTEX_ATTRIBS_ARB
, "GL_MAX_VERTEX_ATTRIBS_ARB" },
228 { GL_MAX_TEXTURE_IMAGE_UNITS_ARB
, "GL_MAX_TEXTURE_IMAGE_UNITS_ARB" },
229 { GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB
, "GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB" },
230 { GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB
, "GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB" },
231 { GL_MAX_TEXTURE_COORDS_ARB
, "GL_MAX_TEXTURE_COORDS_ARB" },
235 #if defined(GL_ARB_fragment_shader)
236 static const struct token_name fragment_limits
[] = {
237 { GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB
, "GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB" },
238 { GL_MAX_TEXTURE_COORDS_ARB
, "GL_MAX_TEXTURE_COORDS_ARB" },
239 { GL_MAX_TEXTURE_IMAGE_UNITS_ARB
, "GL_MAX_TEXTURE_IMAGE_UNITS_ARB" },
246 #if defined(GL_ARB_vertex_shader)
247 if (target
== GL_VERTEX_SHADER_ARB
) {
248 printf(" GL_VERTEX_SHADER_ARB:\n");
249 for (i
= 0; vertex_limits
[i
].token
; i
++) {
250 glGetIntegerv(vertex_limits
[i
].token
, max
);
251 if (glGetError() == GL_NO_ERROR
) {
252 printf(" %s = %d\n", vertex_limits
[i
].name
, max
[0]);
257 #if defined(GL_ARB_fragment_shader)
258 if (target
== GL_FRAGMENT_SHADER_ARB
) {
259 printf(" GL_FRAGMENT_SHADER_ARB:\n");
260 for (i
= 0; fragment_limits
[i
].token
; i
++) {
261 glGetIntegerv(fragment_limits
[i
].token
, max
);
262 if (glGetError() == GL_NO_ERROR
) {
263 printf(" %s = %d\n", fragment_limits
[i
].name
, max
[0]);
272 * Print interesting OpenGL implementation limits.
275 print_limits(const char *extensions
)
282 static const struct token_name limits
[] = {
283 { 1, GL_MAX_ATTRIB_STACK_DEPTH
, "GL_MAX_ATTRIB_STACK_DEPTH" },
284 { 1, GL_MAX_CLIENT_ATTRIB_STACK_DEPTH
, "GL_MAX_CLIENT_ATTRIB_STACK_DEPTH" },
285 { 1, GL_MAX_CLIP_PLANES
, "GL_MAX_CLIP_PLANES" },
286 { 1, GL_MAX_COLOR_MATRIX_STACK_DEPTH
, "GL_MAX_COLOR_MATRIX_STACK_DEPTH" },
287 { 1, GL_MAX_ELEMENTS_VERTICES
, "GL_MAX_ELEMENTS_VERTICES" },
288 { 1, GL_MAX_ELEMENTS_INDICES
, "GL_MAX_ELEMENTS_INDICES" },
289 { 1, GL_MAX_EVAL_ORDER
, "GL_MAX_EVAL_ORDER" },
290 { 1, GL_MAX_LIGHTS
, "GL_MAX_LIGHTS" },
291 { 1, GL_MAX_LIST_NESTING
, "GL_MAX_LIST_NESTING" },
292 { 1, GL_MAX_MODELVIEW_STACK_DEPTH
, "GL_MAX_MODELVIEW_STACK_DEPTH" },
293 { 1, GL_MAX_NAME_STACK_DEPTH
, "GL_MAX_NAME_STACK_DEPTH" },
294 { 1, GL_MAX_PIXEL_MAP_TABLE
, "GL_MAX_PIXEL_MAP_TABLE" },
295 { 1, GL_MAX_PROJECTION_STACK_DEPTH
, "GL_MAX_PROJECTION_STACK_DEPTH" },
296 { 1, GL_MAX_TEXTURE_STACK_DEPTH
, "GL_MAX_TEXTURE_STACK_DEPTH" },
297 { 1, GL_MAX_TEXTURE_SIZE
, "GL_MAX_TEXTURE_SIZE" },
298 { 1, GL_MAX_3D_TEXTURE_SIZE
, "GL_MAX_3D_TEXTURE_SIZE" },
299 { 2, GL_MAX_VIEWPORT_DIMS
, "GL_MAX_VIEWPORT_DIMS" },
300 { 2, GL_ALIASED_LINE_WIDTH_RANGE
, "GL_ALIASED_LINE_WIDTH_RANGE" },
301 { 2, GL_SMOOTH_LINE_WIDTH_RANGE
, "GL_SMOOTH_LINE_WIDTH_RANGE" },
302 { 2, GL_ALIASED_POINT_SIZE_RANGE
, "GL_ALIASED_POINT_SIZE_RANGE" },
303 { 2, GL_SMOOTH_POINT_SIZE_RANGE
, "GL_SMOOTH_POINT_SIZE_RANGE" },
304 #if defined(GL_ARB_texture_cube_map)
305 { 1, GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB
, "GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB" },
307 #if defined(GLX_NV_texture_rectangle)
308 { 1, GL_MAX_RECTANGLE_TEXTURE_SIZE_NV
, "GL_MAX_RECTANGLE_TEXTURE_SIZE_NV" },
310 #if defined(GL_ARB_texture_compression)
311 { 1, GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB
, "GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB" },
313 #if defined(GL_ARB_multitexture)
314 { 1, GL_MAX_TEXTURE_UNITS_ARB
, "GL_MAX_TEXTURE_UNITS_ARB" },
316 #if defined(GL_EXT_texture_lod_bias)
317 { 1, GL_MAX_TEXTURE_LOD_BIAS_EXT
, "GL_MAX_TEXTURE_LOD_BIAS_EXT" },
319 #if defined(GL_EXT_texture_filter_anisotropic)
320 { 1, GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT
, "GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT" },
322 #if defined(GL_ARB_draw_buffers)
323 { 1, GL_MAX_DRAW_BUFFERS_ARB
, "GL_MAX_DRAW_BUFFERS_ARB" },
325 { 0, (GLenum
) 0, NULL
}
329 printf("OpenGL limits:\n");
330 for (i
= 0; limits
[i
].count
; i
++) {
331 glGetIntegerv(limits
[i
].token
, max
);
332 if (glGetError() == GL_NO_ERROR
) {
333 if (limits
[i
].count
== 1)
334 printf(" %s = %d\n", limits
[i
].name
, max
[0]);
335 else /* XXX fix if we ever query something with more than 2 values */
336 printf(" %s = %d, %d\n", limits
[i
].name
, max
[0], max
[1]);
340 /* these don't fit into the above mechanism, unfortunately */
341 glGetConvolutionParameteriv(GL_CONVOLUTION_2D
, GL_MAX_CONVOLUTION_WIDTH
, max
);
342 glGetConvolutionParameteriv(GL_CONVOLUTION_2D
, GL_MAX_CONVOLUTION_HEIGHT
, max
+1);
343 if (glGetError() == GL_NONE
) {
344 printf(" GL_MAX_CONVOLUTION_WIDTH/HEIGHT = %d, %d\n", max
[0], max
[1]);
347 #if defined(GL_ARB_vertex_program)
348 if (strstr(extensions
, "GL_ARB_vertex_program")) {
349 print_program_limits(GL_VERTEX_PROGRAM_ARB
);
352 #if defined(GL_ARB_fragment_program)
353 if (strstr(extensions
, "GL_ARB_fragment_program")) {
354 print_program_limits(GL_FRAGMENT_PROGRAM_ARB
);
357 #if defined(GL_ARB_vertex_shader)
358 if (strstr(extensions
, "GL_ARB_vertex_shader")) {
359 print_shader_limits(GL_VERTEX_SHADER_ARB
);
362 #if defined(GL_ARB_fragment_shader)
363 if (strstr(extensions
, "GL_ARB_fragment_shader")) {
364 print_shader_limits(GL_FRAGMENT_SHADER_ARB
);
371 print_screen_info(Display
*dpy
, int scrnum
, Bool allowDirect
, GLboolean limits
)
374 int attribSingle
[] = {
380 int attribDouble
[] = {
388 XSetWindowAttributes attr
;
392 XVisualInfo
*visinfo
;
393 int width
= 100, height
= 100;
395 root
= RootWindow(dpy
, scrnum
);
397 visinfo
= glXChooseVisual(dpy
, scrnum
, attribSingle
);
399 visinfo
= glXChooseVisual(dpy
, scrnum
, attribDouble
);
401 fprintf(stderr
, "Error: couldn't find RGB GLX visual\n");
406 attr
.background_pixel
= 0;
407 attr
.border_pixel
= 0;
408 attr
.colormap
= XCreateColormap(dpy
, root
, visinfo
->visual
, AllocNone
);
409 attr
.event_mask
= StructureNotifyMask
| ExposureMask
;
410 mask
= CWBackPixel
| CWBorderPixel
| CWColormap
| CWEventMask
;
411 win
= XCreateWindow(dpy
, root
, 0, 0, width
, height
,
412 0, visinfo
->depth
, InputOutput
,
413 visinfo
->visual
, mask
, &attr
);
415 ctx
= glXCreateContext( dpy
, visinfo
, NULL
, allowDirect
);
417 fprintf(stderr
, "Error: glXCreateContext failed\n");
419 XDestroyWindow(dpy
, win
);
423 if (glXMakeCurrent(dpy
, win
, ctx
)) {
424 const char *serverVendor
= glXQueryServerString(dpy
, scrnum
, GLX_VENDOR
);
425 const char *serverVersion
= glXQueryServerString(dpy
, scrnum
, GLX_VERSION
);
426 const char *serverExtensions
= glXQueryServerString(dpy
, scrnum
, GLX_EXTENSIONS
);
427 const char *clientVendor
= glXGetClientString(dpy
, GLX_VENDOR
);
428 const char *clientVersion
= glXGetClientString(dpy
, GLX_VERSION
);
429 const char *clientExtensions
= glXGetClientString(dpy
, GLX_EXTENSIONS
);
430 const char *glxExtensions
= glXQueryExtensionsString(dpy
, scrnum
);
431 const char *glVendor
= (const char *) glGetString(GL_VENDOR
);
432 const char *glRenderer
= (const char *) glGetString(GL_RENDERER
);
433 const char *glVersion
= (const char *) glGetString(GL_VERSION
);
434 const char *glExtensions
= (const char *) glGetString(GL_EXTENSIONS
);
437 char *displayName
= NULL
;
438 char *colon
= NULL
, *period
= NULL
;
440 if (! glXQueryVersion( dpy
, & glxVersionMajor
, & glxVersionMinor
)) {
441 fprintf(stderr
, "Error: glXQueryVersion failed\n");
445 /* Strip the screen number from the display name, if present. */
446 if (!(displayName
= (char *) malloc(strlen(DisplayString(dpy
)) + 1))) {
447 fprintf(stderr
, "Error: malloc() failed\n");
450 strcpy(displayName
, DisplayString(dpy
));
451 colon
= strrchr(displayName
, ':');
453 period
= strchr(colon
, '.');
457 printf("display: %s screen: %d\n", displayName
, scrnum
);
459 printf("direct rendering: ");
460 if (glXIsDirect(dpy
, ctx
)) {
464 printf("No (-i specified)\n");
465 } else if (getenv("LIBGL_ALWAYS_INDIRECT")) {
466 printf("No (LIBGL_ALWAYS_INDIRECT set)\n");
468 printf("No (If you want to find out why, try setting "
469 "LIBGL_DEBUG=verbose)\n");
472 printf("server glx vendor string: %s\n", serverVendor
);
473 printf("server glx version string: %s\n", serverVersion
);
474 printf("server glx extensions:\n");
475 print_extension_list(serverExtensions
);
476 printf("client glx vendor string: %s\n", clientVendor
);
477 printf("client glx version string: %s\n", clientVersion
);
478 printf("client glx extensions:\n");
479 print_extension_list(clientExtensions
);
480 printf("GLX version: %u.%u\n", glxVersionMajor
, glxVersionMinor
);
481 printf("GLX extensions:\n");
482 print_extension_list(glxExtensions
);
483 printf("OpenGL vendor string: %s\n", glVendor
);
484 printf("OpenGL renderer string: %s\n", glRenderer
);
485 printf("OpenGL version string: %s\n", glVersion
);
486 printf("OpenGL extensions:\n");
487 print_extension_list(glExtensions
);
489 print_limits(glExtensions
);
492 fprintf(stderr
, "Error: glXMakeCurrent failed\n");
495 glXDestroyContext(dpy
, ctx
);
497 XDestroyWindow(dpy
, win
);
502 visual_class_name(int cls
)
506 return "StaticColor";
508 return "PseudoColor";
516 return "DirectColor";
524 visual_class_abbrev(int cls
)
546 get_visual_attribs(Display
*dpy
, XVisualInfo
*vInfo
,
547 struct visual_attribs
*attribs
)
549 const char *ext
= glXQueryExtensionsString(dpy
, vInfo
->screen
);
551 memset(attribs
, 0, sizeof(struct visual_attribs
));
553 attribs
->id
= vInfo
->visualid
;
554 #if defined(__cplusplus) || defined(c_plusplus)
555 attribs
->klass
= vInfo
->c_class
;
557 attribs
->klass
= vInfo
->class;
559 attribs
->depth
= vInfo
->depth
;
560 attribs
->redMask
= vInfo
->red_mask
;
561 attribs
->greenMask
= vInfo
->green_mask
;
562 attribs
->blueMask
= vInfo
->blue_mask
;
563 attribs
->colormapSize
= vInfo
->colormap_size
;
564 attribs
->bitsPerRGB
= vInfo
->bits_per_rgb
;
566 if (glXGetConfig(dpy
, vInfo
, GLX_USE_GL
, &attribs
->supportsGL
) != 0)
568 glXGetConfig(dpy
, vInfo
, GLX_BUFFER_SIZE
, &attribs
->bufferSize
);
569 glXGetConfig(dpy
, vInfo
, GLX_LEVEL
, &attribs
->level
);
570 glXGetConfig(dpy
, vInfo
, GLX_RGBA
, &attribs
->rgba
);
571 glXGetConfig(dpy
, vInfo
, GLX_DOUBLEBUFFER
, &attribs
->doubleBuffer
);
572 glXGetConfig(dpy
, vInfo
, GLX_STEREO
, &attribs
->stereo
);
573 glXGetConfig(dpy
, vInfo
, GLX_AUX_BUFFERS
, &attribs
->auxBuffers
);
574 glXGetConfig(dpy
, vInfo
, GLX_RED_SIZE
, &attribs
->redSize
);
575 glXGetConfig(dpy
, vInfo
, GLX_GREEN_SIZE
, &attribs
->greenSize
);
576 glXGetConfig(dpy
, vInfo
, GLX_BLUE_SIZE
, &attribs
->blueSize
);
577 glXGetConfig(dpy
, vInfo
, GLX_ALPHA_SIZE
, &attribs
->alphaSize
);
578 glXGetConfig(dpy
, vInfo
, GLX_DEPTH_SIZE
, &attribs
->depthSize
);
579 glXGetConfig(dpy
, vInfo
, GLX_STENCIL_SIZE
, &attribs
->stencilSize
);
580 glXGetConfig(dpy
, vInfo
, GLX_ACCUM_RED_SIZE
, &attribs
->accumRedSize
);
581 glXGetConfig(dpy
, vInfo
, GLX_ACCUM_GREEN_SIZE
, &attribs
->accumGreenSize
);
582 glXGetConfig(dpy
, vInfo
, GLX_ACCUM_BLUE_SIZE
, &attribs
->accumBlueSize
);
583 glXGetConfig(dpy
, vInfo
, GLX_ACCUM_ALPHA_SIZE
, &attribs
->accumAlphaSize
);
585 /* get transparent pixel stuff */
586 glXGetConfig(dpy
, vInfo
,GLX_TRANSPARENT_TYPE
, &attribs
->transparentType
);
587 if (attribs
->transparentType
== GLX_TRANSPARENT_RGB
) {
588 glXGetConfig(dpy
, vInfo
, GLX_TRANSPARENT_RED_VALUE
, &attribs
->transparentRedValue
);
589 glXGetConfig(dpy
, vInfo
, GLX_TRANSPARENT_GREEN_VALUE
, &attribs
->transparentGreenValue
);
590 glXGetConfig(dpy
, vInfo
, GLX_TRANSPARENT_BLUE_VALUE
, &attribs
->transparentBlueValue
);
591 glXGetConfig(dpy
, vInfo
, GLX_TRANSPARENT_ALPHA_VALUE
, &attribs
->transparentAlphaValue
);
593 else if (attribs
->transparentType
== GLX_TRANSPARENT_INDEX
) {
594 glXGetConfig(dpy
, vInfo
, GLX_TRANSPARENT_INDEX_VALUE
, &attribs
->transparentIndexValue
);
597 /* multisample attribs */
598 #ifdef GLX_ARB_multisample
599 if (ext
&& strstr(ext
, "GLX_ARB_multisample") == 0) {
600 glXGetConfig(dpy
, vInfo
, GLX_SAMPLE_BUFFERS_ARB
, &attribs
->numMultisample
);
601 glXGetConfig(dpy
, vInfo
, GLX_SAMPLES_ARB
, &attribs
->numSamples
);
605 attribs
->numSamples
= 0;
606 attribs
->numMultisample
= 0;
609 #if defined(GLX_EXT_visual_rating)
610 if (ext
&& strstr(ext
, "GLX_EXT_visual_rating")) {
611 glXGetConfig(dpy
, vInfo
, GLX_VISUAL_CAVEAT_EXT
, &attribs
->visualCaveat
);
614 attribs
->visualCaveat
= GLX_NONE_EXT
;
617 attribs
->visualCaveat
= 0;
623 print_visual_attribs_verbose(const struct visual_attribs
*attribs
)
625 printf("Visual ID: %x depth=%d class=%s\n",
626 attribs
->id
, attribs
->depth
, visual_class_name(attribs
->klass
));
627 printf(" bufferSize=%d level=%d renderType=%s doubleBuffer=%d stereo=%d\n",
628 attribs
->bufferSize
, attribs
->level
, attribs
->rgba
? "rgba" : "ci",
629 attribs
->doubleBuffer
, attribs
->stereo
);
630 printf(" rgba: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n",
631 attribs
->redSize
, attribs
->greenSize
,
632 attribs
->blueSize
, attribs
->alphaSize
);
633 printf(" auxBuffers=%d depthSize=%d stencilSize=%d\n",
634 attribs
->auxBuffers
, attribs
->depthSize
, attribs
->stencilSize
);
635 printf(" accum: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n",
636 attribs
->accumRedSize
, attribs
->accumGreenSize
,
637 attribs
->accumBlueSize
, attribs
->accumAlphaSize
);
638 printf(" multiSample=%d multiSampleBuffers=%d\n",
639 attribs
->numSamples
, attribs
->numMultisample
);
640 #ifdef GLX_EXT_visual_rating
641 if (attribs
->visualCaveat
== GLX_NONE_EXT
|| attribs
->visualCaveat
== 0)
642 printf(" visualCaveat=None\n");
643 else if (attribs
->visualCaveat
== GLX_SLOW_VISUAL_EXT
)
644 printf(" visualCaveat=Slow\n");
645 else if (attribs
->visualCaveat
== GLX_NON_CONFORMANT_VISUAL_EXT
)
646 printf(" visualCaveat=Nonconformant\n");
648 if (attribs
->transparentType
== GLX_NONE
) {
649 printf(" Opaque.\n");
651 else if (attribs
->transparentType
== GLX_TRANSPARENT_RGB
) {
652 printf(" Transparent RGB: Red=%d Green=%d Blue=%d Alpha=%d\n",attribs
->transparentRedValue
,attribs
->transparentGreenValue
,attribs
->transparentBlueValue
,attribs
->transparentAlphaValue
);
654 else if (attribs
->transparentType
== GLX_TRANSPARENT_INDEX
) {
655 printf(" Transparent index=%d\n",attribs
->transparentIndexValue
);
661 print_visual_attribs_short_header(void)
663 printf(" visual x bf lv rg d st colorbuffer ax dp st accumbuffer ms cav\n");
664 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");
665 printf("----------------------------------------------------------------------\n");
670 print_visual_attribs_short(const struct visual_attribs
*attribs
)
673 #ifdef GLX_EXT_visual_rating
674 if (attribs
->visualCaveat
== GLX_NONE_EXT
|| attribs
->visualCaveat
== 0)
676 else if (attribs
->visualCaveat
== GLX_SLOW_VISUAL_EXT
)
678 else if (attribs
->visualCaveat
== GLX_NON_CONFORMANT_VISUAL_EXT
)
686 printf("0x%2x %2d %2s %2d %2d %2d %1s %2s %2s %2d %2d %2d %2d %2d %2d %2d",
689 visual_class_abbrev(attribs
->klass
),
690 attribs
->transparentType
!= GLX_NONE
,
693 attribs
->rgba
? "r" : "c",
694 attribs
->doubleBuffer
? "y" : ".",
695 attribs
->stereo
? "y" : ".",
696 attribs
->redSize
, attribs
->greenSize
,
697 attribs
->blueSize
, attribs
->alphaSize
,
703 printf(" %2d %2d %2d %2d %2d %1d %s\n",
704 attribs
->accumRedSize
, attribs
->accumGreenSize
,
705 attribs
->accumBlueSize
, attribs
->accumAlphaSize
,
706 attribs
->numSamples
, attribs
->numMultisample
,
713 print_visual_attribs_long_header(void)
715 printf("Vis Vis Visual Trans buff lev render DB ste r g b a aux dep ste accum buffers MS MS\n");
716 printf(" ID Depth Type parent size el type reo sz sz sz sz buf th ncl r g b a num bufs\n");
717 printf("----------------------------------------------------------------------------------------------------\n");
722 print_visual_attribs_long(const struct visual_attribs
*attribs
)
724 printf("0x%2x %2d %-11s %2d %2d %2d %4s %3d %3d %3d %3d %3d %3d",
727 visual_class_name(attribs
->klass
),
728 attribs
->transparentType
!= GLX_NONE
,
731 attribs
->rgba
? "rgba" : "ci ",
732 attribs
->doubleBuffer
,
734 attribs
->redSize
, attribs
->greenSize
,
735 attribs
->blueSize
, attribs
->alphaSize
738 printf(" %3d %4d %2d %3d %3d %3d %3d %2d %2d\n",
741 attribs
->stencilSize
,
742 attribs
->accumRedSize
, attribs
->accumGreenSize
,
743 attribs
->accumBlueSize
, attribs
->accumAlphaSize
,
744 attribs
->numSamples
, attribs
->numMultisample
750 print_visual_info(Display
*dpy
, int scrnum
, InfoMode mode
)
752 XVisualInfo theTemplate
;
753 XVisualInfo
*visuals
;
758 /* get list of all visuals on this screen */
759 theTemplate
.screen
= scrnum
;
760 mask
= VisualScreenMask
;
761 visuals
= XGetVisualInfo(dpy
, mask
, &theTemplate
, &numVisuals
);
763 if (mode
== Verbose
) {
764 for (i
= 0; i
< numVisuals
; i
++) {
765 struct visual_attribs attribs
;
766 get_visual_attribs(dpy
, &visuals
[i
], &attribs
);
767 print_visual_attribs_verbose(&attribs
);
770 else if (mode
== Normal
) {
771 print_visual_attribs_short_header();
772 for (i
= 0; i
< numVisuals
; i
++) {
773 struct visual_attribs attribs
;
774 get_visual_attribs(dpy
, &visuals
[i
], &attribs
);
775 print_visual_attribs_short(&attribs
);
778 else if (mode
== Wide
) {
779 print_visual_attribs_long_header();
780 for (i
= 0; i
< numVisuals
; i
++) {
781 struct visual_attribs attribs
;
782 get_visual_attribs(dpy
, &visuals
[i
], &attribs
);
783 print_visual_attribs_long(&attribs
);
792 * Stand-alone Mesa doesn't really implement the GLX protocol so it
793 * doesn't really know the GLX attributes associated with an X visual.
794 * The first time a visual is presented to Mesa's pseudo-GLX it
795 * attaches ancilliary buffers to it (like depth and stencil).
796 * But that usually only works if glXChooseVisual is used.
797 * This function calls glXChooseVisual() to sort of "prime the pump"
798 * for Mesa's GLX so that the visuals that get reported actually
799 * reflect what applications will see.
800 * This has no effect when using true GLX.
803 mesa_hack(Display
*dpy
, int scrnum
)
805 static int attribs
[] = {
812 GLX_ACCUM_RED_SIZE
, 1,
813 GLX_ACCUM_GREEN_SIZE
, 1,
814 GLX_ACCUM_BLUE_SIZE
, 1,
815 GLX_ACCUM_ALPHA_SIZE
, 1,
819 XVisualInfo
*visinfo
;
821 visinfo
= glXChooseVisual(dpy
, scrnum
, attribs
);
828 * Examine all visuals to find the so-called best one.
829 * We prefer deepest RGBA buffer with depth, stencil and accum
830 * that has no caveats.
833 find_best_visual(Display
*dpy
, int scrnum
)
835 XVisualInfo theTemplate
;
836 XVisualInfo
*visuals
;
840 struct visual_attribs bestVis
;
842 /* get list of all visuals on this screen */
843 theTemplate
.screen
= scrnum
;
844 mask
= VisualScreenMask
;
845 visuals
= XGetVisualInfo(dpy
, mask
, &theTemplate
, &numVisuals
);
847 /* init bestVis with first visual info */
848 get_visual_attribs(dpy
, &visuals
[0], &bestVis
);
850 /* try to find a "better" visual */
851 for (i
= 1; i
< numVisuals
; i
++) {
852 struct visual_attribs vis
;
854 get_visual_attribs(dpy
, &visuals
[i
], &vis
);
856 /* always skip visuals with caveats */
857 if (vis
.visualCaveat
!= GLX_NONE_EXT
)
860 /* see if this vis is better than bestVis */
861 if ((!bestVis
.supportsGL
&& vis
.supportsGL
) ||
862 (bestVis
.visualCaveat
!= GLX_NONE_EXT
) ||
863 (!bestVis
.rgba
&& vis
.rgba
) ||
864 (!bestVis
.doubleBuffer
&& vis
.doubleBuffer
) ||
865 (bestVis
.redSize
< vis
.redSize
) ||
866 (bestVis
.greenSize
< vis
.greenSize
) ||
867 (bestVis
.blueSize
< vis
.blueSize
) ||
868 (bestVis
.alphaSize
< vis
.alphaSize
) ||
869 (bestVis
.depthSize
< vis
.depthSize
) ||
870 (bestVis
.stencilSize
< vis
.stencilSize
) ||
871 (bestVis
.accumRedSize
< vis
.accumRedSize
)) {
872 /* found a better visual */
886 printf("Usage: glxinfo [-v] [-t] [-h] [-i] [-b] [-display <dname>]\n");
887 printf("\t-v: Print visuals info in verbose form.\n");
888 printf("\t-t: Print verbose table.\n");
889 printf("\t-display <dname>: Print GLX visuals on specified server.\n");
890 printf("\t-h: This information.\n");
891 printf("\t-i: Force an indirect rendering context.\n");
892 printf("\t-b: Find the 'best' visual and print it's number.\n");
893 printf("\t-l: Print interesting OpenGL limits.\n");
898 main(int argc
, char *argv
[])
900 char *displayName
= NULL
;
902 int numScreens
, scrnum
;
903 InfoMode mode
= Normal
;
904 GLboolean findBest
= GL_FALSE
;
905 GLboolean limits
= GL_FALSE
;
906 Bool allowDirect
= True
;
909 for (i
= 1; i
< argc
; i
++) {
910 if (strcmp(argv
[i
], "-display") == 0 && i
+ 1 < argc
) {
911 displayName
= argv
[i
+ 1];
914 else if (strcmp(argv
[i
], "-t") == 0) {
917 else if (strcmp(argv
[i
], "-v") == 0) {
920 else if (strcmp(argv
[i
], "-b") == 0) {
923 else if (strcmp(argv
[i
], "-i") == 0) {
926 else if (strcmp(argv
[i
], "-l") == 0) {
929 else if (strcmp(argv
[i
], "-h") == 0) {
934 printf("Unknown option `%s'\n", argv
[i
]);
940 dpy
= XOpenDisplay(displayName
);
942 fprintf(stderr
, "Error: unable to open display %s\n", XDisplayName(displayName
));
949 b
= find_best_visual(dpy
, 0);
953 numScreens
= ScreenCount(dpy
);
954 print_display_info(dpy
);
955 for (scrnum
= 0; scrnum
< numScreens
; scrnum
++) {
956 mesa_hack(dpy
, scrnum
);
957 print_screen_info(dpy
, scrnum
, allowDirect
, limits
);
959 print_visual_info(dpy
, scrnum
, mode
);
960 if (scrnum
+ 1 < numScreens
)