blob: 1dbcd218be0b60725431ae16a043366672e810e7 [file] [log] [blame]
Brian Paul25673f02000-03-31 18:17:51 +00001/* $Id: glxinfo.c,v 1.6 2000/03/31 18:17:51 brianp Exp $ */
Brian Pauld2bfe1e1999-09-16 16:40:46 +00002
3/*
Brian Paul76bc4402000-01-27 16:43:56 +00004 * Copyright (C) 1999 Brian Paul All Rights Reserved.
5 *
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:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
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.
Brian Pauld2bfe1e1999-09-16 16:40:46 +000022 */
23
24
Brian Paul76bc4402000-01-27 16:43:56 +000025/*
26 * This program is a work-alike of the IRIX glxinfo program.
27 * Command line options:
28 * -t print wide table
29 * -v print verbose information
30 * -display DisplayName specify the X display to interogate
31 *
32 * Brian Paul 26 January 2000
33 */
Brian Pauld2bfe1e1999-09-16 16:40:46 +000034
Brian Paul76bc4402000-01-27 16:43:56 +000035
36#include <X11/Xlib.h>
37#include <X11/Xutil.h>
Brian Pauld2bfe1e1999-09-16 16:40:46 +000038#include <GL/gl.h>
Brian Pauld2bfe1e1999-09-16 16:40:46 +000039#include <GL/glu.h>
Brian Paul76bc4402000-01-27 16:43:56 +000040#include <GL/glx.h>
Brian Pauld2bfe1e1999-09-16 16:40:46 +000041#include <stdio.h>
Brian Paul76bc4402000-01-27 16:43:56 +000042#include <string.h>
Brian Pauld2bfe1e1999-09-16 16:40:46 +000043
44
Brian Paul76bc4402000-01-27 16:43:56 +000045typedef enum
Brian Pauld2bfe1e1999-09-16 16:40:46 +000046{
Brian Paul76bc4402000-01-27 16:43:56 +000047 Normal,
48 Wide,
49 Verbose
50} InfoMode;
Brian Pauld2bfe1e1999-09-16 16:40:46 +000051
Brian Pauld2bfe1e1999-09-16 16:40:46 +000052
Brian Paul76bc4402000-01-27 16:43:56 +000053struct visual_attribs
54{
55 /* X visual attribs */
56 int id;
57 int klass;
58 int depth;
59 int redMask, greenMask, blueMask;
60 int colormapSize;
61 int bitsPerRGB;
Brian Pauld2bfe1e1999-09-16 16:40:46 +000062
Brian Paul76bc4402000-01-27 16:43:56 +000063 /* GL visual attribs */
64 int supportsGL;
65 int transparent;
66 int bufferSize;
67 int level;
68 int rgba;
69 int doubleBuffer;
70 int stereo;
71 int auxBuffers;
72 int redSize, greenSize, blueSize, alphaSize;
73 int depthSize;
74 int stencilSize;
75 int accumRedSize, accumGreenSize, accumBlueSize, accumAlphaSize;
76 int numSamples, numMultisample;
Brian Paul25673f02000-03-31 18:17:51 +000077 int visualCaveat;
Brian Paul76bc4402000-01-27 16:43:56 +000078};
79
80
81/*
82 * Print a list of extensions, with word-wrapping.
83 */
84static void
85print_extension_list(const char *ext)
86{
87 const char *indentString = " ";
88 const int indent = 4;
89 const int max = 79;
90 int width, i, j;
91
92 if (!ext || !ext[0])
93 return;
94
95 width = indent;
96 printf(indentString);
97 i = j = 0;
98 while (1) {
99 if (ext[j] == ' ' || ext[j] == 0) {
100 /* found end of an extension name */
101 const int len = j - i;
102 if (width + len > max) {
103 /* start a new line */
104 printf("\n");
105 width = indent;
106 printf(indentString);
107 }
108 /* print the extension name between ext[i] and ext[j] */
109 while (i < j) {
110 printf("%c", ext[i]);
111 i++;
112 }
113 /* either we're all done, or we'll continue with next extension */
114 width += len + 1;
115 if (ext[j] == 0) {
116 break;
117 }
118 else {
119 i++;
120 j++;
Brian Paul7ac43502000-02-23 22:50:35 +0000121 if (ext[j] == 0)
122 break;
Brian Paul76bc4402000-01-27 16:43:56 +0000123 printf(", ");
124 width += 2;
125 }
126 }
127 j++;
128 }
129 printf("\n");
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000130}
131
132
Brian Paul76bc4402000-01-27 16:43:56 +0000133static void
134print_screen_info(Display *dpy, int scrnum)
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000135{
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000136 Window win;
Brian Paul8460cc92000-02-02 20:57:51 +0000137 int attribSingle[] = {
138 GLX_RGBA,
139 GLX_RED_SIZE, 1,
140 GLX_GREEN_SIZE, 1,
141 GLX_BLUE_SIZE, 1,
142 None };
143 int attribDouble[] = {
144 GLX_RGBA,
145 GLX_RED_SIZE, 1,
146 GLX_GREEN_SIZE, 1,
147 GLX_BLUE_SIZE, 1,
148 GLX_DOUBLEBUFFER,
149 None };
150
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000151 XSetWindowAttributes attr;
152 unsigned long mask;
153 Window root;
154 GLXContext ctx;
155 XVisualInfo *visinfo;
156 int width = 100, height = 100;
157
Brian Paul76bc4402000-01-27 16:43:56 +0000158 root = RootWindow(dpy, scrnum);
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000159
Brian Paul8460cc92000-02-02 20:57:51 +0000160 visinfo = glXChooseVisual(dpy, scrnum, attribSingle);
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000161 if (!visinfo) {
Brian Paul8460cc92000-02-02 20:57:51 +0000162 visinfo = glXChooseVisual(dpy, scrnum, attribDouble);
163 if (!visinfo) {
164 fprintf(stderr, "Error: couldn't find RGB GLX visual!\n");
165 return;
166 }
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000167 }
168
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000169 attr.background_pixel = 0;
170 attr.border_pixel = 0;
171 attr.colormap = XCreateColormap( dpy, root, visinfo->visual, AllocNone);
172 attr.event_mask = StructureNotifyMask | ExposureMask;
173 mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
Brian Paul76bc4402000-01-27 16:43:56 +0000174 win = XCreateWindow(dpy, root, 0, 0, width, height,
175 0, visinfo->depth, InputOutput,
176 visinfo->visual, mask, &attr);
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000177
178 ctx = glXCreateContext( dpy, visinfo, NULL, True );
179
180 glXMakeCurrent( dpy, win, ctx );
181
Brian Paul76bc4402000-01-27 16:43:56 +0000182
183 {
184 const char *serverVendor = glXQueryServerString(dpy, scrnum, GLX_VENDOR);
185 const char *serverVersion = glXQueryServerString(dpy, scrnum, GLX_VERSION);
186 const char *serverExtensions = glXQueryServerString(dpy, scrnum, GLX_EXTENSIONS);
187 const char *clientVersion = glXGetClientString(dpy, GLX_VERSION);
188 const char *clientExtensions = glXGetClientString(dpy, GLX_EXTENSIONS);
189 const char *glxExtensions = glXQueryExtensionsString(dpy, scrnum);
190 const char *glVendor = (const char *) glGetString(GL_VENDOR);
191 const char *glRenderer = (const char *) glGetString(GL_RENDERER);
192 const char *glVersion = (const char *) glGetString(GL_VERSION);
193 const char *glExtensions = (const char *) glGetString(GL_EXTENSIONS);
194 const char *gluVersion = (const char *) gluGetString(GLU_VERSION);
195 const char *gluExtensions = (const char *) gluGetString(GLU_EXTENSIONS);
196 printf("display: %s screen:%d\n", DisplayString(dpy), scrnum);
197 printf("server glx vendor string: %s\n", serverVendor);
198 printf("server glx version string: %s\n", serverVersion);
199 printf("server glx extensions:\n");
200 print_extension_list(serverExtensions);
201 printf("client glx version: %s\n", clientVersion);
202 printf("client glx extensions:\n");
203 print_extension_list(clientExtensions);
204 printf("GLX extensions:\n");
205 print_extension_list(glxExtensions);
206 printf("OpenGL vendor string: %s\n", glVendor);
207 printf("OpenGL renderer string: %s\n", glRenderer);
208 printf("OpenGL version string: %s\n", glVersion);
209 printf("OpenGL extensions:\n");
210 print_extension_list(glExtensions);
211 printf("glu version: %s\n", gluVersion);
212 printf("glu extensions:\n");
213 print_extension_list(gluExtensions);
214 }
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000215
216 glXDestroyContext(dpy, ctx);
217 XDestroyWindow(dpy, win);
Brian Paul76bc4402000-01-27 16:43:56 +0000218}
219
220
221static const char *
222visual_class_name(int cls)
223{
224 switch (cls) {
225 case StaticColor:
226 return "StaticColor";
227 case PseudoColor:
228 return "PseudoColor";
229 case StaticGray:
230 return "StaticGray";
231 case GrayScale:
232 return "GrayScale";
233 case TrueColor:
234 return "TrueColor";
235 case DirectColor:
236 return "DirectColor";
237 default:
238 return "";
239 }
240}
241
242
243static const char *
244visual_class_abbrev(int cls)
245{
246 switch (cls) {
247 case StaticColor:
248 return "sc";
249 case PseudoColor:
250 return "pc";
251 case StaticGray:
252 return "sg";
253 case GrayScale:
254 return "gs";
255 case TrueColor:
256 return "tc";
257 case DirectColor:
258 return "dc";
259 default:
260 return "";
261 }
262}
263
264
265static void
266get_visual_attribs(Display *dpy, XVisualInfo *vInfo,
267 struct visual_attribs *attribs)
268{
Brian Paul25673f02000-03-31 18:17:51 +0000269 const char *ext = glXQueryExtensionsString(dpy, vInfo->screen);
270
Brian Paul76bc4402000-01-27 16:43:56 +0000271 attribs->id = vInfo->visualid;
272#if defined(__cplusplus) || defined(c_plusplus)
273 attribs->klass = vInfo->c_class;
274#else
275 attribs->klass = vInfo->class;
276#endif
277 attribs->depth = vInfo->depth;
278 attribs->redMask = vInfo->red_mask;
279 attribs->greenMask = vInfo->green_mask;
280 attribs->blueMask = vInfo->blue_mask;
281 attribs->colormapSize = vInfo->colormap_size;
282 attribs->bitsPerRGB = vInfo->bits_per_rgb;
283
Brian Paul76bc4402000-01-27 16:43:56 +0000284 glXGetConfig(dpy, vInfo, GLX_USE_GL, &attribs->supportsGL);
285 glXGetConfig(dpy, vInfo, GLX_BUFFER_SIZE, &attribs->bufferSize);
286 glXGetConfig(dpy, vInfo, GLX_LEVEL, &attribs->level);
287 glXGetConfig(dpy, vInfo, GLX_RGBA, &attribs->rgba);
288 glXGetConfig(dpy, vInfo, GLX_DOUBLEBUFFER, &attribs->doubleBuffer);
289 glXGetConfig(dpy, vInfo, GLX_STEREO, &attribs->stereo);
290 glXGetConfig(dpy, vInfo, GLX_AUX_BUFFERS, &attribs->auxBuffers);
291 glXGetConfig(dpy, vInfo, GLX_RED_SIZE, &attribs->redSize);
292 glXGetConfig(dpy, vInfo, GLX_GREEN_SIZE, &attribs->greenSize);
293 glXGetConfig(dpy, vInfo, GLX_BLUE_SIZE, &attribs->blueSize);
294 glXGetConfig(dpy, vInfo, GLX_ALPHA_SIZE, &attribs->alphaSize);
295 glXGetConfig(dpy, vInfo, GLX_DEPTH_SIZE, &attribs->depthSize);
296 glXGetConfig(dpy, vInfo, GLX_STENCIL_SIZE, &attribs->stencilSize);
297 glXGetConfig(dpy, vInfo, GLX_ACCUM_RED_SIZE, &attribs->accumRedSize);
298 glXGetConfig(dpy, vInfo, GLX_ACCUM_GREEN_SIZE, &attribs->accumGreenSize);
299 glXGetConfig(dpy, vInfo, GLX_ACCUM_BLUE_SIZE, &attribs->accumBlueSize);
300 glXGetConfig(dpy, vInfo, GLX_ACCUM_ALPHA_SIZE, &attribs->accumAlphaSize);
301
Brian Paule06c7f32000-01-27 16:53:55 +0000302 /* transparent pixel value not implemented yet */
303 attribs->transparent = 0;
304
305 /* multisample tests not implemented yet */
Brian Paul76bc4402000-01-27 16:43:56 +0000306 attribs->numSamples = 0;
307 attribs->numMultisample = 0;
Brian Paul25673f02000-03-31 18:17:51 +0000308
309#if defined(GLX_EXT_visual_rating)
310 if (ext && strstr(ext, "GLX_EXT_visual_rating")) {
311 glXGetConfig(dpy, vInfo, GLX_VISUAL_CAVEAT_EXT, &attribs->visualCaveat);
312 }
313 else {
314 attribs->visualCaveat = GLX_NONE_EXT;
315 }
316#else
317 attribs->visualCaveat = 0;
318#endif
Brian Paul76bc4402000-01-27 16:43:56 +0000319}
320
321
322static void
323print_visual_attribs_verbose(const struct visual_attribs *attribs)
324{
325 printf("Visual ID: %x depth=%d class=%s\n",
326 attribs->id, attribs->depth, visual_class_name(attribs->klass));
327 printf(" bufferSize=%d level=%d renderType=%s doubleBuffer=%d stereo=%d\n",
328 attribs->bufferSize, attribs->level, attribs->rgba ? "rgba" : "ci",
329 attribs->doubleBuffer, attribs->stereo);
330 printf(" rgba: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n",
331 attribs->redSize, attribs->greenSize,
332 attribs->blueSize, attribs->alphaSize);
333 printf(" auxBuffers=%d depthSize=%d stencilSize=%d\n",
334 attribs->auxBuffers, attribs->depthSize, attribs->stencilSize);
335 printf(" accum: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n",
336 attribs->accumRedSize, attribs->accumGreenSize,
337 attribs->accumBlueSize, attribs->accumAlphaSize);
338 printf(" multiSample=%d multiSampleBuffers=%d\n",
339 attribs->numSamples, attribs->numMultisample);
340 printf(" %s\n", attribs->transparent ? "Transparent." : "Opaque.");
Brian Paul25673f02000-03-31 18:17:51 +0000341#ifdef GLX_EXT_visual_rating
342 if (attribs->visualCaveat == GLX_NONE_EXT || attribs->visualCaveat == 0)
343 printf(" visualCaveat: None\n");
344 else if (attribs->visualCaveat == GLX_SLOW_VISUAL_EXT)
345 printf(" visualCaveat: Slow\n");
346 else if (attribs->visualCaveat == GLX_NON_CONFORMANT_VISUAL_EXT)
347 printf(" visualCaveat: Nonconformant\n");
348#endif
Brian Paul76bc4402000-01-27 16:43:56 +0000349}
350
351
352static void
353print_visual_attribs_short_header(void)
354{
Brian Paul25673f02000-03-31 18:17:51 +0000355 printf(" visual x bf lv rg d st r g b a ax dp st accum buffs ms cav\n");
356 printf(" id dep cl sp sz l ci b ro sz sz sz sz bf th cl r g b a ns b eat\n");
357 printf("----------------------------------------------------------------------\n");
Brian Paul76bc4402000-01-27 16:43:56 +0000358}
359
360
361static void
362print_visual_attribs_short(const struct visual_attribs *attribs)
363{
Brian Paul25673f02000-03-31 18:17:51 +0000364 char *caveat;
365#ifdef GLX_EXT_visual_rating
366 if (attribs->visualCaveat == GLX_NONE_EXT || attribs->visualCaveat == 0)
367 caveat = "None";
368 else if (attribs->visualCaveat == GLX_SLOW_VISUAL_EXT)
369 caveat = "Slow";
370 else if (attribs->visualCaveat == GLX_NON_CONFORMANT_VISUAL_EXT)
371 caveat = "Ncon";
372#else
373 caveat = "None";
374#endif
375
Brian Paul76bc4402000-01-27 16:43:56 +0000376 printf("0x%2x %2d %2s %2d %2d %2d %1s %2s %2s %2d %2d %2d %2d %2d %2d %2d",
377 attribs->id,
378 attribs->depth,
379 visual_class_abbrev(attribs->klass),
380 attribs->transparent,
381 attribs->bufferSize,
382 attribs->level,
383 attribs->rgba ? "r" : "c",
384 attribs->doubleBuffer ? "y" : ".",
385 attribs->stereo ? "y" : ".",
386 attribs->redSize, attribs->greenSize,
387 attribs->blueSize, attribs->alphaSize,
388 attribs->auxBuffers,
389 attribs->depthSize,
390 attribs->stencilSize
391 );
392
Brian Paul25673f02000-03-31 18:17:51 +0000393 printf(" %2d %2d %2d %2d %2d %1d %s\n",
Brian Paul76bc4402000-01-27 16:43:56 +0000394 attribs->accumRedSize, attribs->accumGreenSize,
395 attribs->accumBlueSize, attribs->accumAlphaSize,
Brian Paul25673f02000-03-31 18:17:51 +0000396 attribs->numSamples, attribs->numMultisample,
397 caveat
Brian Paul76bc4402000-01-27 16:43:56 +0000398 );
399}
400
401
402static void
403print_visual_attribs_long_header(void)
404{
405 printf("Vis Vis Visual Trans buff lev render DB ste r g b a aux dep ste accum buffers MS MS\n");
406 printf(" ID Depth Type parent size el type reo sz sz sz sz buf th ncl r g b a num bufs\n");
407 printf("----------------------------------------------------------------------------------------------------\n");
408}
409
410
411static void
412print_visual_attribs_long(const struct visual_attribs *attribs)
413{
414 printf("0x%2x %2d %-11s %2d %2d %2d %4s %3d %3d %3d %3d %3d %3d",
415 attribs->id,
416 attribs->depth,
417 visual_class_name(attribs->klass),
418 attribs->transparent,
419 attribs->bufferSize,
420 attribs->level,
421 attribs->rgba ? "rgba" : "ci ",
422 attribs->doubleBuffer,
423 attribs->stereo,
424 attribs->redSize, attribs->greenSize,
425 attribs->blueSize, attribs->alphaSize
426 );
427
428 printf(" %3d %4d %2d %3d %3d %3d %3d %2d %2d\n",
429 attribs->auxBuffers,
430 attribs->depthSize,
431 attribs->stencilSize,
432 attribs->accumRedSize, attribs->accumGreenSize,
433 attribs->accumBlueSize, attribs->accumAlphaSize,
434 attribs->numSamples, attribs->numMultisample
435 );
436}
437
438
439static void
440print_visual_info(Display *dpy, int scrnum, InfoMode mode)
441{
442 XVisualInfo template;
443 XVisualInfo *visuals;
444 int numVisuals;
445 long mask;
446 int i;
447
448 /* get list of all visuals on this screen */
449 template.screen = scrnum;
450 mask = VisualScreenMask;
451 visuals = XGetVisualInfo(dpy, mask, &template, &numVisuals);
452
453 if (mode == Verbose) {
454 for (i = 0; i < numVisuals; i++) {
455 struct visual_attribs attribs;
456 get_visual_attribs(dpy, &visuals[i], &attribs);
457 print_visual_attribs_verbose(&attribs);
458 }
459 }
460 else if (mode == Normal) {
461 print_visual_attribs_short_header();
462 for (i = 0; i < numVisuals; i++) {
463 struct visual_attribs attribs;
464 get_visual_attribs(dpy, &visuals[i], &attribs);
465 print_visual_attribs_short(&attribs);
466 }
467 }
468 else if (mode == Wide) {
469 print_visual_attribs_long_header();
470 for (i = 0; i < numVisuals; i++) {
471 struct visual_attribs attribs;
472 get_visual_attribs(dpy, &visuals[i], &attribs);
473 print_visual_attribs_long(&attribs);
474 }
475 }
476
477 XFree(visuals);
478}
479
480
481int
482main(int argc, char *argv[])
483{
484 char *displayName = ":0";
485 Display *dpy;
486 int numScreens, scrnum;
487 InfoMode mode = Normal;
488 int i;
489
490 for (i = 1; i < argc; i++) {
491 if (strcmp(argv[i], "-display") == 0 && i + 1 < argc) {
492 displayName = argv[i + 1];
493 i++;
494 }
495 else if (strcmp(argv[i], "-t") == 0) {
496 mode = Wide;
497 }
498 else if (strcmp(argv[i], "-v") == 0) {
499 mode = Verbose;
500 }
501 }
502
503 dpy = XOpenDisplay(displayName);
504 if (!dpy) {
505 fprintf(stderr, "Error: unable to open display %s\n", displayName);
506 return -1;
507 }
508
509 numScreens = ScreenCount(dpy);
510 for (scrnum = 0; scrnum < numScreens; scrnum++) {
511 print_screen_info(dpy, 0);
512 printf("\n");
513 print_visual_info(dpy, 0, mode);
514 if (scrnum + 1 < numScreens)
515 printf("\n\n");
516 }
517
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000518 XCloseDisplay(dpy);
519
520 return 0;
521}