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: %s\n", glXIsDirect(dpy
, ctx
) ? "Yes" : "No");
460 printf("server glx vendor string: %s\n", serverVendor
);
461 printf("server glx version string: %s\n", serverVersion
);
462 printf("server glx extensions:\n");
463 print_extension_list(serverExtensions
);
464 printf("client glx vendor string: %s\n", clientVendor
);
465 printf("client glx version string: %s\n", clientVersion
);
466 printf("client glx extensions:\n");
467 print_extension_list(clientExtensions
);
468 printf("GLX version: %u.%u\n", glxVersionMajor
, glxVersionMinor
);
469 printf("GLX extensions:\n");
470 print_extension_list(glxExtensions
);
471 printf("OpenGL vendor string: %s\n", glVendor
);
472 printf("OpenGL renderer string: %s\n", glRenderer
);
473 printf("OpenGL version string: %s\n", glVersion
);
474 printf("OpenGL extensions:\n");
475 print_extension_list(glExtensions
);
477 print_limits(glExtensions
);
480 fprintf(stderr
, "Error: glXMakeCurrent failed\n");
483 glXDestroyContext(dpy
, ctx
);
485 XDestroyWindow(dpy
, win
);
490 visual_class_name(int cls
)
494 return "StaticColor";
496 return "PseudoColor";
504 return "DirectColor";
512 visual_class_abbrev(int cls
)
534 get_visual_attribs(Display
*dpy
, XVisualInfo
*vInfo
,
535 struct visual_attribs
*attribs
)
537 const char *ext
= glXQueryExtensionsString(dpy
, vInfo
->screen
);
539 memset(attribs
, 0, sizeof(struct visual_attribs
));
541 attribs
->id
= vInfo
->visualid
;
542 #if defined(__cplusplus) || defined(c_plusplus)
543 attribs
->klass
= vInfo
->c_class
;
545 attribs
->klass
= vInfo
->class;
547 attribs
->depth
= vInfo
->depth
;
548 attribs
->redMask
= vInfo
->red_mask
;
549 attribs
->greenMask
= vInfo
->green_mask
;
550 attribs
->blueMask
= vInfo
->blue_mask
;
551 attribs
->colormapSize
= vInfo
->colormap_size
;
552 attribs
->bitsPerRGB
= vInfo
->bits_per_rgb
;
554 if (glXGetConfig(dpy
, vInfo
, GLX_USE_GL
, &attribs
->supportsGL
) != 0)
556 glXGetConfig(dpy
, vInfo
, GLX_BUFFER_SIZE
, &attribs
->bufferSize
);
557 glXGetConfig(dpy
, vInfo
, GLX_LEVEL
, &attribs
->level
);
558 glXGetConfig(dpy
, vInfo
, GLX_RGBA
, &attribs
->rgba
);
559 glXGetConfig(dpy
, vInfo
, GLX_DOUBLEBUFFER
, &attribs
->doubleBuffer
);
560 glXGetConfig(dpy
, vInfo
, GLX_STEREO
, &attribs
->stereo
);
561 glXGetConfig(dpy
, vInfo
, GLX_AUX_BUFFERS
, &attribs
->auxBuffers
);
562 glXGetConfig(dpy
, vInfo
, GLX_RED_SIZE
, &attribs
->redSize
);
563 glXGetConfig(dpy
, vInfo
, GLX_GREEN_SIZE
, &attribs
->greenSize
);
564 glXGetConfig(dpy
, vInfo
, GLX_BLUE_SIZE
, &attribs
->blueSize
);
565 glXGetConfig(dpy
, vInfo
, GLX_ALPHA_SIZE
, &attribs
->alphaSize
);
566 glXGetConfig(dpy
, vInfo
, GLX_DEPTH_SIZE
, &attribs
->depthSize
);
567 glXGetConfig(dpy
, vInfo
, GLX_STENCIL_SIZE
, &attribs
->stencilSize
);
568 glXGetConfig(dpy
, vInfo
, GLX_ACCUM_RED_SIZE
, &attribs
->accumRedSize
);
569 glXGetConfig(dpy
, vInfo
, GLX_ACCUM_GREEN_SIZE
, &attribs
->accumGreenSize
);
570 glXGetConfig(dpy
, vInfo
, GLX_ACCUM_BLUE_SIZE
, &attribs
->accumBlueSize
);
571 glXGetConfig(dpy
, vInfo
, GLX_ACCUM_ALPHA_SIZE
, &attribs
->accumAlphaSize
);
573 /* get transparent pixel stuff */
574 glXGetConfig(dpy
, vInfo
,GLX_TRANSPARENT_TYPE
, &attribs
->transparentType
);
575 if (attribs
->transparentType
== GLX_TRANSPARENT_RGB
) {
576 glXGetConfig(dpy
, vInfo
, GLX_TRANSPARENT_RED_VALUE
, &attribs
->transparentRedValue
);
577 glXGetConfig(dpy
, vInfo
, GLX_TRANSPARENT_GREEN_VALUE
, &attribs
->transparentGreenValue
);
578 glXGetConfig(dpy
, vInfo
, GLX_TRANSPARENT_BLUE_VALUE
, &attribs
->transparentBlueValue
);
579 glXGetConfig(dpy
, vInfo
, GLX_TRANSPARENT_ALPHA_VALUE
, &attribs
->transparentAlphaValue
);
581 else if (attribs
->transparentType
== GLX_TRANSPARENT_INDEX
) {
582 glXGetConfig(dpy
, vInfo
, GLX_TRANSPARENT_INDEX_VALUE
, &attribs
->transparentIndexValue
);
585 /* multisample attribs */
586 #ifdef GLX_ARB_multisample
587 if (ext
&& strstr(ext
, "GLX_ARB_multisample") == 0) {
588 glXGetConfig(dpy
, vInfo
, GLX_SAMPLE_BUFFERS_ARB
, &attribs
->numMultisample
);
589 glXGetConfig(dpy
, vInfo
, GLX_SAMPLES_ARB
, &attribs
->numSamples
);
593 attribs
->numSamples
= 0;
594 attribs
->numMultisample
= 0;
597 #if defined(GLX_EXT_visual_rating)
598 if (ext
&& strstr(ext
, "GLX_EXT_visual_rating")) {
599 glXGetConfig(dpy
, vInfo
, GLX_VISUAL_CAVEAT_EXT
, &attribs
->visualCaveat
);
602 attribs
->visualCaveat
= GLX_NONE_EXT
;
605 attribs
->visualCaveat
= 0;
611 print_visual_attribs_verbose(const struct visual_attribs
*attribs
)
613 printf("Visual ID: %x depth=%d class=%s\n",
614 attribs
->id
, attribs
->depth
, visual_class_name(attribs
->klass
));
615 printf(" bufferSize=%d level=%d renderType=%s doubleBuffer=%d stereo=%d\n",
616 attribs
->bufferSize
, attribs
->level
, attribs
->rgba
? "rgba" : "ci",
617 attribs
->doubleBuffer
, attribs
->stereo
);
618 printf(" rgba: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n",
619 attribs
->redSize
, attribs
->greenSize
,
620 attribs
->blueSize
, attribs
->alphaSize
);
621 printf(" auxBuffers=%d depthSize=%d stencilSize=%d\n",
622 attribs
->auxBuffers
, attribs
->depthSize
, attribs
->stencilSize
);
623 printf(" accum: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n",
624 attribs
->accumRedSize
, attribs
->accumGreenSize
,
625 attribs
->accumBlueSize
, attribs
->accumAlphaSize
);
626 printf(" multiSample=%d multiSampleBuffers=%d\n",
627 attribs
->numSamples
, attribs
->numMultisample
);
628 #ifdef GLX_EXT_visual_rating
629 if (attribs
->visualCaveat
== GLX_NONE_EXT
|| attribs
->visualCaveat
== 0)
630 printf(" visualCaveat=None\n");
631 else if (attribs
->visualCaveat
== GLX_SLOW_VISUAL_EXT
)
632 printf(" visualCaveat=Slow\n");
633 else if (attribs
->visualCaveat
== GLX_NON_CONFORMANT_VISUAL_EXT
)
634 printf(" visualCaveat=Nonconformant\n");
636 if (attribs
->transparentType
== GLX_NONE
) {
637 printf(" Opaque.\n");
639 else if (attribs
->transparentType
== GLX_TRANSPARENT_RGB
) {
640 printf(" Transparent RGB: Red=%d Green=%d Blue=%d Alpha=%d\n",attribs
->transparentRedValue
,attribs
->transparentGreenValue
,attribs
->transparentBlueValue
,attribs
->transparentAlphaValue
);
642 else if (attribs
->transparentType
== GLX_TRANSPARENT_INDEX
) {
643 printf(" Transparent index=%d\n",attribs
->transparentIndexValue
);
649 print_visual_attribs_short_header(void)
651 printf(" visual x bf lv rg d st colorbuffer ax dp st accumbuffer ms cav\n");
652 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");
653 printf("----------------------------------------------------------------------\n");
658 print_visual_attribs_short(const struct visual_attribs
*attribs
)
661 #ifdef GLX_EXT_visual_rating
662 if (attribs
->visualCaveat
== GLX_NONE_EXT
|| attribs
->visualCaveat
== 0)
664 else if (attribs
->visualCaveat
== GLX_SLOW_VISUAL_EXT
)
666 else if (attribs
->visualCaveat
== GLX_NON_CONFORMANT_VISUAL_EXT
)
674 printf("0x%2x %2d %2s %2d %2d %2d %1s %2s %2s %2d %2d %2d %2d %2d %2d %2d",
677 visual_class_abbrev(attribs
->klass
),
678 attribs
->transparentType
!= GLX_NONE
,
681 attribs
->rgba
? "r" : "c",
682 attribs
->doubleBuffer
? "y" : ".",
683 attribs
->stereo
? "y" : ".",
684 attribs
->redSize
, attribs
->greenSize
,
685 attribs
->blueSize
, attribs
->alphaSize
,
691 printf(" %2d %2d %2d %2d %2d %1d %s\n",
692 attribs
->accumRedSize
, attribs
->accumGreenSize
,
693 attribs
->accumBlueSize
, attribs
->accumAlphaSize
,
694 attribs
->numSamples
, attribs
->numMultisample
,
701 print_visual_attribs_long_header(void)
703 printf("Vis Vis Visual Trans buff lev render DB ste r g b a aux dep ste accum buffers MS MS\n");
704 printf(" ID Depth Type parent size el type reo sz sz sz sz buf th ncl r g b a num bufs\n");
705 printf("----------------------------------------------------------------------------------------------------\n");
710 print_visual_attribs_long(const struct visual_attribs
*attribs
)
712 printf("0x%2x %2d %-11s %2d %2d %2d %4s %3d %3d %3d %3d %3d %3d",
715 visual_class_name(attribs
->klass
),
716 attribs
->transparentType
!= GLX_NONE
,
719 attribs
->rgba
? "rgba" : "ci ",
720 attribs
->doubleBuffer
,
722 attribs
->redSize
, attribs
->greenSize
,
723 attribs
->blueSize
, attribs
->alphaSize
726 printf(" %3d %4d %2d %3d %3d %3d %3d %2d %2d\n",
729 attribs
->stencilSize
,
730 attribs
->accumRedSize
, attribs
->accumGreenSize
,
731 attribs
->accumBlueSize
, attribs
->accumAlphaSize
,
732 attribs
->numSamples
, attribs
->numMultisample
738 print_visual_info(Display
*dpy
, int scrnum
, InfoMode mode
)
740 XVisualInfo theTemplate
;
741 XVisualInfo
*visuals
;
746 /* get list of all visuals on this screen */
747 theTemplate
.screen
= scrnum
;
748 mask
= VisualScreenMask
;
749 visuals
= XGetVisualInfo(dpy
, mask
, &theTemplate
, &numVisuals
);
751 if (mode
== Verbose
) {
752 for (i
= 0; i
< numVisuals
; i
++) {
753 struct visual_attribs attribs
;
754 get_visual_attribs(dpy
, &visuals
[i
], &attribs
);
755 print_visual_attribs_verbose(&attribs
);
758 else if (mode
== Normal
) {
759 print_visual_attribs_short_header();
760 for (i
= 0; i
< numVisuals
; i
++) {
761 struct visual_attribs attribs
;
762 get_visual_attribs(dpy
, &visuals
[i
], &attribs
);
763 print_visual_attribs_short(&attribs
);
766 else if (mode
== Wide
) {
767 print_visual_attribs_long_header();
768 for (i
= 0; i
< numVisuals
; i
++) {
769 struct visual_attribs attribs
;
770 get_visual_attribs(dpy
, &visuals
[i
], &attribs
);
771 print_visual_attribs_long(&attribs
);
780 * Stand-alone Mesa doesn't really implement the GLX protocol so it
781 * doesn't really know the GLX attributes associated with an X visual.
782 * The first time a visual is presented to Mesa's pseudo-GLX it
783 * attaches ancilliary buffers to it (like depth and stencil).
784 * But that usually only works if glXChooseVisual is used.
785 * This function calls glXChooseVisual() to sort of "prime the pump"
786 * for Mesa's GLX so that the visuals that get reported actually
787 * reflect what applications will see.
788 * This has no effect when using true GLX.
791 mesa_hack(Display
*dpy
, int scrnum
)
793 static int attribs
[] = {
800 GLX_ACCUM_RED_SIZE
, 1,
801 GLX_ACCUM_GREEN_SIZE
, 1,
802 GLX_ACCUM_BLUE_SIZE
, 1,
803 GLX_ACCUM_ALPHA_SIZE
, 1,
807 XVisualInfo
*visinfo
;
809 visinfo
= glXChooseVisual(dpy
, scrnum
, attribs
);
816 * Examine all visuals to find the so-called best one.
817 * We prefer deepest RGBA buffer with depth, stencil and accum
818 * that has no caveats.
821 find_best_visual(Display
*dpy
, int scrnum
)
823 XVisualInfo theTemplate
;
824 XVisualInfo
*visuals
;
828 struct visual_attribs bestVis
;
830 /* get list of all visuals on this screen */
831 theTemplate
.screen
= scrnum
;
832 mask
= VisualScreenMask
;
833 visuals
= XGetVisualInfo(dpy
, mask
, &theTemplate
, &numVisuals
);
835 /* init bestVis with first visual info */
836 get_visual_attribs(dpy
, &visuals
[0], &bestVis
);
838 /* try to find a "better" visual */
839 for (i
= 1; i
< numVisuals
; i
++) {
840 struct visual_attribs vis
;
842 get_visual_attribs(dpy
, &visuals
[i
], &vis
);
844 /* always skip visuals with caveats */
845 if (vis
.visualCaveat
!= GLX_NONE_EXT
)
848 /* see if this vis is better than bestVis */
849 if ((!bestVis
.supportsGL
&& vis
.supportsGL
) ||
850 (bestVis
.visualCaveat
!= GLX_NONE_EXT
) ||
851 (!bestVis
.rgba
&& vis
.rgba
) ||
852 (!bestVis
.doubleBuffer
&& vis
.doubleBuffer
) ||
853 (bestVis
.redSize
< vis
.redSize
) ||
854 (bestVis
.greenSize
< vis
.greenSize
) ||
855 (bestVis
.blueSize
< vis
.blueSize
) ||
856 (bestVis
.alphaSize
< vis
.alphaSize
) ||
857 (bestVis
.depthSize
< vis
.depthSize
) ||
858 (bestVis
.stencilSize
< vis
.stencilSize
) ||
859 (bestVis
.accumRedSize
< vis
.accumRedSize
)) {
860 /* found a better visual */
874 printf("Usage: glxinfo [-v] [-t] [-h] [-i] [-b] [-display <dname>]\n");
875 printf("\t-v: Print visuals info in verbose form.\n");
876 printf("\t-t: Print verbose table.\n");
877 printf("\t-display <dname>: Print GLX visuals on specified server.\n");
878 printf("\t-h: This information.\n");
879 printf("\t-i: Force an indirect rendering context.\n");
880 printf("\t-b: Find the 'best' visual and print it's number.\n");
881 printf("\t-l: Print interesting OpenGL limits.\n");
886 main(int argc
, char *argv
[])
888 char *displayName
= NULL
;
890 int numScreens
, scrnum
;
891 InfoMode mode
= Normal
;
892 GLboolean findBest
= GL_FALSE
;
893 GLboolean limits
= GL_FALSE
;
894 Bool allowDirect
= True
;
897 for (i
= 1; i
< argc
; i
++) {
898 if (strcmp(argv
[i
], "-display") == 0 && i
+ 1 < argc
) {
899 displayName
= argv
[i
+ 1];
902 else if (strcmp(argv
[i
], "-t") == 0) {
905 else if (strcmp(argv
[i
], "-v") == 0) {
908 else if (strcmp(argv
[i
], "-b") == 0) {
911 else if (strcmp(argv
[i
], "-i") == 0) {
914 else if (strcmp(argv
[i
], "-l") == 0) {
917 else if (strcmp(argv
[i
], "-h") == 0) {
922 printf("Unknown option `%s'\n", argv
[i
]);
928 dpy
= XOpenDisplay(displayName
);
930 fprintf(stderr
, "Error: unable to open display %s\n", displayName
);
937 b
= find_best_visual(dpy
, 0);
941 numScreens
= ScreenCount(dpy
);
942 print_display_info(dpy
);
943 for (scrnum
= 0; scrnum
< numScreens
; scrnum
++) {
944 mesa_hack(dpy
, scrnum
);
945 print_screen_info(dpy
, scrnum
, allowDirect
, limits
);
947 print_visual_info(dpy
, scrnum
, mode
);
948 if (scrnum
+ 1 < numScreens
)