1 /* $Id: glxinfo.c,v 1.4 2000/02/02 20:57:51 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 attribSingle
[] = {
140 int attribDouble
[] = {
148 XSetWindowAttributes attr
;
152 XVisualInfo
*visinfo
;
153 int width
= 100, height
= 100;
155 root
= RootWindow(dpy
, scrnum
);
157 visinfo
= glXChooseVisual(dpy
, scrnum
, attribSingle
);
159 visinfo
= glXChooseVisual(dpy
, scrnum
, attribDouble
);
161 fprintf(stderr
, "Error: couldn't find RGB GLX visual!\n");
166 attr
.background_pixel
= 0;
167 attr
.border_pixel
= 0;
168 attr
.colormap
= XCreateColormap( dpy
, root
, visinfo
->visual
, AllocNone
);
169 attr
.event_mask
= StructureNotifyMask
| ExposureMask
;
170 mask
= CWBackPixel
| CWBorderPixel
| CWColormap
| CWEventMask
;
171 win
= XCreateWindow(dpy
, root
, 0, 0, width
, height
,
172 0, visinfo
->depth
, InputOutput
,
173 visinfo
->visual
, mask
, &attr
);
175 ctx
= glXCreateContext( dpy
, visinfo
, NULL
, True
);
177 glXMakeCurrent( dpy
, win
, ctx
);
181 const char *serverVendor
= glXQueryServerString(dpy
, scrnum
, GLX_VENDOR
);
182 const char *serverVersion
= glXQueryServerString(dpy
, scrnum
, GLX_VERSION
);
183 const char *serverExtensions
= glXQueryServerString(dpy
, scrnum
, GLX_EXTENSIONS
);
184 const char *clientVersion
= glXGetClientString(dpy
, GLX_VERSION
);
185 const char *clientExtensions
= glXGetClientString(dpy
, GLX_EXTENSIONS
);
186 const char *glxExtensions
= glXQueryExtensionsString(dpy
, scrnum
);
187 const char *glVendor
= (const char *) glGetString(GL_VENDOR
);
188 const char *glRenderer
= (const char *) glGetString(GL_RENDERER
);
189 const char *glVersion
= (const char *) glGetString(GL_VERSION
);
190 const char *glExtensions
= (const char *) glGetString(GL_EXTENSIONS
);
191 const char *gluVersion
= (const char *) gluGetString(GLU_VERSION
);
192 const char *gluExtensions
= (const char *) gluGetString(GLU_EXTENSIONS
);
193 printf("display: %s screen:%d\n", DisplayString(dpy
), scrnum
);
194 printf("server glx vendor string: %s\n", serverVendor
);
195 printf("server glx version string: %s\n", serverVersion
);
196 printf("server glx extensions:\n");
197 print_extension_list(serverExtensions
);
198 printf("client glx version: %s\n", clientVersion
);
199 printf("client glx extensions:\n");
200 print_extension_list(clientExtensions
);
201 printf("GLX extensions:\n");
202 print_extension_list(glxExtensions
);
203 printf("OpenGL vendor string: %s\n", glVendor
);
204 printf("OpenGL renderer string: %s\n", glRenderer
);
205 printf("OpenGL version string: %s\n", glVersion
);
206 printf("OpenGL extensions:\n");
207 print_extension_list(glExtensions
);
208 printf("glu version: %s\n", gluVersion
);
209 printf("glu extensions:\n");
210 print_extension_list(gluExtensions
);
213 glXDestroyContext(dpy
, ctx
);
214 XDestroyWindow(dpy
, win
);
219 visual_class_name(int cls
)
223 return "StaticColor";
225 return "PseudoColor";
233 return "DirectColor";
241 visual_class_abbrev(int cls
)
263 get_visual_attribs(Display
*dpy
, XVisualInfo
*vInfo
,
264 struct visual_attribs
*attribs
)
266 attribs
->id
= vInfo
->visualid
;
267 #if defined(__cplusplus) || defined(c_plusplus)
268 attribs
->klass
= vInfo
->c_class
;
270 attribs
->klass
= vInfo
->class;
272 attribs
->depth
= vInfo
->depth
;
273 attribs
->redMask
= vInfo
->red_mask
;
274 attribs
->greenMask
= vInfo
->green_mask
;
275 attribs
->blueMask
= vInfo
->blue_mask
;
276 attribs
->colormapSize
= vInfo
->colormap_size
;
277 attribs
->bitsPerRGB
= vInfo
->bits_per_rgb
;
279 glXGetConfig(dpy
, vInfo
, GLX_USE_GL
, &attribs
->supportsGL
);
280 glXGetConfig(dpy
, vInfo
, GLX_BUFFER_SIZE
, &attribs
->bufferSize
);
281 glXGetConfig(dpy
, vInfo
, GLX_LEVEL
, &attribs
->level
);
282 glXGetConfig(dpy
, vInfo
, GLX_RGBA
, &attribs
->rgba
);
283 glXGetConfig(dpy
, vInfo
, GLX_DOUBLEBUFFER
, &attribs
->doubleBuffer
);
284 glXGetConfig(dpy
, vInfo
, GLX_STEREO
, &attribs
->stereo
);
285 glXGetConfig(dpy
, vInfo
, GLX_AUX_BUFFERS
, &attribs
->auxBuffers
);
286 glXGetConfig(dpy
, vInfo
, GLX_RED_SIZE
, &attribs
->redSize
);
287 glXGetConfig(dpy
, vInfo
, GLX_GREEN_SIZE
, &attribs
->greenSize
);
288 glXGetConfig(dpy
, vInfo
, GLX_BLUE_SIZE
, &attribs
->blueSize
);
289 glXGetConfig(dpy
, vInfo
, GLX_ALPHA_SIZE
, &attribs
->alphaSize
);
290 glXGetConfig(dpy
, vInfo
, GLX_DEPTH_SIZE
, &attribs
->depthSize
);
291 glXGetConfig(dpy
, vInfo
, GLX_STENCIL_SIZE
, &attribs
->stencilSize
);
292 glXGetConfig(dpy
, vInfo
, GLX_ACCUM_RED_SIZE
, &attribs
->accumRedSize
);
293 glXGetConfig(dpy
, vInfo
, GLX_ACCUM_GREEN_SIZE
, &attribs
->accumGreenSize
);
294 glXGetConfig(dpy
, vInfo
, GLX_ACCUM_BLUE_SIZE
, &attribs
->accumBlueSize
);
295 glXGetConfig(dpy
, vInfo
, GLX_ACCUM_ALPHA_SIZE
, &attribs
->accumAlphaSize
);
297 /* transparent pixel value not implemented yet */
298 attribs
->transparent
= 0;
300 /* multisample tests not implemented yet */
301 attribs
->numSamples
= 0;
302 attribs
->numMultisample
= 0;
307 print_visual_attribs_verbose(const struct visual_attribs
*attribs
)
309 printf("Visual ID: %x depth=%d class=%s\n",
310 attribs
->id
, attribs
->depth
, visual_class_name(attribs
->klass
));
311 printf(" bufferSize=%d level=%d renderType=%s doubleBuffer=%d stereo=%d\n",
312 attribs
->bufferSize
, attribs
->level
, attribs
->rgba
? "rgba" : "ci",
313 attribs
->doubleBuffer
, attribs
->stereo
);
314 printf(" rgba: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n",
315 attribs
->redSize
, attribs
->greenSize
,
316 attribs
->blueSize
, attribs
->alphaSize
);
317 printf(" auxBuffers=%d depthSize=%d stencilSize=%d\n",
318 attribs
->auxBuffers
, attribs
->depthSize
, attribs
->stencilSize
);
319 printf(" accum: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n",
320 attribs
->accumRedSize
, attribs
->accumGreenSize
,
321 attribs
->accumBlueSize
, attribs
->accumAlphaSize
);
322 printf(" multiSample=%d multiSampleBuffers=%d\n",
323 attribs
->numSamples
, attribs
->numMultisample
);
324 printf(" %s\n", attribs
->transparent
? "Transparent." : "Opaque.");
329 print_visual_attribs_short_header(void)
331 printf(" visual x bf lv rg d st r g b a ax dp st accum buffs ms \n");
332 printf(" id dep cl sp sz l ci b ro sz sz sz sz bf th cl r g b a ns b\n");
333 printf("-----------------------------------------------------------------\n");
338 print_visual_attribs_short(const struct visual_attribs
*attribs
)
340 printf("0x%2x %2d %2s %2d %2d %2d %1s %2s %2s %2d %2d %2d %2d %2d %2d %2d",
343 visual_class_abbrev(attribs
->klass
),
344 attribs
->transparent
,
347 attribs
->rgba
? "r" : "c",
348 attribs
->doubleBuffer
? "y" : ".",
349 attribs
->stereo
? "y" : ".",
350 attribs
->redSize
, attribs
->greenSize
,
351 attribs
->blueSize
, attribs
->alphaSize
,
357 printf(" %2d %2d %2d %2d %2d %1d\n",
358 attribs
->accumRedSize
, attribs
->accumGreenSize
,
359 attribs
->accumBlueSize
, attribs
->accumAlphaSize
,
360 attribs
->numSamples
, attribs
->numMultisample
366 print_visual_attribs_long_header(void)
368 printf("Vis Vis Visual Trans buff lev render DB ste r g b a aux dep ste accum buffers MS MS\n");
369 printf(" ID Depth Type parent size el type reo sz sz sz sz buf th ncl r g b a num bufs\n");
370 printf("----------------------------------------------------------------------------------------------------\n");
375 print_visual_attribs_long(const struct visual_attribs
*attribs
)
377 printf("0x%2x %2d %-11s %2d %2d %2d %4s %3d %3d %3d %3d %3d %3d",
380 visual_class_name(attribs
->klass
),
381 attribs
->transparent
,
384 attribs
->rgba
? "rgba" : "ci ",
385 attribs
->doubleBuffer
,
387 attribs
->redSize
, attribs
->greenSize
,
388 attribs
->blueSize
, attribs
->alphaSize
391 printf(" %3d %4d %2d %3d %3d %3d %3d %2d %2d\n",
394 attribs
->stencilSize
,
395 attribs
->accumRedSize
, attribs
->accumGreenSize
,
396 attribs
->accumBlueSize
, attribs
->accumAlphaSize
,
397 attribs
->numSamples
, attribs
->numMultisample
403 print_visual_info(Display
*dpy
, int scrnum
, InfoMode mode
)
405 XVisualInfo
template;
406 XVisualInfo
*visuals
;
411 /* get list of all visuals on this screen */
412 template.screen
= scrnum
;
413 mask
= VisualScreenMask
;
414 visuals
= XGetVisualInfo(dpy
, mask
, &template, &numVisuals
);
416 if (mode
== Verbose
) {
417 for (i
= 0; i
< numVisuals
; i
++) {
418 struct visual_attribs attribs
;
419 get_visual_attribs(dpy
, &visuals
[i
], &attribs
);
420 print_visual_attribs_verbose(&attribs
);
423 else if (mode
== Normal
) {
424 print_visual_attribs_short_header();
425 for (i
= 0; i
< numVisuals
; i
++) {
426 struct visual_attribs attribs
;
427 get_visual_attribs(dpy
, &visuals
[i
], &attribs
);
428 print_visual_attribs_short(&attribs
);
431 else if (mode
== Wide
) {
432 print_visual_attribs_long_header();
433 for (i
= 0; i
< numVisuals
; i
++) {
434 struct visual_attribs attribs
;
435 get_visual_attribs(dpy
, &visuals
[i
], &attribs
);
436 print_visual_attribs_long(&attribs
);
445 main(int argc
, char *argv
[])
447 char *displayName
= ":0";
449 int numScreens
, scrnum
;
450 InfoMode mode
= Normal
;
453 for (i
= 1; i
< argc
; i
++) {
454 if (strcmp(argv
[i
], "-display") == 0 && i
+ 1 < argc
) {
455 displayName
= argv
[i
+ 1];
458 else if (strcmp(argv
[i
], "-t") == 0) {
461 else if (strcmp(argv
[i
], "-v") == 0) {
466 dpy
= XOpenDisplay(displayName
);
468 fprintf(stderr
, "Error: unable to open display %s\n", displayName
);
472 numScreens
= ScreenCount(dpy
);
473 for (scrnum
= 0; scrnum
< numScreens
; scrnum
++) {
474 print_screen_info(dpy
, 0);
476 print_visual_info(dpy
, 0, mode
);
477 if (scrnum
+ 1 < numScreens
)