blob: 48a0a372571612dbaf6ac836802539d993631c38 [file] [log] [blame]
Brian Paula9c53fa2000-04-03 15:45:34 +00001/* $Id: glxinfo.c,v 1.7 2000/04/03 15:45:34 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 Paula9c53fa2000-04-03 15:45:34 +0000271 memset(attribs, 0, sizeof(struct visual_attribs));
272
Brian Paul76bc4402000-01-27 16:43:56 +0000273 attribs->id = vInfo->visualid;
274#if defined(__cplusplus) || defined(c_plusplus)
275 attribs->klass = vInfo->c_class;
276#else
277 attribs->klass = vInfo->class;
278#endif
279 attribs->depth = vInfo->depth;
280 attribs->redMask = vInfo->red_mask;
281 attribs->greenMask = vInfo->green_mask;
282 attribs->blueMask = vInfo->blue_mask;
283 attribs->colormapSize = vInfo->colormap_size;
284 attribs->bitsPerRGB = vInfo->bits_per_rgb;
285
Brian Paula9c53fa2000-04-03 15:45:34 +0000286 if (glXGetConfig(dpy, vInfo, GLX_USE_GL, &attribs->supportsGL) != 0)
287 return;
Brian Paul76bc4402000-01-27 16:43:56 +0000288 glXGetConfig(dpy, vInfo, GLX_BUFFER_SIZE, &attribs->bufferSize);
289 glXGetConfig(dpy, vInfo, GLX_LEVEL, &attribs->level);
290 glXGetConfig(dpy, vInfo, GLX_RGBA, &attribs->rgba);
291 glXGetConfig(dpy, vInfo, GLX_DOUBLEBUFFER, &attribs->doubleBuffer);
292 glXGetConfig(dpy, vInfo, GLX_STEREO, &attribs->stereo);
293 glXGetConfig(dpy, vInfo, GLX_AUX_BUFFERS, &attribs->auxBuffers);
294 glXGetConfig(dpy, vInfo, GLX_RED_SIZE, &attribs->redSize);
295 glXGetConfig(dpy, vInfo, GLX_GREEN_SIZE, &attribs->greenSize);
296 glXGetConfig(dpy, vInfo, GLX_BLUE_SIZE, &attribs->blueSize);
297 glXGetConfig(dpy, vInfo, GLX_ALPHA_SIZE, &attribs->alphaSize);
298 glXGetConfig(dpy, vInfo, GLX_DEPTH_SIZE, &attribs->depthSize);
299 glXGetConfig(dpy, vInfo, GLX_STENCIL_SIZE, &attribs->stencilSize);
300 glXGetConfig(dpy, vInfo, GLX_ACCUM_RED_SIZE, &attribs->accumRedSize);
301 glXGetConfig(dpy, vInfo, GLX_ACCUM_GREEN_SIZE, &attribs->accumGreenSize);
302 glXGetConfig(dpy, vInfo, GLX_ACCUM_BLUE_SIZE, &attribs->accumBlueSize);
303 glXGetConfig(dpy, vInfo, GLX_ACCUM_ALPHA_SIZE, &attribs->accumAlphaSize);
304
Brian Paule06c7f32000-01-27 16:53:55 +0000305 /* transparent pixel value not implemented yet */
306 attribs->transparent = 0;
307
308 /* multisample tests not implemented yet */
Brian Paul76bc4402000-01-27 16:43:56 +0000309 attribs->numSamples = 0;
310 attribs->numMultisample = 0;
Brian Paul25673f02000-03-31 18:17:51 +0000311
312#if defined(GLX_EXT_visual_rating)
313 if (ext && strstr(ext, "GLX_EXT_visual_rating")) {
314 glXGetConfig(dpy, vInfo, GLX_VISUAL_CAVEAT_EXT, &attribs->visualCaveat);
315 }
316 else {
317 attribs->visualCaveat = GLX_NONE_EXT;
318 }
319#else
320 attribs->visualCaveat = 0;
321#endif
Brian Paul76bc4402000-01-27 16:43:56 +0000322}
323
324
325static void
326print_visual_attribs_verbose(const struct visual_attribs *attribs)
327{
328 printf("Visual ID: %x depth=%d class=%s\n",
329 attribs->id, attribs->depth, visual_class_name(attribs->klass));
330 printf(" bufferSize=%d level=%d renderType=%s doubleBuffer=%d stereo=%d\n",
331 attribs->bufferSize, attribs->level, attribs->rgba ? "rgba" : "ci",
332 attribs->doubleBuffer, attribs->stereo);
333 printf(" rgba: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n",
334 attribs->redSize, attribs->greenSize,
335 attribs->blueSize, attribs->alphaSize);
336 printf(" auxBuffers=%d depthSize=%d stencilSize=%d\n",
337 attribs->auxBuffers, attribs->depthSize, attribs->stencilSize);
338 printf(" accum: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n",
339 attribs->accumRedSize, attribs->accumGreenSize,
340 attribs->accumBlueSize, attribs->accumAlphaSize);
341 printf(" multiSample=%d multiSampleBuffers=%d\n",
342 attribs->numSamples, attribs->numMultisample);
Brian Paul25673f02000-03-31 18:17:51 +0000343#ifdef GLX_EXT_visual_rating
344 if (attribs->visualCaveat == GLX_NONE_EXT || attribs->visualCaveat == 0)
Brian Paula9c53fa2000-04-03 15:45:34 +0000345 printf(" visualCaveat=None\n");
Brian Paul25673f02000-03-31 18:17:51 +0000346 else if (attribs->visualCaveat == GLX_SLOW_VISUAL_EXT)
Brian Paula9c53fa2000-04-03 15:45:34 +0000347 printf(" visualCaveat=Slow\n");
Brian Paul25673f02000-03-31 18:17:51 +0000348 else if (attribs->visualCaveat == GLX_NON_CONFORMANT_VISUAL_EXT)
Brian Paula9c53fa2000-04-03 15:45:34 +0000349 printf(" visualCaveat=Nonconformant\n");
Brian Paul25673f02000-03-31 18:17:51 +0000350#endif
Brian Paula9c53fa2000-04-03 15:45:34 +0000351 printf(" %s\n", attribs->transparent ? "Transparent." : "Opaque.");
Brian Paul76bc4402000-01-27 16:43:56 +0000352}
353
354
355static void
356print_visual_attribs_short_header(void)
357{
Brian Paula9c53fa2000-04-03 15:45:34 +0000358 printf(" visual x bf lv rg d st colorbuffer ax dp st accumbuffer ms cav\n");
359 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 +0000360 printf("----------------------------------------------------------------------\n");
Brian Paul76bc4402000-01-27 16:43:56 +0000361}
362
363
364static void
365print_visual_attribs_short(const struct visual_attribs *attribs)
366{
Brian Paul25673f02000-03-31 18:17:51 +0000367 char *caveat;
368#ifdef GLX_EXT_visual_rating
369 if (attribs->visualCaveat == GLX_NONE_EXT || attribs->visualCaveat == 0)
370 caveat = "None";
371 else if (attribs->visualCaveat == GLX_SLOW_VISUAL_EXT)
372 caveat = "Slow";
373 else if (attribs->visualCaveat == GLX_NON_CONFORMANT_VISUAL_EXT)
374 caveat = "Ncon";
375#else
376 caveat = "None";
377#endif
378
Brian Paul76bc4402000-01-27 16:43:56 +0000379 printf("0x%2x %2d %2s %2d %2d %2d %1s %2s %2s %2d %2d %2d %2d %2d %2d %2d",
380 attribs->id,
381 attribs->depth,
382 visual_class_abbrev(attribs->klass),
383 attribs->transparent,
384 attribs->bufferSize,
385 attribs->level,
386 attribs->rgba ? "r" : "c",
387 attribs->doubleBuffer ? "y" : ".",
388 attribs->stereo ? "y" : ".",
389 attribs->redSize, attribs->greenSize,
390 attribs->blueSize, attribs->alphaSize,
391 attribs->auxBuffers,
392 attribs->depthSize,
393 attribs->stencilSize
394 );
395
Brian Paul25673f02000-03-31 18:17:51 +0000396 printf(" %2d %2d %2d %2d %2d %1d %s\n",
Brian Paul76bc4402000-01-27 16:43:56 +0000397 attribs->accumRedSize, attribs->accumGreenSize,
398 attribs->accumBlueSize, attribs->accumAlphaSize,
Brian Paul25673f02000-03-31 18:17:51 +0000399 attribs->numSamples, attribs->numMultisample,
400 caveat
Brian Paul76bc4402000-01-27 16:43:56 +0000401 );
402}
403
404
405static void
406print_visual_attribs_long_header(void)
407{
408 printf("Vis Vis Visual Trans buff lev render DB ste r g b a aux dep ste accum buffers MS MS\n");
409 printf(" ID Depth Type parent size el type reo sz sz sz sz buf th ncl r g b a num bufs\n");
410 printf("----------------------------------------------------------------------------------------------------\n");
411}
412
413
414static void
415print_visual_attribs_long(const struct visual_attribs *attribs)
416{
417 printf("0x%2x %2d %-11s %2d %2d %2d %4s %3d %3d %3d %3d %3d %3d",
418 attribs->id,
419 attribs->depth,
420 visual_class_name(attribs->klass),
421 attribs->transparent,
422 attribs->bufferSize,
423 attribs->level,
424 attribs->rgba ? "rgba" : "ci ",
425 attribs->doubleBuffer,
426 attribs->stereo,
427 attribs->redSize, attribs->greenSize,
428 attribs->blueSize, attribs->alphaSize
429 );
430
431 printf(" %3d %4d %2d %3d %3d %3d %3d %2d %2d\n",
432 attribs->auxBuffers,
433 attribs->depthSize,
434 attribs->stencilSize,
435 attribs->accumRedSize, attribs->accumGreenSize,
436 attribs->accumBlueSize, attribs->accumAlphaSize,
437 attribs->numSamples, attribs->numMultisample
438 );
439}
440
441
442static void
443print_visual_info(Display *dpy, int scrnum, InfoMode mode)
444{
445 XVisualInfo template;
446 XVisualInfo *visuals;
447 int numVisuals;
448 long mask;
449 int i;
450
451 /* get list of all visuals on this screen */
452 template.screen = scrnum;
453 mask = VisualScreenMask;
454 visuals = XGetVisualInfo(dpy, mask, &template, &numVisuals);
455
456 if (mode == Verbose) {
457 for (i = 0; i < numVisuals; i++) {
458 struct visual_attribs attribs;
459 get_visual_attribs(dpy, &visuals[i], &attribs);
460 print_visual_attribs_verbose(&attribs);
461 }
462 }
463 else if (mode == Normal) {
464 print_visual_attribs_short_header();
465 for (i = 0; i < numVisuals; i++) {
466 struct visual_attribs attribs;
467 get_visual_attribs(dpy, &visuals[i], &attribs);
468 print_visual_attribs_short(&attribs);
469 }
470 }
471 else if (mode == Wide) {
472 print_visual_attribs_long_header();
473 for (i = 0; i < numVisuals; i++) {
474 struct visual_attribs attribs;
475 get_visual_attribs(dpy, &visuals[i], &attribs);
476 print_visual_attribs_long(&attribs);
477 }
478 }
479
480 XFree(visuals);
481}
482
483
484int
485main(int argc, char *argv[])
486{
487 char *displayName = ":0";
488 Display *dpy;
489 int numScreens, scrnum;
490 InfoMode mode = Normal;
491 int i;
492
493 for (i = 1; i < argc; i++) {
494 if (strcmp(argv[i], "-display") == 0 && i + 1 < argc) {
495 displayName = argv[i + 1];
496 i++;
497 }
498 else if (strcmp(argv[i], "-t") == 0) {
499 mode = Wide;
500 }
501 else if (strcmp(argv[i], "-v") == 0) {
502 mode = Verbose;
503 }
504 }
505
506 dpy = XOpenDisplay(displayName);
507 if (!dpy) {
508 fprintf(stderr, "Error: unable to open display %s\n", displayName);
509 return -1;
510 }
511
512 numScreens = ScreenCount(dpy);
513 for (scrnum = 0; scrnum < numScreens; scrnum++) {
514 print_screen_info(dpy, 0);
515 printf("\n");
516 print_visual_info(dpy, 0, mode);
517 if (scrnum + 1 < numScreens)
518 printf("\n\n");
519 }
520
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000521 XCloseDisplay(dpy);
522
523 return 0;
524}