1 /* $Id: glxinfo.c,v 1.2 2000/01/27 16:43:56 brianp Exp $ */
4 * Copyright (C) 1999 Brian Paul All Rights Reserved.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 * This program is a work-alike of the IRIX glxinfo program.
27 * Command line options:
29 * -v print verbose information
30 * -display DisplayName specify the X display to interogate
32 * Brian Paul 26 January 2000
37 #include <X11/Xutil.h>
55 /* X visual attribs */
59 int redMask
, greenMask
, blueMask
;
63 /* GL visual attribs */
72 int redSize
, greenSize
, blueSize
, alphaSize
;
75 int accumRedSize
, accumGreenSize
, accumBlueSize
, accumAlphaSize
;
76 int numSamples
, numMultisample
;
81 * Print a list of extensions, with word-wrapping.
84 print_extension_list(const char *ext
)
86 const char *indentString
= " ";
98 if (ext
[j
] == ' ' || ext
[j
] == 0) {
99 /* found end of an extension name */
100 const int len
= j
- i
;
101 if (width
+ len
> max
) {
102 /* start a new line */
105 printf(indentString
);
107 /* print the extension name between ext[i] and ext[j] */
109 printf("%c", ext
[i
]);
112 /* either we're all done, or we'll continue with next extension */
131 print_screen_info(Display
*dpy
, int scrnum
)
134 int attrib
[] = { GLX_RGBA
,
139 XSetWindowAttributes attr
;
143 XVisualInfo
*visinfo
;
144 int width
= 100, height
= 100;
146 root
= RootWindow(dpy
, scrnum
);
148 visinfo
= glXChooseVisual(dpy
, scrnum
, attrib
);
150 fprintf(stderr
, "Error: couldn't find RGB GLX visual!\n");
154 attr
.background_pixel
= 0;
155 attr
.border_pixel
= 0;
156 attr
.colormap
= XCreateColormap( dpy
, root
, visinfo
->visual
, AllocNone
);
157 attr
.event_mask
= StructureNotifyMask
| ExposureMask
;
158 mask
= CWBackPixel
| CWBorderPixel
| CWColormap
| CWEventMask
;
159 win
= XCreateWindow(dpy
, root
, 0, 0, width
, height
,
160 0, visinfo
->depth
, InputOutput
,
161 visinfo
->visual
, mask
, &attr
);
163 ctx
= glXCreateContext( dpy
, visinfo
, NULL
, True
);
165 glXMakeCurrent( dpy
, win
, ctx
);
169 const char *serverVendor
= glXQueryServerString(dpy
, scrnum
, GLX_VENDOR
);
170 const char *serverVersion
= glXQueryServerString(dpy
, scrnum
, GLX_VERSION
);
171 const char *serverExtensions
= glXQueryServerString(dpy
, scrnum
, GLX_EXTENSIONS
);
172 const char *clientVersion
= glXGetClientString(dpy
, GLX_VERSION
);
173 const char *clientExtensions
= glXGetClientString(dpy
, GLX_EXTENSIONS
);
174 const char *glxExtensions
= glXQueryExtensionsString(dpy
, scrnum
);
175 const char *glVendor
= (const char *) glGetString(GL_VENDOR
);
176 const char *glRenderer
= (const char *) glGetString(GL_RENDERER
);
177 const char *glVersion
= (const char *) glGetString(GL_VERSION
);
178 const char *glExtensions
= (const char *) glGetString(GL_EXTENSIONS
);
179 const char *gluVersion
= (const char *) gluGetString(GLU_VERSION
);
180 const char *gluExtensions
= (const char *) gluGetString(GLU_EXTENSIONS
);
181 printf("display: %s screen:%d\n", DisplayString(dpy
), scrnum
);
182 printf("server glx vendor string: %s\n", serverVendor
);
183 printf("server glx version string: %s\n", serverVersion
);
184 printf("server glx extensions:\n");
185 print_extension_list(serverExtensions
);
186 printf("client glx version: %s\n", clientVersion
);
187 printf("client glx extensions:\n");
188 print_extension_list(clientExtensions
);
189 printf("GLX extensions:\n");
190 print_extension_list(glxExtensions
);
191 printf("OpenGL vendor string: %s\n", glVendor
);
192 printf("OpenGL renderer string: %s\n", glRenderer
);
193 printf("OpenGL version string: %s\n", glVersion
);
194 printf("OpenGL extensions:\n");
195 print_extension_list(glExtensions
);
196 printf("glu version: %s\n", gluVersion
);
197 printf("glu extensions:\n");
198 print_extension_list(gluExtensions
);
201 glXDestroyContext(dpy
, ctx
);
202 XDestroyWindow(dpy
, win
);
207 visual_class_name(int cls
)
211 return "StaticColor";
213 return "PseudoColor";
221 return "DirectColor";
229 visual_class_abbrev(int cls
)
251 get_visual_attribs(Display
*dpy
, XVisualInfo
*vInfo
,
252 struct visual_attribs
*attribs
)
254 attribs
->id
= vInfo
->visualid
;
255 #if defined(__cplusplus) || defined(c_plusplus)
256 attribs
->klass
= vInfo
->c_class
;
258 attribs
->klass
= vInfo
->class;
260 attribs
->depth
= vInfo
->depth
;
261 attribs
->redMask
= vInfo
->red_mask
;
262 attribs
->greenMask
= vInfo
->green_mask
;
263 attribs
->blueMask
= vInfo
->blue_mask
;
264 attribs
->colormapSize
= vInfo
->colormap_size
;
265 attribs
->bitsPerRGB
= vInfo
->bits_per_rgb
;
267 attribs
->transparent
= 0;
268 glXGetConfig(dpy
, vInfo
, GLX_USE_GL
, &attribs
->supportsGL
);
269 glXGetConfig(dpy
, vInfo
, GLX_BUFFER_SIZE
, &attribs
->bufferSize
);
270 glXGetConfig(dpy
, vInfo
, GLX_LEVEL
, &attribs
->level
);
271 glXGetConfig(dpy
, vInfo
, GLX_RGBA
, &attribs
->rgba
);
272 glXGetConfig(dpy
, vInfo
, GLX_DOUBLEBUFFER
, &attribs
->doubleBuffer
);
273 glXGetConfig(dpy
, vInfo
, GLX_STEREO
, &attribs
->stereo
);
274 glXGetConfig(dpy
, vInfo
, GLX_AUX_BUFFERS
, &attribs
->auxBuffers
);
275 glXGetConfig(dpy
, vInfo
, GLX_RED_SIZE
, &attribs
->redSize
);
276 glXGetConfig(dpy
, vInfo
, GLX_GREEN_SIZE
, &attribs
->greenSize
);
277 glXGetConfig(dpy
, vInfo
, GLX_BLUE_SIZE
, &attribs
->blueSize
);
278 glXGetConfig(dpy
, vInfo
, GLX_ALPHA_SIZE
, &attribs
->alphaSize
);
279 glXGetConfig(dpy
, vInfo
, GLX_DEPTH_SIZE
, &attribs
->depthSize
);
280 glXGetConfig(dpy
, vInfo
, GLX_STENCIL_SIZE
, &attribs
->stencilSize
);
281 glXGetConfig(dpy
, vInfo
, GLX_ACCUM_RED_SIZE
, &attribs
->accumRedSize
);
282 glXGetConfig(dpy
, vInfo
, GLX_ACCUM_GREEN_SIZE
, &attribs
->accumGreenSize
);
283 glXGetConfig(dpy
, vInfo
, GLX_ACCUM_BLUE_SIZE
, &attribs
->accumBlueSize
);
284 glXGetConfig(dpy
, vInfo
, GLX_ACCUM_ALPHA_SIZE
, &attribs
->accumAlphaSize
);
286 attribs
->numSamples
= 0;
287 attribs
->numMultisample
= 0;
292 print_visual_attribs_verbose(const struct visual_attribs
*attribs
)
294 printf("Visual ID: %x depth=%d class=%s\n",
295 attribs
->id
, attribs
->depth
, visual_class_name(attribs
->klass
));
296 printf(" bufferSize=%d level=%d renderType=%s doubleBuffer=%d stereo=%d\n",
297 attribs
->bufferSize
, attribs
->level
, attribs
->rgba
? "rgba" : "ci",
298 attribs
->doubleBuffer
, attribs
->stereo
);
299 printf(" rgba: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n",
300 attribs
->redSize
, attribs
->greenSize
,
301 attribs
->blueSize
, attribs
->alphaSize
);
302 printf(" auxBuffers=%d depthSize=%d stencilSize=%d\n",
303 attribs
->auxBuffers
, attribs
->depthSize
, attribs
->stencilSize
);
304 printf(" accum: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n",
305 attribs
->accumRedSize
, attribs
->accumGreenSize
,
306 attribs
->accumBlueSize
, attribs
->accumAlphaSize
);
307 printf(" multiSample=%d multiSampleBuffers=%d\n",
308 attribs
->numSamples
, attribs
->numMultisample
);
309 printf(" %s\n", attribs
->transparent
? "Transparent." : "Opaque.");
314 print_visual_attribs_short_header(void)
316 printf(" visual x bf lv rg d st r g b a ax dp st accum buffs ms \n");
317 printf(" id dep cl sp sz l ci b ro sz sz sz sz bf th cl r g b a ns b\n");
318 printf("-----------------------------------------------------------------\n");
323 print_visual_attribs_short(const struct visual_attribs
*attribs
)
325 printf("0x%2x %2d %2s %2d %2d %2d %1s %2s %2s %2d %2d %2d %2d %2d %2d %2d",
328 visual_class_abbrev(attribs
->klass
),
329 attribs
->transparent
,
332 attribs
->rgba
? "r" : "c",
333 attribs
->doubleBuffer
? "y" : ".",
334 attribs
->stereo
? "y" : ".",
335 attribs
->redSize
, attribs
->greenSize
,
336 attribs
->blueSize
, attribs
->alphaSize
,
342 printf(" %2d %2d %2d %2d %2d %1d\n",
343 attribs
->accumRedSize
, attribs
->accumGreenSize
,
344 attribs
->accumBlueSize
, attribs
->accumAlphaSize
,
345 attribs
->numSamples
, attribs
->numMultisample
351 print_visual_attribs_long_header(void)
353 printf("Vis Vis Visual Trans buff lev render DB ste r g b a aux dep ste accum buffers MS MS\n");
354 printf(" ID Depth Type parent size el type reo sz sz sz sz buf th ncl r g b a num bufs\n");
355 printf("----------------------------------------------------------------------------------------------------\n");
360 print_visual_attribs_long(const struct visual_attribs
*attribs
)
362 printf("0x%2x %2d %-11s %2d %2d %2d %4s %3d %3d %3d %3d %3d %3d",
365 visual_class_name(attribs
->klass
),
366 attribs
->transparent
,
369 attribs
->rgba
? "rgba" : "ci ",
370 attribs
->doubleBuffer
,
372 attribs
->redSize
, attribs
->greenSize
,
373 attribs
->blueSize
, attribs
->alphaSize
376 printf(" %3d %4d %2d %3d %3d %3d %3d %2d %2d\n",
379 attribs
->stencilSize
,
380 attribs
->accumRedSize
, attribs
->accumGreenSize
,
381 attribs
->accumBlueSize
, attribs
->accumAlphaSize
,
382 attribs
->numSamples
, attribs
->numMultisample
388 print_visual_info(Display
*dpy
, int scrnum
, InfoMode mode
)
390 XVisualInfo
template;
391 XVisualInfo
*visuals
;
396 /* get list of all visuals on this screen */
397 template.screen
= scrnum
;
398 mask
= VisualScreenMask
;
399 visuals
= XGetVisualInfo(dpy
, mask
, &template, &numVisuals
);
401 if (mode
== Verbose
) {
402 for (i
= 0; i
< numVisuals
; i
++) {
403 struct visual_attribs attribs
;
404 get_visual_attribs(dpy
, &visuals
[i
], &attribs
);
405 print_visual_attribs_verbose(&attribs
);
408 else if (mode
== Normal
) {
409 print_visual_attribs_short_header();
410 for (i
= 0; i
< numVisuals
; i
++) {
411 struct visual_attribs attribs
;
412 get_visual_attribs(dpy
, &visuals
[i
], &attribs
);
413 print_visual_attribs_short(&attribs
);
416 else if (mode
== Wide
) {
417 print_visual_attribs_long_header();
418 for (i
= 0; i
< numVisuals
; i
++) {
419 struct visual_attribs attribs
;
420 get_visual_attribs(dpy
, &visuals
[i
], &attribs
);
421 print_visual_attribs_long(&attribs
);
430 main(int argc
, char *argv
[])
432 char *displayName
= ":0";
434 int numScreens
, scrnum
;
435 InfoMode mode
= Normal
;
438 for (i
= 1; i
< argc
; i
++) {
439 if (strcmp(argv
[i
], "-display") == 0 && i
+ 1 < argc
) {
440 displayName
= argv
[i
+ 1];
443 else if (strcmp(argv
[i
], "-t") == 0) {
446 else if (strcmp(argv
[i
], "-v") == 0) {
451 dpy
= XOpenDisplay(displayName
);
453 fprintf(stderr
, "Error: unable to open display %s\n", displayName
);
457 numScreens
= ScreenCount(dpy
);
458 for (scrnum
= 0; scrnum
< numScreens
; scrnum
++) {
459 print_screen_info(dpy
, 0);
461 print_visual_info(dpy
, 0, mode
);
462 if (scrnum
+ 1 < numScreens
)