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
56 #define GLX_RGBA_BIT 0x00000001
59 #ifndef GLX_COLOR_INDEX_BIT
60 #define GLX_COLOR_INDEX_BIT 0x00000002
73 /* X visual attribs */
77 int redMask
, greenMask
, blueMask
;
81 /* GL visual attribs */
84 int transparentRedValue
;
85 int transparentGreenValue
;
86 int transparentBlueValue
;
87 int transparentAlphaValue
;
88 int transparentIndexValue
;
95 int redSize
, greenSize
, blueSize
, alphaSize
;
98 int accumRedSize
, accumGreenSize
, accumBlueSize
, accumAlphaSize
;
99 int numSamples
, numMultisample
;
105 * Print a list of extensions, with word-wrapping.
108 print_extension_list(const char *ext
)
110 const char *indentString
= " ";
111 const int indent
= 4;
119 printf(indentString
);
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 */
129 printf(indentString
);
131 /* print the extension name between ext[i] and ext[j] */
133 printf("%c", ext
[i
]);
136 /* either we're all done, or we'll continue with next extension */
157 print_display_info(Display
*dpy
)
159 printf("name of display: %s\n", DisplayString(dpy
));
164 * Print interesting limits for vertex/fragment programs.
167 print_program_limits(GLenum target
)
169 #if defined(GL_ARB_vertex_program) || defined(GL_ARB_fragment_program)
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" },
195 PFNGLGETPROGRAMIVARBPROC GetProgramivARB_func
= (PFNGLGETPROGRAMIVARBPROC
)
196 glXGetProcAddressARB((GLubyte
*) "glGetProgramivARB");
200 if (target
== GL_VERTEX_PROGRAM_ARB
) {
201 printf(" GL_VERTEX_PROGRAM_ARB:\n");
203 else if (target
== GL_FRAGMENT_PROGRAM_ARB
) {
204 printf(" GL_FRAGMENT_PROGRAM_ARB:\n");
207 return; /* something's wrong */
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]);
216 #endif /* GL_ARB_vertex_program / GL_ARB_fragment_program */
221 * Print interesting limits for vertex/fragment shaders.
224 print_shader_limits(GLenum target
)
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" },
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" },
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]);
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]);
279 * Print interesting OpenGL implementation limits.
282 print_limits(const char *extensions
)
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" },
314 #if defined(GLX_NV_texture_rectangle)
315 { 1, GL_MAX_RECTANGLE_TEXTURE_SIZE_NV
, "GL_MAX_RECTANGLE_TEXTURE_SIZE_NV" },
317 #if defined(GL_ARB_texture_compression)
318 { 1, GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB
, "GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB" },
320 #if defined(GL_ARB_multitexture)
321 { 1, GL_MAX_TEXTURE_UNITS_ARB
, "GL_MAX_TEXTURE_UNITS_ARB" },
323 #if defined(GL_EXT_texture_lod_bias)
324 { 1, GL_MAX_TEXTURE_LOD_BIAS_EXT
, "GL_MAX_TEXTURE_LOD_BIAS_EXT" },
326 #if defined(GL_EXT_texture_filter_anisotropic)
327 { 1, GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT
, "GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT" },
329 #if defined(GL_ARB_draw_buffers)
330 { 1, GL_MAX_DRAW_BUFFERS_ARB
, "GL_MAX_DRAW_BUFFERS_ARB" },
332 { 0, (GLenum
) 0, NULL
}
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]);
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]);
354 #if defined(GL_ARB_vertex_program)
355 if (strstr(extensions
, "GL_ARB_vertex_program")) {
356 print_program_limits(GL_VERTEX_PROGRAM_ARB
);
359 #if defined(GL_ARB_fragment_program)
360 if (strstr(extensions
, "GL_ARB_fragment_program")) {
361 print_program_limits(GL_FRAGMENT_PROGRAM_ARB
);
364 #if defined(GL_ARB_vertex_shader)
365 if (strstr(extensions
, "GL_ARB_vertex_shader")) {
366 print_shader_limits(GL_VERTEX_SHADER_ARB
);
369 #if defined(GL_ARB_fragment_shader)
370 if (strstr(extensions
, "GL_ARB_fragment_shader")) {
371 print_shader_limits(GL_FRAGMENT_SHADER_ARB
);
378 print_screen_info(Display
*dpy
, int scrnum
, Bool allowDirect
, GLboolean limits
)
381 int attribSingle
[] = {
387 int attribDouble
[] = {
395 XSetWindowAttributes attr
;
398 GLXContext ctx
= NULL
;
399 XVisualInfo
*visinfo
;
400 int width
= 100, height
= 100;
402 root
= RootWindow(dpy
, scrnum
);
404 visinfo
= glXChooseVisual(dpy
, scrnum
, attribSingle
);
406 visinfo
= glXChooseVisual(dpy
, scrnum
, attribDouble
);
409 ctx
= glXCreateContext( dpy
, visinfo
, NULL
, allowDirect
);
411 #ifdef GLX_VERSION_1_3
413 int fbAttribSingle
[] = {
414 GLX_RENDER_TYPE
, GLX_RGBA_BIT
,
418 GLX_DOUBLEBUFFER
, GL_TRUE
,
420 int fbAttribDouble
[] = {
421 GLX_RENDER_TYPE
, GLX_RGBA_BIT
,
426 GLXFBConfig
*configs
= NULL
;
430 configs
= glXChooseFBConfig(dpy
, scrnum
, fbAttribSingle
, &nConfigs
);
432 configs
= glXChooseFBConfig(dpy
, scrnum
, fbAttribDouble
, &nConfigs
);
435 visinfo
= glXGetVisualFromFBConfig(dpy
, configs
[0]);
436 ctx
= glXCreateNewContext(dpy
, configs
[0], GLX_RGBA_TYPE
, NULL
, allowDirect
);
443 fprintf(stderr
, "Error: couldn't find RGB GLX visual or fbconfig\n");
448 fprintf(stderr
, "Error: glXCreateContext failed\n");
450 XDestroyWindow(dpy
, win
);
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
);
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
);
477 char *displayName
= NULL
;
478 char *colon
= NULL
, *period
= NULL
;
480 if (! glXQueryVersion( dpy
, & glxVersionMajor
, & glxVersionMinor
)) {
481 fprintf(stderr
, "Error: glXQueryVersion failed\n");
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");
490 strcpy(displayName
, DisplayString(dpy
));
491 colon
= strrchr(displayName
, ':');
493 period
= strchr(colon
, '.');
497 printf("display: %s screen: %d\n", displayName
, scrnum
);
499 printf("direct rendering: ");
500 if (glXIsDirect(dpy
, ctx
)) {
504 printf("No (-i specified)\n");
505 } else if (getenv("LIBGL_ALWAYS_INDIRECT")) {
506 printf("No (LIBGL_ALWAYS_INDIRECT set)\n");
508 printf("No (If you want to find out why, try setting "
509 "LIBGL_DEBUG=verbose)\n");
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 printf("OpenGL extensions:\n");
527 print_extension_list(glExtensions
);
529 print_limits(glExtensions
);
532 fprintf(stderr
, "Error: glXMakeCurrent failed\n");
535 glXDestroyContext(dpy
, ctx
);
537 XDestroyWindow(dpy
, win
);
542 visual_class_name(int cls
)
546 return "StaticColor";
548 return "PseudoColor";
556 return "DirectColor";
564 visual_class_abbrev(int cls
)
585 visual_render_type_name(int type
)
590 case GLX_COLOR_INDEX_BIT
:
592 case GLX_RGBA_BIT
| GLX_COLOR_INDEX_BIT
:
600 get_visual_attribs(Display
*dpy
, XVisualInfo
*vInfo
,
601 struct visual_attribs
*attribs
)
603 const char *ext
= glXQueryExtensionsString(dpy
, vInfo
->screen
);
606 memset(attribs
, 0, sizeof(struct visual_attribs
));
608 attribs
->id
= vInfo
->visualid
;
609 #if defined(__cplusplus) || defined(c_plusplus)
610 attribs
->klass
= vInfo
->c_class
;
612 attribs
->klass
= vInfo
->class;
614 attribs
->depth
= vInfo
->depth
;
615 attribs
->redMask
= vInfo
->red_mask
;
616 attribs
->greenMask
= vInfo
->green_mask
;
617 attribs
->blueMask
= vInfo
->blue_mask
;
618 attribs
->colormapSize
= vInfo
->colormap_size
;
619 attribs
->bitsPerRGB
= vInfo
->bits_per_rgb
;
621 if (glXGetConfig(dpy
, vInfo
, GLX_USE_GL
, &attribs
->supportsGL
) != 0 ||
622 !attribs
->supportsGL
)
624 glXGetConfig(dpy
, vInfo
, GLX_BUFFER_SIZE
, &attribs
->bufferSize
);
625 glXGetConfig(dpy
, vInfo
, GLX_LEVEL
, &attribs
->level
);
626 glXGetConfig(dpy
, vInfo
, GLX_RGBA
, &rgba
);
628 attribs
->render_type
= GLX_RGBA_BIT
;
630 attribs
->render_type
= GLX_COLOR_INDEX_BIT
;
632 glXGetConfig(dpy
, vInfo
, GLX_DOUBLEBUFFER
, &attribs
->doubleBuffer
);
633 glXGetConfig(dpy
, vInfo
, GLX_STEREO
, &attribs
->stereo
);
634 glXGetConfig(dpy
, vInfo
, GLX_AUX_BUFFERS
, &attribs
->auxBuffers
);
635 glXGetConfig(dpy
, vInfo
, GLX_RED_SIZE
, &attribs
->redSize
);
636 glXGetConfig(dpy
, vInfo
, GLX_GREEN_SIZE
, &attribs
->greenSize
);
637 glXGetConfig(dpy
, vInfo
, GLX_BLUE_SIZE
, &attribs
->blueSize
);
638 glXGetConfig(dpy
, vInfo
, GLX_ALPHA_SIZE
, &attribs
->alphaSize
);
639 glXGetConfig(dpy
, vInfo
, GLX_DEPTH_SIZE
, &attribs
->depthSize
);
640 glXGetConfig(dpy
, vInfo
, GLX_STENCIL_SIZE
, &attribs
->stencilSize
);
641 glXGetConfig(dpy
, vInfo
, GLX_ACCUM_RED_SIZE
, &attribs
->accumRedSize
);
642 glXGetConfig(dpy
, vInfo
, GLX_ACCUM_GREEN_SIZE
, &attribs
->accumGreenSize
);
643 glXGetConfig(dpy
, vInfo
, GLX_ACCUM_BLUE_SIZE
, &attribs
->accumBlueSize
);
644 glXGetConfig(dpy
, vInfo
, GLX_ACCUM_ALPHA_SIZE
, &attribs
->accumAlphaSize
);
646 /* get transparent pixel stuff */
647 glXGetConfig(dpy
, vInfo
,GLX_TRANSPARENT_TYPE
, &attribs
->transparentType
);
648 if (attribs
->transparentType
== GLX_TRANSPARENT_RGB
) {
649 glXGetConfig(dpy
, vInfo
, GLX_TRANSPARENT_RED_VALUE
, &attribs
->transparentRedValue
);
650 glXGetConfig(dpy
, vInfo
, GLX_TRANSPARENT_GREEN_VALUE
, &attribs
->transparentGreenValue
);
651 glXGetConfig(dpy
, vInfo
, GLX_TRANSPARENT_BLUE_VALUE
, &attribs
->transparentBlueValue
);
652 glXGetConfig(dpy
, vInfo
, GLX_TRANSPARENT_ALPHA_VALUE
, &attribs
->transparentAlphaValue
);
654 else if (attribs
->transparentType
== GLX_TRANSPARENT_INDEX
) {
655 glXGetConfig(dpy
, vInfo
, GLX_TRANSPARENT_INDEX_VALUE
, &attribs
->transparentIndexValue
);
658 /* multisample attribs */
659 #ifdef GLX_ARB_multisample
660 if (ext
&& strstr(ext
, "GLX_ARB_multisample")) {
661 glXGetConfig(dpy
, vInfo
, GLX_SAMPLE_BUFFERS_ARB
, &attribs
->numMultisample
);
662 glXGetConfig(dpy
, vInfo
, GLX_SAMPLES_ARB
, &attribs
->numSamples
);
666 attribs
->numSamples
= 0;
667 attribs
->numMultisample
= 0;
670 #if defined(GLX_EXT_visual_rating)
671 if (ext
&& strstr(ext
, "GLX_EXT_visual_rating")) {
672 glXGetConfig(dpy
, vInfo
, GLX_VISUAL_CAVEAT_EXT
, &attribs
->visualCaveat
);
675 attribs
->visualCaveat
= GLX_NONE_EXT
;
678 attribs
->visualCaveat
= 0;
684 #ifdef GLX_VERSION_1_3
687 glx_token_to_visual_class(int visual_type
)
689 switch (visual_type
) {
692 case GLX_DIRECT_COLOR
:
694 case GLX_PSEUDO_COLOR
:
696 case GLX_STATIC_COLOR
:
700 case GLX_STATIC_GRAY
:
709 get_fbconfig_attribs(Display
*dpy
, GLXFBConfig fbconfig
,
710 struct visual_attribs
*attribs
)
714 memset(attribs
, 0, sizeof(struct visual_attribs
));
716 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_FBCONFIG_ID
, &attribs
->id
);
719 attribs
->depth
= vInfo
->depth
;
720 attribs
->redMask
= vInfo
->red_mask
;
721 attribs
->greenMask
= vInfo
->green_mask
;
722 attribs
->blueMask
= vInfo
->blue_mask
;
723 attribs
->colormapSize
= vInfo
->colormap_size
;
724 attribs
->bitsPerRGB
= vInfo
->bits_per_rgb
;
727 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_X_VISUAL_TYPE
, &visual_type
);
728 attribs
->klass
= glx_token_to_visual_class(visual_type
);
730 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_BUFFER_SIZE
, &attribs
->bufferSize
);
731 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_LEVEL
, &attribs
->level
);
732 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_RENDER_TYPE
, &attribs
->render_type
);
733 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_DOUBLEBUFFER
, &attribs
->doubleBuffer
);
734 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_STEREO
, &attribs
->stereo
);
735 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_AUX_BUFFERS
, &attribs
->auxBuffers
);
737 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_RED_SIZE
, &attribs
->redSize
);
738 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_GREEN_SIZE
, &attribs
->greenSize
);
739 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_BLUE_SIZE
, &attribs
->blueSize
);
740 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_ALPHA_SIZE
, &attribs
->alphaSize
);
741 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_DEPTH_SIZE
, &attribs
->depthSize
);
742 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_STENCIL_SIZE
, &attribs
->stencilSize
);
744 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_ACCUM_RED_SIZE
, &attribs
->accumRedSize
);
745 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_ACCUM_GREEN_SIZE
, &attribs
->accumGreenSize
);
746 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_ACCUM_BLUE_SIZE
, &attribs
->accumBlueSize
);
747 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_ACCUM_ALPHA_SIZE
, &attribs
->accumAlphaSize
);
749 /* get transparent pixel stuff */
750 glXGetFBConfigAttrib(dpy
, fbconfig
,GLX_TRANSPARENT_TYPE
, &attribs
->transparentType
);
751 if (attribs
->transparentType
== GLX_TRANSPARENT_RGB
) {
752 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_TRANSPARENT_RED_VALUE
, &attribs
->transparentRedValue
);
753 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_TRANSPARENT_GREEN_VALUE
, &attribs
->transparentGreenValue
);
754 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_TRANSPARENT_BLUE_VALUE
, &attribs
->transparentBlueValue
);
755 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_TRANSPARENT_ALPHA_VALUE
, &attribs
->transparentAlphaValue
);
757 else if (attribs
->transparentType
== GLX_TRANSPARENT_INDEX
) {
758 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_TRANSPARENT_INDEX_VALUE
, &attribs
->transparentIndexValue
);
761 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_SAMPLE_BUFFERS
, &attribs
->numMultisample
);
762 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_SAMPLES
, &attribs
->numSamples
);
763 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_CONFIG_CAVEAT
, &attribs
->visualCaveat
);
773 print_visual_attribs_verbose(const struct visual_attribs
*attribs
)
775 printf("Visual ID: %x depth=%d class=%s\n",
776 attribs
->id
, attribs
->depth
, visual_class_name(attribs
->klass
));
777 printf(" bufferSize=%d level=%d renderType=%s doubleBuffer=%d stereo=%d\n",
778 attribs
->bufferSize
, attribs
->level
,
779 visual_render_type_name(attribs
->render_type
),
780 attribs
->doubleBuffer
, attribs
->stereo
);
781 printf(" rgba: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n",
782 attribs
->redSize
, attribs
->greenSize
,
783 attribs
->blueSize
, attribs
->alphaSize
);
784 printf(" auxBuffers=%d depthSize=%d stencilSize=%d\n",
785 attribs
->auxBuffers
, attribs
->depthSize
, attribs
->stencilSize
);
786 printf(" accum: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n",
787 attribs
->accumRedSize
, attribs
->accumGreenSize
,
788 attribs
->accumBlueSize
, attribs
->accumAlphaSize
);
789 printf(" multiSample=%d multiSampleBuffers=%d\n",
790 attribs
->numSamples
, attribs
->numMultisample
);
791 #ifdef GLX_EXT_visual_rating
792 if (attribs
->visualCaveat
== GLX_NONE_EXT
|| attribs
->visualCaveat
== 0)
793 printf(" visualCaveat=None\n");
794 else if (attribs
->visualCaveat
== GLX_SLOW_VISUAL_EXT
)
795 printf(" visualCaveat=Slow\n");
796 else if (attribs
->visualCaveat
== GLX_NON_CONFORMANT_VISUAL_EXT
)
797 printf(" visualCaveat=Nonconformant\n");
799 if (attribs
->transparentType
== GLX_NONE
) {
800 printf(" Opaque.\n");
802 else if (attribs
->transparentType
== GLX_TRANSPARENT_RGB
) {
803 printf(" Transparent RGB: Red=%d Green=%d Blue=%d Alpha=%d\n",attribs
->transparentRedValue
,attribs
->transparentGreenValue
,attribs
->transparentBlueValue
,attribs
->transparentAlphaValue
);
805 else if (attribs
->transparentType
== GLX_TRANSPARENT_INDEX
) {
806 printf(" Transparent index=%d\n",attribs
->transparentIndexValue
);
812 print_visual_attribs_short_header(void)
814 printf(" visual x bf lv rg d st colorbuffer ax dp st accumbuffer ms cav\n");
815 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");
816 printf("----------------------------------------------------------------------\n");
821 print_visual_attribs_short(const struct visual_attribs
*attribs
)
824 #ifdef GLX_EXT_visual_rating
825 if (attribs
->visualCaveat
== GLX_NONE_EXT
|| attribs
->visualCaveat
== 0)
827 else if (attribs
->visualCaveat
== GLX_SLOW_VISUAL_EXT
)
829 else if (attribs
->visualCaveat
== GLX_NON_CONFORMANT_VISUAL_EXT
)
837 printf("0x%02x %2d %2s %2d %2d %2d %c%c %c %c %2d %2d %2d %2d %2d %2d %2d",
840 visual_class_abbrev(attribs
->klass
),
841 attribs
->transparentType
!= GLX_NONE
,
844 (attribs
->render_type
& GLX_RGBA_BIT
) ? 'r' : ' ',
845 (attribs
->render_type
& GLX_COLOR_INDEX_BIT
) ? 'c' : ' ',
846 attribs
->doubleBuffer
? 'y' : '.',
847 attribs
->stereo
? 'y' : '.',
848 attribs
->redSize
, attribs
->greenSize
,
849 attribs
->blueSize
, attribs
->alphaSize
,
855 printf(" %2d %2d %2d %2d %2d %1d %s\n",
856 attribs
->accumRedSize
, attribs
->accumGreenSize
,
857 attribs
->accumBlueSize
, attribs
->accumAlphaSize
,
858 attribs
->numSamples
, attribs
->numMultisample
,
865 print_visual_attribs_long_header(void)
867 printf("Vis Vis Visual Trans buff lev render DB ste r g b a aux dep ste accum buffers MS MS\n");
868 printf(" ID Depth Type parent size el type reo sz sz sz sz buf th ncl r g b a num bufs\n");
869 printf("----------------------------------------------------------------------------------------------------\n");
874 print_visual_attribs_long(const struct visual_attribs
*attribs
)
876 printf("0x%2x %2d %-11s %2d %2d %2d %4s %3d %3d %3d %3d %3d %3d",
879 visual_class_name(attribs
->klass
),
880 attribs
->transparentType
!= GLX_NONE
,
883 visual_render_type_name(attribs
->render_type
),
884 attribs
->doubleBuffer
,
886 attribs
->redSize
, attribs
->greenSize
,
887 attribs
->blueSize
, attribs
->alphaSize
890 printf(" %3d %4d %2d %3d %3d %3d %3d %2d %2d\n",
893 attribs
->stencilSize
,
894 attribs
->accumRedSize
, attribs
->accumGreenSize
,
895 attribs
->accumBlueSize
, attribs
->accumAlphaSize
,
896 attribs
->numSamples
, attribs
->numMultisample
902 print_visual_info(Display
*dpy
, int scrnum
, InfoMode mode
)
904 XVisualInfo theTemplate
;
905 XVisualInfo
*visuals
;
906 int numVisuals
, numGlxVisuals
;
909 struct visual_attribs attribs
;
911 /* get list of all visuals on this screen */
912 theTemplate
.screen
= scrnum
;
913 mask
= VisualScreenMask
;
914 visuals
= XGetVisualInfo(dpy
, mask
, &theTemplate
, &numVisuals
);
917 for (i
= 0; i
< numVisuals
; i
++) {
918 if (get_visual_attribs(dpy
, &visuals
[i
], &attribs
))
922 if (numGlxVisuals
== 0)
925 printf("%d GLX Visuals\n", numGlxVisuals
);
928 print_visual_attribs_short_header();
929 else if (mode
== Wide
)
930 print_visual_attribs_long_header();
932 for (i
= 0; i
< numVisuals
; i
++) {
933 if (!get_visual_attribs(dpy
, &visuals
[i
], &attribs
))
937 print_visual_attribs_verbose(&attribs
);
938 else if (mode
== Normal
)
939 print_visual_attribs_short(&attribs
);
940 else if (mode
== Wide
)
941 print_visual_attribs_long(&attribs
);
948 #ifdef GLX_VERSION_1_3
951 print_fbconfig_info(Display
*dpy
, int scrnum
, InfoMode mode
)
954 struct visual_attribs attribs
;
955 GLXFBConfig
*fbconfigs
;
958 /* get list of all fbconfigs on this screen */
959 fbconfigs
= glXGetFBConfigs(dpy
, scrnum
, &numFBConfigs
);
961 if (numFBConfigs
== 0)
964 printf("%d GLXFBConfigs:\n", numFBConfigs
);
966 print_visual_attribs_short_header();
967 else if (mode
== Wide
)
968 print_visual_attribs_long_header();
970 for (i
= 0; i
< numFBConfigs
; i
++) {
971 get_fbconfig_attribs(dpy
, fbconfigs
[i
], &attribs
);
974 print_visual_attribs_verbose(&attribs
);
975 else if (mode
== Normal
)
976 print_visual_attribs_short(&attribs
);
977 else if (mode
== Wide
)
978 print_visual_attribs_long(&attribs
);
988 * Stand-alone Mesa doesn't really implement the GLX protocol so it
989 * doesn't really know the GLX attributes associated with an X visual.
990 * The first time a visual is presented to Mesa's pseudo-GLX it
991 * attaches ancilliary buffers to it (like depth and stencil).
992 * But that usually only works if glXChooseVisual is used.
993 * This function calls glXChooseVisual() to sort of "prime the pump"
994 * for Mesa's GLX so that the visuals that get reported actually
995 * reflect what applications will see.
996 * This has no effect when using true GLX.
999 mesa_hack(Display
*dpy
, int scrnum
)
1001 static int attribs
[] = {
1007 GLX_STENCIL_SIZE
, 1,
1008 GLX_ACCUM_RED_SIZE
, 1,
1009 GLX_ACCUM_GREEN_SIZE
, 1,
1010 GLX_ACCUM_BLUE_SIZE
, 1,
1011 GLX_ACCUM_ALPHA_SIZE
, 1,
1015 XVisualInfo
*visinfo
;
1017 visinfo
= glXChooseVisual(dpy
, scrnum
, attribs
);
1024 * Examine all visuals to find the so-called best one.
1025 * We prefer deepest RGBA buffer with depth, stencil and accum
1026 * that has no caveats.
1029 find_best_visual(Display
*dpy
, int scrnum
)
1031 XVisualInfo theTemplate
;
1032 XVisualInfo
*visuals
;
1036 struct visual_attribs bestVis
;
1038 /* get list of all visuals on this screen */
1039 theTemplate
.screen
= scrnum
;
1040 mask
= VisualScreenMask
;
1041 visuals
= XGetVisualInfo(dpy
, mask
, &theTemplate
, &numVisuals
);
1043 /* init bestVis with first visual info */
1044 get_visual_attribs(dpy
, &visuals
[0], &bestVis
);
1046 /* try to find a "better" visual */
1047 for (i
= 1; i
< numVisuals
; i
++) {
1048 struct visual_attribs vis
;
1050 get_visual_attribs(dpy
, &visuals
[i
], &vis
);
1052 /* always skip visuals with caveats */
1053 if (vis
.visualCaveat
!= GLX_NONE_EXT
)
1056 /* see if this vis is better than bestVis */
1057 if ((!bestVis
.supportsGL
&& vis
.supportsGL
) ||
1058 (bestVis
.visualCaveat
!= GLX_NONE_EXT
) ||
1059 (!(bestVis
.render_type
& GLX_RGBA_BIT
) && (vis
.render_type
& GLX_RGBA_BIT
)) ||
1060 (!bestVis
.doubleBuffer
&& vis
.doubleBuffer
) ||
1061 (bestVis
.redSize
< vis
.redSize
) ||
1062 (bestVis
.greenSize
< vis
.greenSize
) ||
1063 (bestVis
.blueSize
< vis
.blueSize
) ||
1064 (bestVis
.alphaSize
< vis
.alphaSize
) ||
1065 (bestVis
.depthSize
< vis
.depthSize
) ||
1066 (bestVis
.stencilSize
< vis
.stencilSize
) ||
1067 (bestVis
.accumRedSize
< vis
.accumRedSize
)) {
1068 /* found a better visual */
1082 printf("Usage: glxinfo [-v] [-t] [-h] [-i] [-b] [-display <dname>]\n");
1083 printf("\t-v: Print visuals info in verbose form.\n");
1084 printf("\t-t: Print verbose table.\n");
1085 printf("\t-display <dname>: Print GLX visuals on specified server.\n");
1086 printf("\t-h: This information.\n");
1087 printf("\t-i: Force an indirect rendering context.\n");
1088 printf("\t-b: Find the 'best' visual and print it's number.\n");
1089 printf("\t-l: Print interesting OpenGL limits.\n");
1094 main(int argc
, char *argv
[])
1096 char *displayName
= NULL
;
1098 int numScreens
, scrnum
;
1099 InfoMode mode
= Normal
;
1100 GLboolean findBest
= GL_FALSE
;
1101 GLboolean limits
= GL_FALSE
;
1102 Bool allowDirect
= True
;
1105 for (i
= 1; i
< argc
; i
++) {
1106 if (strcmp(argv
[i
], "-display") == 0 && i
+ 1 < argc
) {
1107 displayName
= argv
[i
+ 1];
1110 else if (strcmp(argv
[i
], "-t") == 0) {
1113 else if (strcmp(argv
[i
], "-v") == 0) {
1116 else if (strcmp(argv
[i
], "-b") == 0) {
1119 else if (strcmp(argv
[i
], "-i") == 0) {
1120 allowDirect
= False
;
1122 else if (strcmp(argv
[i
], "-l") == 0) {
1125 else if (strcmp(argv
[i
], "-h") == 0) {
1130 printf("Unknown option `%s'\n", argv
[i
]);
1136 dpy
= XOpenDisplay(displayName
);
1138 fprintf(stderr
, "Error: unable to open display %s\n", XDisplayName(displayName
));
1145 b
= find_best_visual(dpy
, 0);
1149 numScreens
= ScreenCount(dpy
);
1150 print_display_info(dpy
);
1151 for (scrnum
= 0; scrnum
< numScreens
; scrnum
++) {
1152 mesa_hack(dpy
, scrnum
);
1153 print_screen_info(dpy
, scrnum
, allowDirect
, limits
);
1155 print_visual_info(dpy
, scrnum
, mode
);
1156 #ifdef GLX_VERSION_1_3
1157 print_fbconfig_info(dpy
, scrnum
, mode
);
1159 if (scrnum
+ 1 < numScreens
)