blob: 86959de19c6d8087fe22ec8f3c64869cb9534c5f [file] [log] [blame]
Brian Paul34fb5db2000-04-22 20:31:23 +00001/* $Id: glxinfo.c,v 1.8 2000/04/22 20:31:23 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 );
Brian Paul34fb5db2000-04-22 20:31:23 +0000179 if (!ctx) {
180 XDestroyWindow(dpy, win);
181 return;
182 }
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000183
Brian Paul34fb5db2000-04-22 20:31:23 +0000184 if (glXMakeCurrent( dpy, win, ctx )) {
Brian Paul76bc4402000-01-27 16:43:56 +0000185 const char *serverVendor = glXQueryServerString(dpy, scrnum, GLX_VENDOR);
186 const char *serverVersion = glXQueryServerString(dpy, scrnum, GLX_VERSION);
187 const char *serverExtensions = glXQueryServerString(dpy, scrnum, GLX_EXTENSIONS);
Brian Paul34fb5db2000-04-22 20:31:23 +0000188 const char *clientVendor = glXGetClientString(dpy, GLX_VENDOR);
Brian Paul76bc4402000-01-27 16:43:56 +0000189 const char *clientVersion = glXGetClientString(dpy, GLX_VERSION);
190 const char *clientExtensions = glXGetClientString(dpy, GLX_EXTENSIONS);
191 const char *glxExtensions = glXQueryExtensionsString(dpy, scrnum);
192 const char *glVendor = (const char *) glGetString(GL_VENDOR);
193 const char *glRenderer = (const char *) glGetString(GL_RENDERER);
194 const char *glVersion = (const char *) glGetString(GL_VERSION);
195 const char *glExtensions = (const char *) glGetString(GL_EXTENSIONS);
196 const char *gluVersion = (const char *) gluGetString(GLU_VERSION);
197 const char *gluExtensions = (const char *) gluGetString(GLU_EXTENSIONS);
198 printf("display: %s screen:%d\n", DisplayString(dpy), scrnum);
199 printf("server glx vendor string: %s\n", serverVendor);
200 printf("server glx version string: %s\n", serverVersion);
201 printf("server glx extensions:\n");
202 print_extension_list(serverExtensions);
Brian Paul34fb5db2000-04-22 20:31:23 +0000203 printf("client glx vendor string: %s\n", clientVendor);
204 printf("client glx version string: %s\n", clientVersion);
Brian Paul76bc4402000-01-27 16:43:56 +0000205 printf("client glx extensions:\n");
206 print_extension_list(clientExtensions);
207 printf("GLX extensions:\n");
208 print_extension_list(glxExtensions);
209 printf("OpenGL vendor string: %s\n", glVendor);
210 printf("OpenGL renderer string: %s\n", glRenderer);
211 printf("OpenGL version string: %s\n", glVersion);
212 printf("OpenGL extensions:\n");
213 print_extension_list(glExtensions);
214 printf("glu version: %s\n", gluVersion);
215 printf("glu extensions:\n");
216 print_extension_list(gluExtensions);
217 }
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000218
219 glXDestroyContext(dpy, ctx);
220 XDestroyWindow(dpy, win);
Brian Paul76bc4402000-01-27 16:43:56 +0000221}
222
223
224static const char *
225visual_class_name(int cls)
226{
227 switch (cls) {
228 case StaticColor:
229 return "StaticColor";
230 case PseudoColor:
231 return "PseudoColor";
232 case StaticGray:
233 return "StaticGray";
234 case GrayScale:
235 return "GrayScale";
236 case TrueColor:
237 return "TrueColor";
238 case DirectColor:
239 return "DirectColor";
240 default:
241 return "";
242 }
243}
244
245
246static const char *
247visual_class_abbrev(int cls)
248{
249 switch (cls) {
250 case StaticColor:
251 return "sc";
252 case PseudoColor:
253 return "pc";
254 case StaticGray:
255 return "sg";
256 case GrayScale:
257 return "gs";
258 case TrueColor:
259 return "tc";
260 case DirectColor:
261 return "dc";
262 default:
263 return "";
264 }
265}
266
267
268static void
269get_visual_attribs(Display *dpy, XVisualInfo *vInfo,
270 struct visual_attribs *attribs)
271{
Brian Paul25673f02000-03-31 18:17:51 +0000272 const char *ext = glXQueryExtensionsString(dpy, vInfo->screen);
273
Brian Paula9c53fa2000-04-03 15:45:34 +0000274 memset(attribs, 0, sizeof(struct visual_attribs));
275
Brian Paul76bc4402000-01-27 16:43:56 +0000276 attribs->id = vInfo->visualid;
277#if defined(__cplusplus) || defined(c_plusplus)
278 attribs->klass = vInfo->c_class;
279#else
280 attribs->klass = vInfo->class;
281#endif
282 attribs->depth = vInfo->depth;
283 attribs->redMask = vInfo->red_mask;
284 attribs->greenMask = vInfo->green_mask;
285 attribs->blueMask = vInfo->blue_mask;
286 attribs->colormapSize = vInfo->colormap_size;
287 attribs->bitsPerRGB = vInfo->bits_per_rgb;
288
Brian Paula9c53fa2000-04-03 15:45:34 +0000289 if (glXGetConfig(dpy, vInfo, GLX_USE_GL, &attribs->supportsGL) != 0)
290 return;
Brian Paul76bc4402000-01-27 16:43:56 +0000291 glXGetConfig(dpy, vInfo, GLX_BUFFER_SIZE, &attribs->bufferSize);
292 glXGetConfig(dpy, vInfo, GLX_LEVEL, &attribs->level);
293 glXGetConfig(dpy, vInfo, GLX_RGBA, &attribs->rgba);
294 glXGetConfig(dpy, vInfo, GLX_DOUBLEBUFFER, &attribs->doubleBuffer);
295 glXGetConfig(dpy, vInfo, GLX_STEREO, &attribs->stereo);
296 glXGetConfig(dpy, vInfo, GLX_AUX_BUFFERS, &attribs->auxBuffers);
297 glXGetConfig(dpy, vInfo, GLX_RED_SIZE, &attribs->redSize);
298 glXGetConfig(dpy, vInfo, GLX_GREEN_SIZE, &attribs->greenSize);
299 glXGetConfig(dpy, vInfo, GLX_BLUE_SIZE, &attribs->blueSize);
300 glXGetConfig(dpy, vInfo, GLX_ALPHA_SIZE, &attribs->alphaSize);
301 glXGetConfig(dpy, vInfo, GLX_DEPTH_SIZE, &attribs->depthSize);
302 glXGetConfig(dpy, vInfo, GLX_STENCIL_SIZE, &attribs->stencilSize);
303 glXGetConfig(dpy, vInfo, GLX_ACCUM_RED_SIZE, &attribs->accumRedSize);
304 glXGetConfig(dpy, vInfo, GLX_ACCUM_GREEN_SIZE, &attribs->accumGreenSize);
305 glXGetConfig(dpy, vInfo, GLX_ACCUM_BLUE_SIZE, &attribs->accumBlueSize);
306 glXGetConfig(dpy, vInfo, GLX_ACCUM_ALPHA_SIZE, &attribs->accumAlphaSize);
307
Brian Paule06c7f32000-01-27 16:53:55 +0000308 /* transparent pixel value not implemented yet */
309 attribs->transparent = 0;
310
311 /* multisample tests not implemented yet */
Brian Paul76bc4402000-01-27 16:43:56 +0000312 attribs->numSamples = 0;
313 attribs->numMultisample = 0;
Brian Paul25673f02000-03-31 18:17:51 +0000314
315#if defined(GLX_EXT_visual_rating)
316 if (ext && strstr(ext, "GLX_EXT_visual_rating")) {
317 glXGetConfig(dpy, vInfo, GLX_VISUAL_CAVEAT_EXT, &attribs->visualCaveat);
318 }
319 else {
320 attribs->visualCaveat = GLX_NONE_EXT;
321 }
322#else
323 attribs->visualCaveat = 0;
324#endif
Brian Paul76bc4402000-01-27 16:43:56 +0000325}
326
327
328static void
329print_visual_attribs_verbose(const struct visual_attribs *attribs)
330{
331 printf("Visual ID: %x depth=%d class=%s\n",
332 attribs->id, attribs->depth, visual_class_name(attribs->klass));
333 printf(" bufferSize=%d level=%d renderType=%s doubleBuffer=%d stereo=%d\n",
334 attribs->bufferSize, attribs->level, attribs->rgba ? "rgba" : "ci",
335 attribs->doubleBuffer, attribs->stereo);
336 printf(" rgba: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n",
337 attribs->redSize, attribs->greenSize,
338 attribs->blueSize, attribs->alphaSize);
339 printf(" auxBuffers=%d depthSize=%d stencilSize=%d\n",
340 attribs->auxBuffers, attribs->depthSize, attribs->stencilSize);
341 printf(" accum: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n",
342 attribs->accumRedSize, attribs->accumGreenSize,
343 attribs->accumBlueSize, attribs->accumAlphaSize);
344 printf(" multiSample=%d multiSampleBuffers=%d\n",
345 attribs->numSamples, attribs->numMultisample);
Brian Paul25673f02000-03-31 18:17:51 +0000346#ifdef GLX_EXT_visual_rating
347 if (attribs->visualCaveat == GLX_NONE_EXT || attribs->visualCaveat == 0)
Brian Paula9c53fa2000-04-03 15:45:34 +0000348 printf(" visualCaveat=None\n");
Brian Paul25673f02000-03-31 18:17:51 +0000349 else if (attribs->visualCaveat == GLX_SLOW_VISUAL_EXT)
Brian Paula9c53fa2000-04-03 15:45:34 +0000350 printf(" visualCaveat=Slow\n");
Brian Paul25673f02000-03-31 18:17:51 +0000351 else if (attribs->visualCaveat == GLX_NON_CONFORMANT_VISUAL_EXT)
Brian Paula9c53fa2000-04-03 15:45:34 +0000352 printf(" visualCaveat=Nonconformant\n");
Brian Paul25673f02000-03-31 18:17:51 +0000353#endif
Brian Paula9c53fa2000-04-03 15:45:34 +0000354 printf(" %s\n", attribs->transparent ? "Transparent." : "Opaque.");
Brian Paul76bc4402000-01-27 16:43:56 +0000355}
356
357
358static void
359print_visual_attribs_short_header(void)
360{
Brian Paula9c53fa2000-04-03 15:45:34 +0000361 printf(" visual x bf lv rg d st colorbuffer ax dp st accumbuffer ms cav\n");
362 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");
Brian Paul25673f02000-03-31 18:17:51 +0000363 printf("----------------------------------------------------------------------\n");
Brian Paul76bc4402000-01-27 16:43:56 +0000364}
365
366
367static void
368print_visual_attribs_short(const struct visual_attribs *attribs)
369{
Brian Paul25673f02000-03-31 18:17:51 +0000370 char *caveat;
371#ifdef GLX_EXT_visual_rating
372 if (attribs->visualCaveat == GLX_NONE_EXT || attribs->visualCaveat == 0)
373 caveat = "None";
374 else if (attribs->visualCaveat == GLX_SLOW_VISUAL_EXT)
375 caveat = "Slow";
376 else if (attribs->visualCaveat == GLX_NON_CONFORMANT_VISUAL_EXT)
377 caveat = "Ncon";
378#else
379 caveat = "None";
380#endif
381
Brian Paul76bc4402000-01-27 16:43:56 +0000382 printf("0x%2x %2d %2s %2d %2d %2d %1s %2s %2s %2d %2d %2d %2d %2d %2d %2d",
383 attribs->id,
384 attribs->depth,
385 visual_class_abbrev(attribs->klass),
386 attribs->transparent,
387 attribs->bufferSize,
388 attribs->level,
389 attribs->rgba ? "r" : "c",
390 attribs->doubleBuffer ? "y" : ".",
391 attribs->stereo ? "y" : ".",
392 attribs->redSize, attribs->greenSize,
393 attribs->blueSize, attribs->alphaSize,
394 attribs->auxBuffers,
395 attribs->depthSize,
396 attribs->stencilSize
397 );
398
Brian Paul25673f02000-03-31 18:17:51 +0000399 printf(" %2d %2d %2d %2d %2d %1d %s\n",
Brian Paul76bc4402000-01-27 16:43:56 +0000400 attribs->accumRedSize, attribs->accumGreenSize,
401 attribs->accumBlueSize, attribs->accumAlphaSize,
Brian Paul25673f02000-03-31 18:17:51 +0000402 attribs->numSamples, attribs->numMultisample,
403 caveat
Brian Paul76bc4402000-01-27 16:43:56 +0000404 );
405}
406
407
408static void
409print_visual_attribs_long_header(void)
410{
411 printf("Vis Vis Visual Trans buff lev render DB ste r g b a aux dep ste accum buffers MS MS\n");
412 printf(" ID Depth Type parent size el type reo sz sz sz sz buf th ncl r g b a num bufs\n");
413 printf("----------------------------------------------------------------------------------------------------\n");
414}
415
416
417static void
418print_visual_attribs_long(const struct visual_attribs *attribs)
419{
420 printf("0x%2x %2d %-11s %2d %2d %2d %4s %3d %3d %3d %3d %3d %3d",
421 attribs->id,
422 attribs->depth,
423 visual_class_name(attribs->klass),
424 attribs->transparent,
425 attribs->bufferSize,
426 attribs->level,
427 attribs->rgba ? "rgba" : "ci ",
428 attribs->doubleBuffer,
429 attribs->stereo,
430 attribs->redSize, attribs->greenSize,
431 attribs->blueSize, attribs->alphaSize
432 );
433
434 printf(" %3d %4d %2d %3d %3d %3d %3d %2d %2d\n",
435 attribs->auxBuffers,
436 attribs->depthSize,
437 attribs->stencilSize,
438 attribs->accumRedSize, attribs->accumGreenSize,
439 attribs->accumBlueSize, attribs->accumAlphaSize,
440 attribs->numSamples, attribs->numMultisample
441 );
442}
443
444
445static void
446print_visual_info(Display *dpy, int scrnum, InfoMode mode)
447{
448 XVisualInfo template;
449 XVisualInfo *visuals;
450 int numVisuals;
451 long mask;
452 int i;
453
454 /* get list of all visuals on this screen */
455 template.screen = scrnum;
456 mask = VisualScreenMask;
457 visuals = XGetVisualInfo(dpy, mask, &template, &numVisuals);
458
459 if (mode == Verbose) {
460 for (i = 0; i < numVisuals; i++) {
461 struct visual_attribs attribs;
462 get_visual_attribs(dpy, &visuals[i], &attribs);
463 print_visual_attribs_verbose(&attribs);
464 }
465 }
466 else if (mode == Normal) {
467 print_visual_attribs_short_header();
468 for (i = 0; i < numVisuals; i++) {
469 struct visual_attribs attribs;
470 get_visual_attribs(dpy, &visuals[i], &attribs);
471 print_visual_attribs_short(&attribs);
472 }
473 }
474 else if (mode == Wide) {
475 print_visual_attribs_long_header();
476 for (i = 0; i < numVisuals; i++) {
477 struct visual_attribs attribs;
478 get_visual_attribs(dpy, &visuals[i], &attribs);
479 print_visual_attribs_long(&attribs);
480 }
481 }
482
483 XFree(visuals);
484}
485
486
487int
488main(int argc, char *argv[])
489{
490 char *displayName = ":0";
491 Display *dpy;
492 int numScreens, scrnum;
493 InfoMode mode = Normal;
494 int i;
495
496 for (i = 1; i < argc; i++) {
497 if (strcmp(argv[i], "-display") == 0 && i + 1 < argc) {
498 displayName = argv[i + 1];
499 i++;
500 }
501 else if (strcmp(argv[i], "-t") == 0) {
502 mode = Wide;
503 }
504 else if (strcmp(argv[i], "-v") == 0) {
505 mode = Verbose;
506 }
507 }
508
509 dpy = XOpenDisplay(displayName);
510 if (!dpy) {
511 fprintf(stderr, "Error: unable to open display %s\n", displayName);
512 return -1;
513 }
514
515 numScreens = ScreenCount(dpy);
516 for (scrnum = 0; scrnum < numScreens; scrnum++) {
517 print_screen_info(dpy, 0);
518 printf("\n");
519 print_visual_info(dpy, 0, mode);
520 if (scrnum + 1 < numScreens)
521 printf("\n\n");
522 }
523
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000524 XCloseDisplay(dpy);
525
526 return 0;
527}