blob: d4caf9478a5a366bf0ab2b79af3028db1732ee6c [file] [log] [blame]
Brian Paule06c7f32000-01-27 16:53:55 +00001/* $Id: glxinfo.c,v 1.3 2000/01/27 16:53:55 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;
77};
78
79
80/*
81 * Print a list of extensions, with word-wrapping.
82 */
83static void
84print_extension_list(const char *ext)
85{
86 const char *indentString = " ";
87 const int indent = 4;
88 const int max = 79;
89 int width, i, j;
90
91 if (!ext || !ext[0])
92 return;
93
94 width = indent;
95 printf(indentString);
96 i = j = 0;
97 while (1) {
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 */
103 printf("\n");
104 width = indent;
105 printf(indentString);
106 }
107 /* print the extension name between ext[i] and ext[j] */
108 while (i < j) {
109 printf("%c", ext[i]);
110 i++;
111 }
112 /* either we're all done, or we'll continue with next extension */
113 width += len + 1;
114 if (ext[j] == 0) {
115 break;
116 }
117 else {
118 i++;
119 j++;
120 printf(", ");
121 width += 2;
122 }
123 }
124 j++;
125 }
126 printf("\n");
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000127}
128
129
Brian Paul76bc4402000-01-27 16:43:56 +0000130static void
131print_screen_info(Display *dpy, int scrnum)
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000132{
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000133 Window win;
134 int attrib[] = { GLX_RGBA,
135 GLX_RED_SIZE, 1,
136 GLX_GREEN_SIZE, 1,
137 GLX_BLUE_SIZE, 1,
138 None };
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000139 XSetWindowAttributes attr;
140 unsigned long mask;
141 Window root;
142 GLXContext ctx;
143 XVisualInfo *visinfo;
144 int width = 100, height = 100;
145
Brian Paul76bc4402000-01-27 16:43:56 +0000146 root = RootWindow(dpy, scrnum);
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000147
Brian Paul76bc4402000-01-27 16:43:56 +0000148 visinfo = glXChooseVisual(dpy, scrnum, attrib);
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000149 if (!visinfo) {
150 fprintf(stderr, "Error: couldn't find RGB GLX visual!\n");
Brian Paul76bc4402000-01-27 16:43:56 +0000151 return;
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000152 }
153
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000154 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;
Brian Paul76bc4402000-01-27 16:43:56 +0000159 win = XCreateWindow(dpy, root, 0, 0, width, height,
160 0, visinfo->depth, InputOutput,
161 visinfo->visual, mask, &attr);
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000162
163 ctx = glXCreateContext( dpy, visinfo, NULL, True );
164
165 glXMakeCurrent( dpy, win, ctx );
166
Brian Paul76bc4402000-01-27 16:43:56 +0000167
168 {
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);
199 }
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000200
201 glXDestroyContext(dpy, ctx);
202 XDestroyWindow(dpy, win);
Brian Paul76bc4402000-01-27 16:43:56 +0000203}
204
205
206static const char *
207visual_class_name(int cls)
208{
209 switch (cls) {
210 case StaticColor:
211 return "StaticColor";
212 case PseudoColor:
213 return "PseudoColor";
214 case StaticGray:
215 return "StaticGray";
216 case GrayScale:
217 return "GrayScale";
218 case TrueColor:
219 return "TrueColor";
220 case DirectColor:
221 return "DirectColor";
222 default:
223 return "";
224 }
225}
226
227
228static const char *
229visual_class_abbrev(int cls)
230{
231 switch (cls) {
232 case StaticColor:
233 return "sc";
234 case PseudoColor:
235 return "pc";
236 case StaticGray:
237 return "sg";
238 case GrayScale:
239 return "gs";
240 case TrueColor:
241 return "tc";
242 case DirectColor:
243 return "dc";
244 default:
245 return "";
246 }
247}
248
249
250static void
251get_visual_attribs(Display *dpy, XVisualInfo *vInfo,
252 struct visual_attribs *attribs)
253{
254 attribs->id = vInfo->visualid;
255#if defined(__cplusplus) || defined(c_plusplus)
256 attribs->klass = vInfo->c_class;
257#else
258 attribs->klass = vInfo->class;
259#endif
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;
266
Brian Paul76bc4402000-01-27 16:43:56 +0000267 glXGetConfig(dpy, vInfo, GLX_USE_GL, &attribs->supportsGL);
268 glXGetConfig(dpy, vInfo, GLX_BUFFER_SIZE, &attribs->bufferSize);
269 glXGetConfig(dpy, vInfo, GLX_LEVEL, &attribs->level);
270 glXGetConfig(dpy, vInfo, GLX_RGBA, &attribs->rgba);
271 glXGetConfig(dpy, vInfo, GLX_DOUBLEBUFFER, &attribs->doubleBuffer);
272 glXGetConfig(dpy, vInfo, GLX_STEREO, &attribs->stereo);
273 glXGetConfig(dpy, vInfo, GLX_AUX_BUFFERS, &attribs->auxBuffers);
274 glXGetConfig(dpy, vInfo, GLX_RED_SIZE, &attribs->redSize);
275 glXGetConfig(dpy, vInfo, GLX_GREEN_SIZE, &attribs->greenSize);
276 glXGetConfig(dpy, vInfo, GLX_BLUE_SIZE, &attribs->blueSize);
277 glXGetConfig(dpy, vInfo, GLX_ALPHA_SIZE, &attribs->alphaSize);
278 glXGetConfig(dpy, vInfo, GLX_DEPTH_SIZE, &attribs->depthSize);
279 glXGetConfig(dpy, vInfo, GLX_STENCIL_SIZE, &attribs->stencilSize);
280 glXGetConfig(dpy, vInfo, GLX_ACCUM_RED_SIZE, &attribs->accumRedSize);
281 glXGetConfig(dpy, vInfo, GLX_ACCUM_GREEN_SIZE, &attribs->accumGreenSize);
282 glXGetConfig(dpy, vInfo, GLX_ACCUM_BLUE_SIZE, &attribs->accumBlueSize);
283 glXGetConfig(dpy, vInfo, GLX_ACCUM_ALPHA_SIZE, &attribs->accumAlphaSize);
284
Brian Paule06c7f32000-01-27 16:53:55 +0000285 /* transparent pixel value not implemented yet */
286 attribs->transparent = 0;
287
288 /* multisample tests not implemented yet */
Brian Paul76bc4402000-01-27 16:43:56 +0000289 attribs->numSamples = 0;
290 attribs->numMultisample = 0;
291}
292
293
294static void
295print_visual_attribs_verbose(const struct visual_attribs *attribs)
296{
297 printf("Visual ID: %x depth=%d class=%s\n",
298 attribs->id, attribs->depth, visual_class_name(attribs->klass));
299 printf(" bufferSize=%d level=%d renderType=%s doubleBuffer=%d stereo=%d\n",
300 attribs->bufferSize, attribs->level, attribs->rgba ? "rgba" : "ci",
301 attribs->doubleBuffer, attribs->stereo);
302 printf(" rgba: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n",
303 attribs->redSize, attribs->greenSize,
304 attribs->blueSize, attribs->alphaSize);
305 printf(" auxBuffers=%d depthSize=%d stencilSize=%d\n",
306 attribs->auxBuffers, attribs->depthSize, attribs->stencilSize);
307 printf(" accum: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n",
308 attribs->accumRedSize, attribs->accumGreenSize,
309 attribs->accumBlueSize, attribs->accumAlphaSize);
310 printf(" multiSample=%d multiSampleBuffers=%d\n",
311 attribs->numSamples, attribs->numMultisample);
312 printf(" %s\n", attribs->transparent ? "Transparent." : "Opaque.");
313}
314
315
316static void
317print_visual_attribs_short_header(void)
318{
319 printf(" visual x bf lv rg d st r g b a ax dp st accum buffs ms \n");
320 printf(" id dep cl sp sz l ci b ro sz sz sz sz bf th cl r g b a ns b\n");
321 printf("-----------------------------------------------------------------\n");
322}
323
324
325static void
326print_visual_attribs_short(const struct visual_attribs *attribs)
327{
328 printf("0x%2x %2d %2s %2d %2d %2d %1s %2s %2s %2d %2d %2d %2d %2d %2d %2d",
329 attribs->id,
330 attribs->depth,
331 visual_class_abbrev(attribs->klass),
332 attribs->transparent,
333 attribs->bufferSize,
334 attribs->level,
335 attribs->rgba ? "r" : "c",
336 attribs->doubleBuffer ? "y" : ".",
337 attribs->stereo ? "y" : ".",
338 attribs->redSize, attribs->greenSize,
339 attribs->blueSize, attribs->alphaSize,
340 attribs->auxBuffers,
341 attribs->depthSize,
342 attribs->stencilSize
343 );
344
345 printf(" %2d %2d %2d %2d %2d %1d\n",
346 attribs->accumRedSize, attribs->accumGreenSize,
347 attribs->accumBlueSize, attribs->accumAlphaSize,
348 attribs->numSamples, attribs->numMultisample
349 );
350}
351
352
353static void
354print_visual_attribs_long_header(void)
355{
356 printf("Vis Vis Visual Trans buff lev render DB ste r g b a aux dep ste accum buffers MS MS\n");
357 printf(" ID Depth Type parent size el type reo sz sz sz sz buf th ncl r g b a num bufs\n");
358 printf("----------------------------------------------------------------------------------------------------\n");
359}
360
361
362static void
363print_visual_attribs_long(const struct visual_attribs *attribs)
364{
365 printf("0x%2x %2d %-11s %2d %2d %2d %4s %3d %3d %3d %3d %3d %3d",
366 attribs->id,
367 attribs->depth,
368 visual_class_name(attribs->klass),
369 attribs->transparent,
370 attribs->bufferSize,
371 attribs->level,
372 attribs->rgba ? "rgba" : "ci ",
373 attribs->doubleBuffer,
374 attribs->stereo,
375 attribs->redSize, attribs->greenSize,
376 attribs->blueSize, attribs->alphaSize
377 );
378
379 printf(" %3d %4d %2d %3d %3d %3d %3d %2d %2d\n",
380 attribs->auxBuffers,
381 attribs->depthSize,
382 attribs->stencilSize,
383 attribs->accumRedSize, attribs->accumGreenSize,
384 attribs->accumBlueSize, attribs->accumAlphaSize,
385 attribs->numSamples, attribs->numMultisample
386 );
387}
388
389
390static void
391print_visual_info(Display *dpy, int scrnum, InfoMode mode)
392{
393 XVisualInfo template;
394 XVisualInfo *visuals;
395 int numVisuals;
396 long mask;
397 int i;
398
399 /* get list of all visuals on this screen */
400 template.screen = scrnum;
401 mask = VisualScreenMask;
402 visuals = XGetVisualInfo(dpy, mask, &template, &numVisuals);
403
404 if (mode == Verbose) {
405 for (i = 0; i < numVisuals; i++) {
406 struct visual_attribs attribs;
407 get_visual_attribs(dpy, &visuals[i], &attribs);
408 print_visual_attribs_verbose(&attribs);
409 }
410 }
411 else if (mode == Normal) {
412 print_visual_attribs_short_header();
413 for (i = 0; i < numVisuals; i++) {
414 struct visual_attribs attribs;
415 get_visual_attribs(dpy, &visuals[i], &attribs);
416 print_visual_attribs_short(&attribs);
417 }
418 }
419 else if (mode == Wide) {
420 print_visual_attribs_long_header();
421 for (i = 0; i < numVisuals; i++) {
422 struct visual_attribs attribs;
423 get_visual_attribs(dpy, &visuals[i], &attribs);
424 print_visual_attribs_long(&attribs);
425 }
426 }
427
428 XFree(visuals);
429}
430
431
432int
433main(int argc, char *argv[])
434{
435 char *displayName = ":0";
436 Display *dpy;
437 int numScreens, scrnum;
438 InfoMode mode = Normal;
439 int i;
440
441 for (i = 1; i < argc; i++) {
442 if (strcmp(argv[i], "-display") == 0 && i + 1 < argc) {
443 displayName = argv[i + 1];
444 i++;
445 }
446 else if (strcmp(argv[i], "-t") == 0) {
447 mode = Wide;
448 }
449 else if (strcmp(argv[i], "-v") == 0) {
450 mode = Verbose;
451 }
452 }
453
454 dpy = XOpenDisplay(displayName);
455 if (!dpy) {
456 fprintf(stderr, "Error: unable to open display %s\n", displayName);
457 return -1;
458 }
459
460 numScreens = ScreenCount(dpy);
461 for (scrnum = 0; scrnum < numScreens; scrnum++) {
462 print_screen_info(dpy, 0);
463 printf("\n");
464 print_visual_info(dpy, 0, mode);
465 if (scrnum + 1 < numScreens)
466 printf("\n\n");
467 }
468
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000469 XCloseDisplay(dpy);
470
471 return 0;
472}