blob: 957761273c1af49100631d5c937dc13511d14f52 [file] [log] [blame]
Brian Pauld2bfe1e1999-09-16 16:40:46 +00001/*
Brian Paul2f7ef5f2002-09-06 03:35:43 +00002 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
Brian Paul76bc4402000-01-27 16:43:56 +00003 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Brian Pauld2bfe1e1999-09-16 16:40:46 +000020 */
21
22
Brian Paul76bc4402000-01-27 16:43:56 +000023/*
24 * This program is a work-alike of the IRIX glxinfo program.
25 * Command line options:
26 * -t print wide table
27 * -v print verbose information
28 * -display DisplayName specify the X display to interogate
Brian Paul39557c32001-03-23 21:41:44 +000029 * -b only print ID of "best" visual on screen 0
Brian Paul28bc6cb2002-09-06 03:47:34 +000030 * -i use indirect rendering connection only
Brian Paul2f7ef5f2002-09-06 03:35:43 +000031 * -l print interesting OpenGL limits (added 5 Sep 2002)
Brian Paul76bc4402000-01-27 16:43:56 +000032 *
33 * Brian Paul 26 January 2000
34 */
Brian Pauld2bfe1e1999-09-16 16:40:46 +000035
Brian Paul39557c32001-03-23 21:41:44 +000036#define DO_GLU /* may want to remove this for easier XFree86 building? */
Brian Paul76bc4402000-01-27 16:43:56 +000037
38#include <X11/Xlib.h>
39#include <X11/Xutil.h>
Brian Pauld2bfe1e1999-09-16 16:40:46 +000040#include <GL/gl.h>
Brian Paul39557c32001-03-23 21:41:44 +000041#ifdef DO_GLU
Brian Pauld2bfe1e1999-09-16 16:40:46 +000042#include <GL/glu.h>
Brian Paul39557c32001-03-23 21:41:44 +000043#endif
Brian Paul76bc4402000-01-27 16:43:56 +000044#include <GL/glx.h>
Brian Pauld2bfe1e1999-09-16 16:40:46 +000045#include <stdio.h>
Brian Paul76bc4402000-01-27 16:43:56 +000046#include <string.h>
Brian Paul373aea12001-04-02 22:45:07 +000047#include <stdlib.h>
Brian Pauld2bfe1e1999-09-16 16:40:46 +000048
49
Brian Paul39557c32001-03-23 21:41:44 +000050#ifndef GLX_NONE_EXT
51#define GLX_NONE_EXT 0x8000
52#endif
53
Brian Paul45c56982002-10-14 13:57:23 +000054#ifndef GLX_TRANSPARENT_RGB
55#define GLX_TRANSPARENT_RGB 0x8008
56#endif
Brian Paul39557c32001-03-23 21:41:44 +000057
Brian Paul76bc4402000-01-27 16:43:56 +000058typedef enum
Brian Pauld2bfe1e1999-09-16 16:40:46 +000059{
Brian Paul76bc4402000-01-27 16:43:56 +000060 Normal,
61 Wide,
62 Verbose
63} InfoMode;
Brian Pauld2bfe1e1999-09-16 16:40:46 +000064
Brian Pauld2bfe1e1999-09-16 16:40:46 +000065
Brian Paul76bc4402000-01-27 16:43:56 +000066struct visual_attribs
67{
68 /* X visual attribs */
69 int id;
70 int klass;
71 int depth;
72 int redMask, greenMask, blueMask;
73 int colormapSize;
74 int bitsPerRGB;
Brian Pauld2bfe1e1999-09-16 16:40:46 +000075
Brian Paul76bc4402000-01-27 16:43:56 +000076 /* GL visual attribs */
77 int supportsGL;
Brian Paul45c56982002-10-14 13:57:23 +000078 int transparentType;
79 int transparentRedValue;
80 int transparentGreenValue;
81 int transparentBlueValue;
82 int transparentAlphaValue;
83 int transparentIndexValue;
Brian Paul76bc4402000-01-27 16:43:56 +000084 int bufferSize;
85 int level;
86 int rgba;
87 int doubleBuffer;
88 int stereo;
89 int auxBuffers;
90 int redSize, greenSize, blueSize, alphaSize;
91 int depthSize;
92 int stencilSize;
93 int accumRedSize, accumGreenSize, accumBlueSize, accumAlphaSize;
94 int numSamples, numMultisample;
Brian Paul25673f02000-03-31 18:17:51 +000095 int visualCaveat;
Brian Paul76bc4402000-01-27 16:43:56 +000096};
97
98
99/*
100 * Print a list of extensions, with word-wrapping.
101 */
102static void
103print_extension_list(const char *ext)
104{
105 const char *indentString = " ";
106 const int indent = 4;
107 const int max = 79;
108 int width, i, j;
109
110 if (!ext || !ext[0])
111 return;
112
113 width = indent;
114 printf(indentString);
115 i = j = 0;
116 while (1) {
117 if (ext[j] == ' ' || ext[j] == 0) {
118 /* found end of an extension name */
119 const int len = j - i;
120 if (width + len > max) {
121 /* start a new line */
122 printf("\n");
123 width = indent;
124 printf(indentString);
125 }
126 /* print the extension name between ext[i] and ext[j] */
127 while (i < j) {
128 printf("%c", ext[i]);
129 i++;
130 }
131 /* either we're all done, or we'll continue with next extension */
132 width += len + 1;
133 if (ext[j] == 0) {
134 break;
135 }
136 else {
137 i++;
138 j++;
Brian Paul7ac43502000-02-23 22:50:35 +0000139 if (ext[j] == 0)
140 break;
Brian Paul76bc4402000-01-27 16:43:56 +0000141 printf(", ");
142 width += 2;
143 }
144 }
145 j++;
146 }
147 printf("\n");
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000148}
149
150
Brian Paul76bc4402000-01-27 16:43:56 +0000151static void
Brian Paul373aea12001-04-02 22:45:07 +0000152print_display_info(Display *dpy)
153{
154 printf("name of display: %s\n", DisplayString(dpy));
155}
156
157
158static void
Brian Paul2f7ef5f2002-09-06 03:35:43 +0000159print_limits(void)
160{
161 struct token_name {
162 GLuint count;
163 GLenum token;
164 const char *name;
165 };
166 static const struct token_name limits[] = {
167 { 1, GL_MAX_ATTRIB_STACK_DEPTH, "GL_MAX_ATTRIB_STACK_DEPTH" },
168 { 1, GL_MAX_CLIENT_ATTRIB_STACK_DEPTH, "GL_MAX_CLIENT_ATTRIB_STACK_DEPTH" },
169 { 1, GL_MAX_CLIP_PLANES, "GL_MAX_CLIP_PLANES" },
170 { 1, GL_MAX_COLOR_MATRIX_STACK_DEPTH, "GL_MAX_COLOR_MATRIX_STACK_DEPTH" },
Brian Paul2f7ef5f2002-09-06 03:35:43 +0000171 { 1, GL_MAX_ELEMENTS_VERTICES, "GL_MAX_ELEMENTS_VERTICES" },
172 { 1, GL_MAX_ELEMENTS_INDICES, "GL_MAX_ELEMENTS_INDICES" },
173 { 1, GL_MAX_EVAL_ORDER, "GL_MAX_EVAL_ORDER" },
174 { 1, GL_MAX_LIGHTS, "GL_MAX_LIGHTS" },
175 { 1, GL_MAX_LIST_NESTING, "GL_MAX_LIST_NESTING" },
176 { 1, GL_MAX_MODELVIEW_STACK_DEPTH, "GL_MAX_MODELVIEW_STACK_DEPTH" },
177 { 1, GL_MAX_NAME_STACK_DEPTH, "GL_MAX_NAME_STACK_DEPTH" },
178 { 1, GL_MAX_PIXEL_MAP_TABLE, "GL_MAX_PIXEL_MAP_TABLE" },
179 { 1, GL_MAX_PROJECTION_STACK_DEPTH, "GL_MAX_PROJECTION_STACK_DEPTH" },
180 { 1, GL_MAX_TEXTURE_STACK_DEPTH, "GL_MAX_TEXTURE_STACK_DEPTH" },
181 { 1, GL_MAX_TEXTURE_SIZE, "GL_MAX_TEXTURE_SIZE" },
182 { 1, GL_MAX_3D_TEXTURE_SIZE, "GL_MAX_3D_TEXTURE_SIZE" },
183 { 1, GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB, "GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB" },
184 { 1, GL_MAX_RECTANGLE_TEXTURE_SIZE_NV, "GL_MAX_RECTANGLE_TEXTURE_SIZE_NV" },
185 { 1, GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB, "GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB" },
186 { 1, GL_MAX_TEXTURE_UNITS_ARB, "GL_MAX_TEXTURE_UNITS_ARB" },
187 { 1, GL_MAX_TEXTURE_LOD_BIAS_EXT, "GL_MAX_TEXTURE_LOD_BIAS_EXT" },
188 { 1, GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, "GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT" },
189 { 2, GL_MAX_VIEWPORT_DIMS, "GL_MAX_VIEWPORT_DIMS" },
190 { 2, GL_ALIASED_LINE_WIDTH_RANGE, "GL_ALIASED_LINE_WIDTH_RANGE" },
191 { 2, GL_SMOOTH_LINE_WIDTH_RANGE, "GL_SMOOTH_LINE_WIDTH_RANGE" },
192 { 2, GL_ALIASED_POINT_SIZE_RANGE, "GL_ALIASED_POINT_SIZE_RANGE" },
193 { 2, GL_SMOOTH_POINT_SIZE_RANGE, "GL_SMOOTH_POINT_SIZE_RANGE" },
194 { 0, (GLenum) 0, NULL }
195 };
196 GLint i, max[2];
197 printf("OpenGL limits:\n");
198 for (i = 0; limits[i].count; i++) {
199 glGetIntegerv(limits[i].token, max);
200 if (glGetError() == GL_NONE) {
201 if (limits[i].count == 1)
202 printf(" %s = %d\n", limits[i].name, max[0]);
203 else /* XXX fix if we ever query something with more than 2 values */
204 printf(" %s = %d, %d\n", limits[i].name, max[0], max[1]);
205 }
206 }
Brian Paulf2afdca2004-08-10 15:32:25 +0000207 /* these don't fit into the above mechanism, unfortunately */
208 glGetConvolutionParameteriv(GL_CONVOLUTION_2D, GL_MAX_CONVOLUTION_WIDTH, max);
209 glGetConvolutionParameteriv(GL_CONVOLUTION_2D, GL_MAX_CONVOLUTION_HEIGHT, max+1);
210 if (glGetError() == GL_NONE) {
211 printf(" GL_MAX_CONVOLUTION_WIDTH/HEIGHT = %d, %d\n", max[0], max[1]);
212 }
213
Brian Paul2f7ef5f2002-09-06 03:35:43 +0000214}
215
216
217static void
218print_screen_info(Display *dpy, int scrnum, Bool allowDirect, GLboolean limits)
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000219{
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000220 Window win;
Brian Paul8460cc92000-02-02 20:57:51 +0000221 int attribSingle[] = {
222 GLX_RGBA,
223 GLX_RED_SIZE, 1,
224 GLX_GREEN_SIZE, 1,
225 GLX_BLUE_SIZE, 1,
226 None };
227 int attribDouble[] = {
228 GLX_RGBA,
229 GLX_RED_SIZE, 1,
230 GLX_GREEN_SIZE, 1,
231 GLX_BLUE_SIZE, 1,
232 GLX_DOUBLEBUFFER,
233 None };
234
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000235 XSetWindowAttributes attr;
236 unsigned long mask;
237 Window root;
238 GLXContext ctx;
239 XVisualInfo *visinfo;
240 int width = 100, height = 100;
241
Brian Paul76bc4402000-01-27 16:43:56 +0000242 root = RootWindow(dpy, scrnum);
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000243
Brian Paul8460cc92000-02-02 20:57:51 +0000244 visinfo = glXChooseVisual(dpy, scrnum, attribSingle);
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000245 if (!visinfo) {
Brian Paul8460cc92000-02-02 20:57:51 +0000246 visinfo = glXChooseVisual(dpy, scrnum, attribDouble);
247 if (!visinfo) {
Brian Paul9cff5582000-05-07 18:07:23 +0000248 fprintf(stderr, "Error: couldn't find RGB GLX visual\n");
Brian Paul8460cc92000-02-02 20:57:51 +0000249 return;
250 }
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000251 }
252
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000253 attr.background_pixel = 0;
254 attr.border_pixel = 0;
Brian Paul9cff5582000-05-07 18:07:23 +0000255 attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone);
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000256 attr.event_mask = StructureNotifyMask | ExposureMask;
257 mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
Brian Paul76bc4402000-01-27 16:43:56 +0000258 win = XCreateWindow(dpy, root, 0, 0, width, height,
259 0, visinfo->depth, InputOutput,
260 visinfo->visual, mask, &attr);
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000261
Brian Paul08b3ff12001-04-24 20:57:36 +0000262 ctx = glXCreateContext( dpy, visinfo, NULL, allowDirect );
Brian Paul34fb5db2000-04-22 20:31:23 +0000263 if (!ctx) {
Brian Paul9cff5582000-05-07 18:07:23 +0000264 fprintf(stderr, "Error: glXCreateContext failed\n");
Brian Paul361bccb2006-01-16 16:17:18 +0000265 XFree(visinfo);
Brian Paul34fb5db2000-04-22 20:31:23 +0000266 XDestroyWindow(dpy, win);
267 return;
268 }
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000269
Brian Paul9cff5582000-05-07 18:07:23 +0000270 if (glXMakeCurrent(dpy, win, ctx)) {
Brian Paul76bc4402000-01-27 16:43:56 +0000271 const char *serverVendor = glXQueryServerString(dpy, scrnum, GLX_VENDOR);
272 const char *serverVersion = glXQueryServerString(dpy, scrnum, GLX_VERSION);
273 const char *serverExtensions = glXQueryServerString(dpy, scrnum, GLX_EXTENSIONS);
Brian Paul34fb5db2000-04-22 20:31:23 +0000274 const char *clientVendor = glXGetClientString(dpy, GLX_VENDOR);
Brian Paul76bc4402000-01-27 16:43:56 +0000275 const char *clientVersion = glXGetClientString(dpy, GLX_VERSION);
276 const char *clientExtensions = glXGetClientString(dpy, GLX_EXTENSIONS);
277 const char *glxExtensions = glXQueryExtensionsString(dpy, scrnum);
278 const char *glVendor = (const char *) glGetString(GL_VENDOR);
279 const char *glRenderer = (const char *) glGetString(GL_RENDERER);
280 const char *glVersion = (const char *) glGetString(GL_VERSION);
281 const char *glExtensions = (const char *) glGetString(GL_EXTENSIONS);
Ian Romanickc00fbd52004-02-23 17:37:36 +0000282 int glxVersionMajor;
283 int glxVersionMinor;
Brian Paul373aea12001-04-02 22:45:07 +0000284 char *displayName = NULL;
285 char *colon = NULL, *period = NULL;
Brian Paul39557c32001-03-23 21:41:44 +0000286#ifdef DO_GLU
Brian Paul76bc4402000-01-27 16:43:56 +0000287 const char *gluVersion = (const char *) gluGetString(GLU_VERSION);
288 const char *gluExtensions = (const char *) gluGetString(GLU_EXTENSIONS);
Brian Paul39557c32001-03-23 21:41:44 +0000289#endif
Ian Romanickc00fbd52004-02-23 17:37:36 +0000290
291 if (! glXQueryVersion( dpy, & glxVersionMajor, & glxVersionMinor )) {
292 fprintf(stderr, "Error: glXQueryVersion failed\n");
293 exit(1);
294 }
295
Brian Paul373aea12001-04-02 22:45:07 +0000296 /* Strip the screen number from the display name, if present. */
Brian Paulf02a5f62002-07-12 15:54:01 +0000297 if (!(displayName = (char *) malloc(strlen(DisplayString(dpy)) + 1))) {
Brian Paul373aea12001-04-02 22:45:07 +0000298 fprintf(stderr, "Error: malloc() failed\n");
299 exit(1);
300 }
301 strcpy(displayName, DisplayString(dpy));
302 colon = strrchr(displayName, ':');
303 if (colon) {
304 period = strchr(colon, '.');
305 if (period)
306 *period = '\0';
307 }
308 printf("display: %s screen: %d\n", displayName, scrnum);
309 free(displayName);
Brian Paule691ee22000-05-08 14:53:57 +0000310 printf("direct rendering: %s\n", glXIsDirect(dpy, ctx) ? "Yes" : "No");
Brian Paul76bc4402000-01-27 16:43:56 +0000311 printf("server glx vendor string: %s\n", serverVendor);
312 printf("server glx version string: %s\n", serverVersion);
313 printf("server glx extensions:\n");
314 print_extension_list(serverExtensions);
Brian Paul34fb5db2000-04-22 20:31:23 +0000315 printf("client glx vendor string: %s\n", clientVendor);
316 printf("client glx version string: %s\n", clientVersion);
Brian Paul76bc4402000-01-27 16:43:56 +0000317 printf("client glx extensions:\n");
318 print_extension_list(clientExtensions);
Ian Romanickc00fbd52004-02-23 17:37:36 +0000319 printf("GLX version: %u.%u\n", glxVersionMajor, glxVersionMinor);
Brian Paul76bc4402000-01-27 16:43:56 +0000320 printf("GLX extensions:\n");
321 print_extension_list(glxExtensions);
322 printf("OpenGL vendor string: %s\n", glVendor);
323 printf("OpenGL renderer string: %s\n", glRenderer);
324 printf("OpenGL version string: %s\n", glVersion);
325 printf("OpenGL extensions:\n");
326 print_extension_list(glExtensions);
Brian Paul2f7ef5f2002-09-06 03:35:43 +0000327 if (limits)
328 print_limits();
Brian Paul39557c32001-03-23 21:41:44 +0000329#ifdef DO_GLU
Brian Paul76bc4402000-01-27 16:43:56 +0000330 printf("glu version: %s\n", gluVersion);
331 printf("glu extensions:\n");
332 print_extension_list(gluExtensions);
Brian Paul39557c32001-03-23 21:41:44 +0000333#endif
Brian Paul76bc4402000-01-27 16:43:56 +0000334 }
Brian Paul9cff5582000-05-07 18:07:23 +0000335 else {
336 fprintf(stderr, "Error: glXMakeCurrent failed\n");
337 }
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000338
339 glXDestroyContext(dpy, ctx);
Brian Paul361bccb2006-01-16 16:17:18 +0000340 XFree(visinfo);
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000341 XDestroyWindow(dpy, win);
Brian Paul76bc4402000-01-27 16:43:56 +0000342}
343
344
345static const char *
346visual_class_name(int cls)
347{
348 switch (cls) {
349 case StaticColor:
350 return "StaticColor";
351 case PseudoColor:
352 return "PseudoColor";
353 case StaticGray:
354 return "StaticGray";
355 case GrayScale:
356 return "GrayScale";
357 case TrueColor:
358 return "TrueColor";
359 case DirectColor:
360 return "DirectColor";
361 default:
362 return "";
363 }
364}
365
366
367static const char *
368visual_class_abbrev(int cls)
369{
370 switch (cls) {
371 case StaticColor:
372 return "sc";
373 case PseudoColor:
374 return "pc";
375 case StaticGray:
376 return "sg";
377 case GrayScale:
378 return "gs";
379 case TrueColor:
380 return "tc";
381 case DirectColor:
382 return "dc";
383 default:
384 return "";
385 }
386}
387
388
389static void
390get_visual_attribs(Display *dpy, XVisualInfo *vInfo,
391 struct visual_attribs *attribs)
392{
Brian Paul25673f02000-03-31 18:17:51 +0000393 const char *ext = glXQueryExtensionsString(dpy, vInfo->screen);
394
Brian Paula9c53fa2000-04-03 15:45:34 +0000395 memset(attribs, 0, sizeof(struct visual_attribs));
396
Brian Paul76bc4402000-01-27 16:43:56 +0000397 attribs->id = vInfo->visualid;
398#if defined(__cplusplus) || defined(c_plusplus)
399 attribs->klass = vInfo->c_class;
400#else
401 attribs->klass = vInfo->class;
402#endif
403 attribs->depth = vInfo->depth;
404 attribs->redMask = vInfo->red_mask;
405 attribs->greenMask = vInfo->green_mask;
406 attribs->blueMask = vInfo->blue_mask;
407 attribs->colormapSize = vInfo->colormap_size;
408 attribs->bitsPerRGB = vInfo->bits_per_rgb;
409
Brian Paula9c53fa2000-04-03 15:45:34 +0000410 if (glXGetConfig(dpy, vInfo, GLX_USE_GL, &attribs->supportsGL) != 0)
411 return;
Brian Paul76bc4402000-01-27 16:43:56 +0000412 glXGetConfig(dpy, vInfo, GLX_BUFFER_SIZE, &attribs->bufferSize);
413 glXGetConfig(dpy, vInfo, GLX_LEVEL, &attribs->level);
414 glXGetConfig(dpy, vInfo, GLX_RGBA, &attribs->rgba);
415 glXGetConfig(dpy, vInfo, GLX_DOUBLEBUFFER, &attribs->doubleBuffer);
416 glXGetConfig(dpy, vInfo, GLX_STEREO, &attribs->stereo);
417 glXGetConfig(dpy, vInfo, GLX_AUX_BUFFERS, &attribs->auxBuffers);
418 glXGetConfig(dpy, vInfo, GLX_RED_SIZE, &attribs->redSize);
419 glXGetConfig(dpy, vInfo, GLX_GREEN_SIZE, &attribs->greenSize);
420 glXGetConfig(dpy, vInfo, GLX_BLUE_SIZE, &attribs->blueSize);
421 glXGetConfig(dpy, vInfo, GLX_ALPHA_SIZE, &attribs->alphaSize);
422 glXGetConfig(dpy, vInfo, GLX_DEPTH_SIZE, &attribs->depthSize);
423 glXGetConfig(dpy, vInfo, GLX_STENCIL_SIZE, &attribs->stencilSize);
424 glXGetConfig(dpy, vInfo, GLX_ACCUM_RED_SIZE, &attribs->accumRedSize);
425 glXGetConfig(dpy, vInfo, GLX_ACCUM_GREEN_SIZE, &attribs->accumGreenSize);
426 glXGetConfig(dpy, vInfo, GLX_ACCUM_BLUE_SIZE, &attribs->accumBlueSize);
427 glXGetConfig(dpy, vInfo, GLX_ACCUM_ALPHA_SIZE, &attribs->accumAlphaSize);
428
Brian Paul45c56982002-10-14 13:57:23 +0000429 /* get transparent pixel stuff */
430 glXGetConfig(dpy, vInfo,GLX_TRANSPARENT_TYPE, &attribs->transparentType);
431 if (attribs->transparentType == GLX_TRANSPARENT_RGB) {
432 glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_RED_VALUE, &attribs->transparentRedValue);
433 glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_GREEN_VALUE, &attribs->transparentGreenValue);
434 glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_BLUE_VALUE, &attribs->transparentBlueValue);
435 glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_ALPHA_VALUE, &attribs->transparentAlphaValue);
436 }
437 else if (attribs->transparentType == GLX_TRANSPARENT_INDEX) {
438 glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_INDEX_VALUE, &attribs->transparentIndexValue);
439 }
Brian Paule06c7f32000-01-27 16:53:55 +0000440
Brian Pauld2e39bb2002-11-04 16:24:18 +0000441 /* multisample attribs */
442#ifdef GLX_ARB_multisample
443 if (strstr("GLX_ARB_multisample", ext) == 0) {
444 glXGetConfig(dpy, vInfo, GLX_SAMPLE_BUFFERS_ARB, &attribs->numMultisample);
445 glXGetConfig(dpy, vInfo, GLX_SAMPLES_ARB, &attribs->numSamples);
446 }
447#endif
448 else {
449 attribs->numSamples = 0;
450 attribs->numMultisample = 0;
451 }
Brian Paul25673f02000-03-31 18:17:51 +0000452
453#if defined(GLX_EXT_visual_rating)
454 if (ext && strstr(ext, "GLX_EXT_visual_rating")) {
455 glXGetConfig(dpy, vInfo, GLX_VISUAL_CAVEAT_EXT, &attribs->visualCaveat);
456 }
457 else {
458 attribs->visualCaveat = GLX_NONE_EXT;
459 }
460#else
461 attribs->visualCaveat = 0;
462#endif
Brian Paul76bc4402000-01-27 16:43:56 +0000463}
464
465
466static void
467print_visual_attribs_verbose(const struct visual_attribs *attribs)
468{
469 printf("Visual ID: %x depth=%d class=%s\n",
470 attribs->id, attribs->depth, visual_class_name(attribs->klass));
471 printf(" bufferSize=%d level=%d renderType=%s doubleBuffer=%d stereo=%d\n",
472 attribs->bufferSize, attribs->level, attribs->rgba ? "rgba" : "ci",
473 attribs->doubleBuffer, attribs->stereo);
474 printf(" rgba: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n",
475 attribs->redSize, attribs->greenSize,
476 attribs->blueSize, attribs->alphaSize);
477 printf(" auxBuffers=%d depthSize=%d stencilSize=%d\n",
478 attribs->auxBuffers, attribs->depthSize, attribs->stencilSize);
479 printf(" accum: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n",
480 attribs->accumRedSize, attribs->accumGreenSize,
481 attribs->accumBlueSize, attribs->accumAlphaSize);
482 printf(" multiSample=%d multiSampleBuffers=%d\n",
483 attribs->numSamples, attribs->numMultisample);
Brian Paul25673f02000-03-31 18:17:51 +0000484#ifdef GLX_EXT_visual_rating
485 if (attribs->visualCaveat == GLX_NONE_EXT || attribs->visualCaveat == 0)
Brian Paula9c53fa2000-04-03 15:45:34 +0000486 printf(" visualCaveat=None\n");
Brian Paul25673f02000-03-31 18:17:51 +0000487 else if (attribs->visualCaveat == GLX_SLOW_VISUAL_EXT)
Brian Paula9c53fa2000-04-03 15:45:34 +0000488 printf(" visualCaveat=Slow\n");
Brian Paul25673f02000-03-31 18:17:51 +0000489 else if (attribs->visualCaveat == GLX_NON_CONFORMANT_VISUAL_EXT)
Brian Paula9c53fa2000-04-03 15:45:34 +0000490 printf(" visualCaveat=Nonconformant\n");
Brian Paul25673f02000-03-31 18:17:51 +0000491#endif
Brian Paul45c56982002-10-14 13:57:23 +0000492 if (attribs->transparentType == GLX_NONE) {
493 printf(" Opaque.\n");
494 }
495 else if (attribs->transparentType == GLX_TRANSPARENT_RGB) {
496 printf(" Transparent RGB: Red=%d Green=%d Blue=%d Alpha=%d\n",attribs->transparentRedValue,attribs->transparentGreenValue,attribs->transparentBlueValue,attribs->transparentAlphaValue);
497 }
498 else if (attribs->transparentType == GLX_TRANSPARENT_INDEX) {
499 printf(" Transparent index=%d\n",attribs->transparentIndexValue);
500 }
Brian Paul76bc4402000-01-27 16:43:56 +0000501}
502
503
504static void
505print_visual_attribs_short_header(void)
506{
Brian Paula9c53fa2000-04-03 15:45:34 +0000507 printf(" visual x bf lv rg d st colorbuffer ax dp st accumbuffer ms cav\n");
508 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 +0000509 printf("----------------------------------------------------------------------\n");
Brian Paul76bc4402000-01-27 16:43:56 +0000510}
511
512
513static void
514print_visual_attribs_short(const struct visual_attribs *attribs)
515{
Brian Paula3e44f42002-03-08 19:44:28 +0000516 char *caveat = NULL;
Brian Paul25673f02000-03-31 18:17:51 +0000517#ifdef GLX_EXT_visual_rating
518 if (attribs->visualCaveat == GLX_NONE_EXT || attribs->visualCaveat == 0)
519 caveat = "None";
520 else if (attribs->visualCaveat == GLX_SLOW_VISUAL_EXT)
521 caveat = "Slow";
522 else if (attribs->visualCaveat == GLX_NON_CONFORMANT_VISUAL_EXT)
523 caveat = "Ncon";
Brian Paul28bc6cb2002-09-06 03:47:34 +0000524 else
525 caveat = "None";
Brian Paul25673f02000-03-31 18:17:51 +0000526#else
527 caveat = "None";
528#endif
529
Brian Paul76bc4402000-01-27 16:43:56 +0000530 printf("0x%2x %2d %2s %2d %2d %2d %1s %2s %2s %2d %2d %2d %2d %2d %2d %2d",
531 attribs->id,
532 attribs->depth,
533 visual_class_abbrev(attribs->klass),
Brian Paul45c56982002-10-14 13:57:23 +0000534 attribs->transparentType != GLX_NONE,
Brian Paul76bc4402000-01-27 16:43:56 +0000535 attribs->bufferSize,
536 attribs->level,
537 attribs->rgba ? "r" : "c",
538 attribs->doubleBuffer ? "y" : ".",
539 attribs->stereo ? "y" : ".",
540 attribs->redSize, attribs->greenSize,
541 attribs->blueSize, attribs->alphaSize,
542 attribs->auxBuffers,
543 attribs->depthSize,
544 attribs->stencilSize
545 );
546
Brian Paul25673f02000-03-31 18:17:51 +0000547 printf(" %2d %2d %2d %2d %2d %1d %s\n",
Brian Paul76bc4402000-01-27 16:43:56 +0000548 attribs->accumRedSize, attribs->accumGreenSize,
549 attribs->accumBlueSize, attribs->accumAlphaSize,
Brian Paul25673f02000-03-31 18:17:51 +0000550 attribs->numSamples, attribs->numMultisample,
551 caveat
Brian Paul76bc4402000-01-27 16:43:56 +0000552 );
553}
554
555
556static void
557print_visual_attribs_long_header(void)
558{
559 printf("Vis Vis Visual Trans buff lev render DB ste r g b a aux dep ste accum buffers MS MS\n");
560 printf(" ID Depth Type parent size el type reo sz sz sz sz buf th ncl r g b a num bufs\n");
561 printf("----------------------------------------------------------------------------------------------------\n");
562}
563
564
565static void
566print_visual_attribs_long(const struct visual_attribs *attribs)
567{
568 printf("0x%2x %2d %-11s %2d %2d %2d %4s %3d %3d %3d %3d %3d %3d",
569 attribs->id,
570 attribs->depth,
571 visual_class_name(attribs->klass),
Brian Paul45c56982002-10-14 13:57:23 +0000572 attribs->transparentType != GLX_NONE,
Brian Paul76bc4402000-01-27 16:43:56 +0000573 attribs->bufferSize,
574 attribs->level,
575 attribs->rgba ? "rgba" : "ci ",
576 attribs->doubleBuffer,
577 attribs->stereo,
578 attribs->redSize, attribs->greenSize,
579 attribs->blueSize, attribs->alphaSize
580 );
581
582 printf(" %3d %4d %2d %3d %3d %3d %3d %2d %2d\n",
583 attribs->auxBuffers,
584 attribs->depthSize,
585 attribs->stencilSize,
586 attribs->accumRedSize, attribs->accumGreenSize,
587 attribs->accumBlueSize, attribs->accumAlphaSize,
588 attribs->numSamples, attribs->numMultisample
589 );
590}
591
592
593static void
594print_visual_info(Display *dpy, int scrnum, InfoMode mode)
595{
Brian Paulf02a5f62002-07-12 15:54:01 +0000596 XVisualInfo theTemplate;
Brian Paul76bc4402000-01-27 16:43:56 +0000597 XVisualInfo *visuals;
598 int numVisuals;
599 long mask;
600 int i;
601
602 /* get list of all visuals on this screen */
Brian Paulf02a5f62002-07-12 15:54:01 +0000603 theTemplate.screen = scrnum;
Brian Paul76bc4402000-01-27 16:43:56 +0000604 mask = VisualScreenMask;
Brian Paulf02a5f62002-07-12 15:54:01 +0000605 visuals = XGetVisualInfo(dpy, mask, &theTemplate, &numVisuals);
Brian Paul76bc4402000-01-27 16:43:56 +0000606
607 if (mode == Verbose) {
608 for (i = 0; i < numVisuals; i++) {
609 struct visual_attribs attribs;
610 get_visual_attribs(dpy, &visuals[i], &attribs);
611 print_visual_attribs_verbose(&attribs);
612 }
613 }
614 else if (mode == Normal) {
615 print_visual_attribs_short_header();
616 for (i = 0; i < numVisuals; i++) {
617 struct visual_attribs attribs;
618 get_visual_attribs(dpy, &visuals[i], &attribs);
619 print_visual_attribs_short(&attribs);
620 }
621 }
622 else if (mode == Wide) {
623 print_visual_attribs_long_header();
624 for (i = 0; i < numVisuals; i++) {
625 struct visual_attribs attribs;
626 get_visual_attribs(dpy, &visuals[i], &attribs);
627 print_visual_attribs_long(&attribs);
628 }
629 }
630
631 XFree(visuals);
632}
633
634
Brian Paul39557c32001-03-23 21:41:44 +0000635/*
636 * Stand-alone Mesa doesn't really implement the GLX protocol so it
637 * doesn't really know the GLX attributes associated with an X visual.
638 * The first time a visual is presented to Mesa's pseudo-GLX it
639 * attaches ancilliary buffers to it (like depth and stencil).
640 * But that usually only works if glXChooseVisual is used.
641 * This function calls glXChooseVisual() to sort of "prime the pump"
642 * for Mesa's GLX so that the visuals that get reported actually
643 * reflect what applications will see.
644 * This has no effect when using true GLX.
645 */
646static void
647mesa_hack(Display *dpy, int scrnum)
648{
649 static int attribs[] = {
650 GLX_RGBA,
651 GLX_RED_SIZE, 1,
652 GLX_GREEN_SIZE, 1,
653 GLX_BLUE_SIZE, 1,
654 GLX_DEPTH_SIZE, 1,
655 GLX_STENCIL_SIZE, 1,
656 GLX_ACCUM_RED_SIZE, 1,
657 GLX_ACCUM_GREEN_SIZE, 1,
658 GLX_ACCUM_BLUE_SIZE, 1,
659 GLX_ACCUM_ALPHA_SIZE, 1,
660 GLX_DOUBLEBUFFER,
661 None
662 };
663 XVisualInfo *visinfo;
664
665 visinfo = glXChooseVisual(dpy, scrnum, attribs);
666 if (visinfo)
667 XFree(visinfo);
668}
669
670
671/*
672 * Examine all visuals to find the so-called best one.
673 * We prefer deepest RGBA buffer with depth, stencil and accum
674 * that has no caveats.
675 */
676static int
677find_best_visual(Display *dpy, int scrnum)
678{
Brian Paulf02a5f62002-07-12 15:54:01 +0000679 XVisualInfo theTemplate;
Brian Paul39557c32001-03-23 21:41:44 +0000680 XVisualInfo *visuals;
681 int numVisuals;
682 long mask;
683 int i;
684 struct visual_attribs bestVis;
685
686 /* get list of all visuals on this screen */
Brian Paulf02a5f62002-07-12 15:54:01 +0000687 theTemplate.screen = scrnum;
Brian Paul39557c32001-03-23 21:41:44 +0000688 mask = VisualScreenMask;
Brian Paulf02a5f62002-07-12 15:54:01 +0000689 visuals = XGetVisualInfo(dpy, mask, &theTemplate, &numVisuals);
Brian Paul39557c32001-03-23 21:41:44 +0000690
691 /* init bestVis with first visual info */
692 get_visual_attribs(dpy, &visuals[0], &bestVis);
693
694 /* try to find a "better" visual */
695 for (i = 1; i < numVisuals; i++) {
696 struct visual_attribs vis;
697
698 get_visual_attribs(dpy, &visuals[i], &vis);
699
700 /* always skip visuals with caveats */
701 if (vis.visualCaveat != GLX_NONE_EXT)
702 continue;
703
704 /* see if this vis is better than bestVis */
705 if ((!bestVis.supportsGL && vis.supportsGL) ||
706 (bestVis.visualCaveat != GLX_NONE_EXT) ||
707 (!bestVis.rgba && vis.rgba) ||
708 (!bestVis.doubleBuffer && vis.doubleBuffer) ||
709 (bestVis.redSize < vis.redSize) ||
710 (bestVis.greenSize < vis.greenSize) ||
711 (bestVis.blueSize < vis.blueSize) ||
712 (bestVis.alphaSize < vis.alphaSize) ||
713 (bestVis.depthSize < vis.depthSize) ||
714 (bestVis.stencilSize < vis.stencilSize) ||
715 (bestVis.accumRedSize < vis.accumRedSize)) {
716 /* found a better visual */
717 bestVis = vis;
718 }
719 }
720
721 XFree(visuals);
722
723 return bestVis.id;
724}
725
726
Brian Paul08b3ff12001-04-24 20:57:36 +0000727static void
728usage(void)
729{
730 printf("Usage: glxinfo [-v] [-t] [-h] [-i] [-b] [-display <dname>]\n");
731 printf("\t-v: Print visuals info in verbose form.\n");
732 printf("\t-t: Print verbose table.\n");
733 printf("\t-display <dname>: Print GLX visuals on specified server.\n");
734 printf("\t-h: This information.\n");
735 printf("\t-i: Force an indirect rendering context.\n");
736 printf("\t-b: Find the 'best' visual and print it's number.\n");
Brian Paul0b77a1c2003-04-09 21:50:08 +0000737 printf("\t-l: Print interesting OpenGL limits.\n");
Brian Paul08b3ff12001-04-24 20:57:36 +0000738}
739
740
Brian Paul76bc4402000-01-27 16:43:56 +0000741int
742main(int argc, char *argv[])
743{
Alan Hourihanee18599a2001-03-19 13:58:45 +0000744 char *displayName = NULL;
Brian Paul76bc4402000-01-27 16:43:56 +0000745 Display *dpy;
746 int numScreens, scrnum;
747 InfoMode mode = Normal;
Brian Paul39557c32001-03-23 21:41:44 +0000748 GLboolean findBest = GL_FALSE;
Brian Paul2f7ef5f2002-09-06 03:35:43 +0000749 GLboolean limits = GL_FALSE;
Brian Paul08b3ff12001-04-24 20:57:36 +0000750 Bool allowDirect = True;
Brian Paul76bc4402000-01-27 16:43:56 +0000751 int i;
752
753 for (i = 1; i < argc; i++) {
754 if (strcmp(argv[i], "-display") == 0 && i + 1 < argc) {
755 displayName = argv[i + 1];
756 i++;
757 }
758 else if (strcmp(argv[i], "-t") == 0) {
759 mode = Wide;
760 }
761 else if (strcmp(argv[i], "-v") == 0) {
762 mode = Verbose;
763 }
Brian Paul39557c32001-03-23 21:41:44 +0000764 else if (strcmp(argv[i], "-b") == 0) {
765 findBest = GL_TRUE;
766 }
Brian Paul08b3ff12001-04-24 20:57:36 +0000767 else if (strcmp(argv[i], "-i") == 0) {
768 allowDirect = False;
769 }
Brian Paul2f7ef5f2002-09-06 03:35:43 +0000770 else if (strcmp(argv[i], "-l") == 0) {
771 limits = GL_TRUE;
772 }
Brian Paul08b3ff12001-04-24 20:57:36 +0000773 else if (strcmp(argv[i], "-h") == 0) {
774 usage();
775 return 0;
776 }
777 else {
778 printf("Unknown option `%s'\n", argv[i]);
779 usage();
780 return 0;
781 }
Brian Paul76bc4402000-01-27 16:43:56 +0000782 }
783
784 dpy = XOpenDisplay(displayName);
785 if (!dpy) {
786 fprintf(stderr, "Error: unable to open display %s\n", displayName);
787 return -1;
788 }
789
Brian Paul39557c32001-03-23 21:41:44 +0000790 if (findBest) {
791 int b;
792 mesa_hack(dpy, 0);
793 b = find_best_visual(dpy, 0);
794 printf("%d\n", b);
795 }
796 else {
797 numScreens = ScreenCount(dpy);
Brian Paul373aea12001-04-02 22:45:07 +0000798 print_display_info(dpy);
Brian Paul39557c32001-03-23 21:41:44 +0000799 for (scrnum = 0; scrnum < numScreens; scrnum++) {
800 mesa_hack(dpy, scrnum);
Brian Paul2f7ef5f2002-09-06 03:35:43 +0000801 print_screen_info(dpy, scrnum, allowDirect, limits);
Brian Paul39557c32001-03-23 21:41:44 +0000802 printf("\n");
803 print_visual_info(dpy, scrnum, mode);
804 if (scrnum + 1 < numScreens)
805 printf("\n\n");
806 }
Brian Paul76bc4402000-01-27 16:43:56 +0000807 }
808
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000809 XCloseDisplay(dpy);
810
811 return 0;
812}