blob: f3fb6fd659c4baa3a0a8670ffc540a85fe067fc8 [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 }
207}
208
209
210static void
211print_screen_info(Display *dpy, int scrnum, Bool allowDirect, GLboolean limits)
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000212{
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000213 Window win;
Brian Paul8460cc92000-02-02 20:57:51 +0000214 int attribSingle[] = {
215 GLX_RGBA,
216 GLX_RED_SIZE, 1,
217 GLX_GREEN_SIZE, 1,
218 GLX_BLUE_SIZE, 1,
219 None };
220 int attribDouble[] = {
221 GLX_RGBA,
222 GLX_RED_SIZE, 1,
223 GLX_GREEN_SIZE, 1,
224 GLX_BLUE_SIZE, 1,
225 GLX_DOUBLEBUFFER,
226 None };
227
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000228 XSetWindowAttributes attr;
229 unsigned long mask;
230 Window root;
231 GLXContext ctx;
232 XVisualInfo *visinfo;
233 int width = 100, height = 100;
234
Brian Paul76bc4402000-01-27 16:43:56 +0000235 root = RootWindow(dpy, scrnum);
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000236
Brian Paul8460cc92000-02-02 20:57:51 +0000237 visinfo = glXChooseVisual(dpy, scrnum, attribSingle);
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000238 if (!visinfo) {
Brian Paul8460cc92000-02-02 20:57:51 +0000239 visinfo = glXChooseVisual(dpy, scrnum, attribDouble);
240 if (!visinfo) {
Brian Paul9cff5582000-05-07 18:07:23 +0000241 fprintf(stderr, "Error: couldn't find RGB GLX visual\n");
Brian Paul8460cc92000-02-02 20:57:51 +0000242 return;
243 }
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000244 }
245
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000246 attr.background_pixel = 0;
247 attr.border_pixel = 0;
Brian Paul9cff5582000-05-07 18:07:23 +0000248 attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone);
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000249 attr.event_mask = StructureNotifyMask | ExposureMask;
250 mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
Brian Paul76bc4402000-01-27 16:43:56 +0000251 win = XCreateWindow(dpy, root, 0, 0, width, height,
252 0, visinfo->depth, InputOutput,
253 visinfo->visual, mask, &attr);
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000254
Brian Paul08b3ff12001-04-24 20:57:36 +0000255 ctx = glXCreateContext( dpy, visinfo, NULL, allowDirect );
Brian Paul34fb5db2000-04-22 20:31:23 +0000256 if (!ctx) {
Brian Paul9cff5582000-05-07 18:07:23 +0000257 fprintf(stderr, "Error: glXCreateContext failed\n");
Brian Paul34fb5db2000-04-22 20:31:23 +0000258 XDestroyWindow(dpy, win);
259 return;
260 }
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000261
Brian Paul9cff5582000-05-07 18:07:23 +0000262 if (glXMakeCurrent(dpy, win, ctx)) {
Brian Paul76bc4402000-01-27 16:43:56 +0000263 const char *serverVendor = glXQueryServerString(dpy, scrnum, GLX_VENDOR);
264 const char *serverVersion = glXQueryServerString(dpy, scrnum, GLX_VERSION);
265 const char *serverExtensions = glXQueryServerString(dpy, scrnum, GLX_EXTENSIONS);
Brian Paul34fb5db2000-04-22 20:31:23 +0000266 const char *clientVendor = glXGetClientString(dpy, GLX_VENDOR);
Brian Paul76bc4402000-01-27 16:43:56 +0000267 const char *clientVersion = glXGetClientString(dpy, GLX_VERSION);
268 const char *clientExtensions = glXGetClientString(dpy, GLX_EXTENSIONS);
269 const char *glxExtensions = glXQueryExtensionsString(dpy, scrnum);
270 const char *glVendor = (const char *) glGetString(GL_VENDOR);
271 const char *glRenderer = (const char *) glGetString(GL_RENDERER);
272 const char *glVersion = (const char *) glGetString(GL_VERSION);
273 const char *glExtensions = (const char *) glGetString(GL_EXTENSIONS);
Brian Paul373aea12001-04-02 22:45:07 +0000274 char *displayName = NULL;
275 char *colon = NULL, *period = NULL;
Brian Paul39557c32001-03-23 21:41:44 +0000276#ifdef DO_GLU
Brian Paul76bc4402000-01-27 16:43:56 +0000277 const char *gluVersion = (const char *) gluGetString(GLU_VERSION);
278 const char *gluExtensions = (const char *) gluGetString(GLU_EXTENSIONS);
Brian Paul39557c32001-03-23 21:41:44 +0000279#endif
Brian Paul373aea12001-04-02 22:45:07 +0000280 /* Strip the screen number from the display name, if present. */
Brian Paulf02a5f62002-07-12 15:54:01 +0000281 if (!(displayName = (char *) malloc(strlen(DisplayString(dpy)) + 1))) {
Brian Paul373aea12001-04-02 22:45:07 +0000282 fprintf(stderr, "Error: malloc() failed\n");
283 exit(1);
284 }
285 strcpy(displayName, DisplayString(dpy));
286 colon = strrchr(displayName, ':');
287 if (colon) {
288 period = strchr(colon, '.');
289 if (period)
290 *period = '\0';
291 }
292 printf("display: %s screen: %d\n", displayName, scrnum);
293 free(displayName);
Brian Paule691ee22000-05-08 14:53:57 +0000294 printf("direct rendering: %s\n", glXIsDirect(dpy, ctx) ? "Yes" : "No");
Brian Paul76bc4402000-01-27 16:43:56 +0000295 printf("server glx vendor string: %s\n", serverVendor);
296 printf("server glx version string: %s\n", serverVersion);
297 printf("server glx extensions:\n");
298 print_extension_list(serverExtensions);
Brian Paul34fb5db2000-04-22 20:31:23 +0000299 printf("client glx vendor string: %s\n", clientVendor);
300 printf("client glx version string: %s\n", clientVersion);
Brian Paul76bc4402000-01-27 16:43:56 +0000301 printf("client glx extensions:\n");
302 print_extension_list(clientExtensions);
303 printf("GLX extensions:\n");
304 print_extension_list(glxExtensions);
305 printf("OpenGL vendor string: %s\n", glVendor);
306 printf("OpenGL renderer string: %s\n", glRenderer);
307 printf("OpenGL version string: %s\n", glVersion);
308 printf("OpenGL extensions:\n");
309 print_extension_list(glExtensions);
Brian Paul2f7ef5f2002-09-06 03:35:43 +0000310 if (limits)
311 print_limits();
Brian Paul39557c32001-03-23 21:41:44 +0000312#ifdef DO_GLU
Brian Paul76bc4402000-01-27 16:43:56 +0000313 printf("glu version: %s\n", gluVersion);
314 printf("glu extensions:\n");
315 print_extension_list(gluExtensions);
Brian Paul39557c32001-03-23 21:41:44 +0000316#endif
Brian Paul76bc4402000-01-27 16:43:56 +0000317 }
Brian Paul9cff5582000-05-07 18:07:23 +0000318 else {
319 fprintf(stderr, "Error: glXMakeCurrent failed\n");
320 }
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000321
322 glXDestroyContext(dpy, ctx);
323 XDestroyWindow(dpy, win);
Brian Paul76bc4402000-01-27 16:43:56 +0000324}
325
326
327static const char *
328visual_class_name(int cls)
329{
330 switch (cls) {
331 case StaticColor:
332 return "StaticColor";
333 case PseudoColor:
334 return "PseudoColor";
335 case StaticGray:
336 return "StaticGray";
337 case GrayScale:
338 return "GrayScale";
339 case TrueColor:
340 return "TrueColor";
341 case DirectColor:
342 return "DirectColor";
343 default:
344 return "";
345 }
346}
347
348
349static const char *
350visual_class_abbrev(int cls)
351{
352 switch (cls) {
353 case StaticColor:
354 return "sc";
355 case PseudoColor:
356 return "pc";
357 case StaticGray:
358 return "sg";
359 case GrayScale:
360 return "gs";
361 case TrueColor:
362 return "tc";
363 case DirectColor:
364 return "dc";
365 default:
366 return "";
367 }
368}
369
370
371static void
372get_visual_attribs(Display *dpy, XVisualInfo *vInfo,
373 struct visual_attribs *attribs)
374{
Brian Paul25673f02000-03-31 18:17:51 +0000375 const char *ext = glXQueryExtensionsString(dpy, vInfo->screen);
376
Brian Paula9c53fa2000-04-03 15:45:34 +0000377 memset(attribs, 0, sizeof(struct visual_attribs));
378
Brian Paul76bc4402000-01-27 16:43:56 +0000379 attribs->id = vInfo->visualid;
380#if defined(__cplusplus) || defined(c_plusplus)
381 attribs->klass = vInfo->c_class;
382#else
383 attribs->klass = vInfo->class;
384#endif
385 attribs->depth = vInfo->depth;
386 attribs->redMask = vInfo->red_mask;
387 attribs->greenMask = vInfo->green_mask;
388 attribs->blueMask = vInfo->blue_mask;
389 attribs->colormapSize = vInfo->colormap_size;
390 attribs->bitsPerRGB = vInfo->bits_per_rgb;
391
Brian Paula9c53fa2000-04-03 15:45:34 +0000392 if (glXGetConfig(dpy, vInfo, GLX_USE_GL, &attribs->supportsGL) != 0)
393 return;
Brian Paul76bc4402000-01-27 16:43:56 +0000394 glXGetConfig(dpy, vInfo, GLX_BUFFER_SIZE, &attribs->bufferSize);
395 glXGetConfig(dpy, vInfo, GLX_LEVEL, &attribs->level);
396 glXGetConfig(dpy, vInfo, GLX_RGBA, &attribs->rgba);
397 glXGetConfig(dpy, vInfo, GLX_DOUBLEBUFFER, &attribs->doubleBuffer);
398 glXGetConfig(dpy, vInfo, GLX_STEREO, &attribs->stereo);
399 glXGetConfig(dpy, vInfo, GLX_AUX_BUFFERS, &attribs->auxBuffers);
400 glXGetConfig(dpy, vInfo, GLX_RED_SIZE, &attribs->redSize);
401 glXGetConfig(dpy, vInfo, GLX_GREEN_SIZE, &attribs->greenSize);
402 glXGetConfig(dpy, vInfo, GLX_BLUE_SIZE, &attribs->blueSize);
403 glXGetConfig(dpy, vInfo, GLX_ALPHA_SIZE, &attribs->alphaSize);
404 glXGetConfig(dpy, vInfo, GLX_DEPTH_SIZE, &attribs->depthSize);
405 glXGetConfig(dpy, vInfo, GLX_STENCIL_SIZE, &attribs->stencilSize);
406 glXGetConfig(dpy, vInfo, GLX_ACCUM_RED_SIZE, &attribs->accumRedSize);
407 glXGetConfig(dpy, vInfo, GLX_ACCUM_GREEN_SIZE, &attribs->accumGreenSize);
408 glXGetConfig(dpy, vInfo, GLX_ACCUM_BLUE_SIZE, &attribs->accumBlueSize);
409 glXGetConfig(dpy, vInfo, GLX_ACCUM_ALPHA_SIZE, &attribs->accumAlphaSize);
410
Brian Paul45c56982002-10-14 13:57:23 +0000411 /* get transparent pixel stuff */
412 glXGetConfig(dpy, vInfo,GLX_TRANSPARENT_TYPE, &attribs->transparentType);
413 if (attribs->transparentType == GLX_TRANSPARENT_RGB) {
414 glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_RED_VALUE, &attribs->transparentRedValue);
415 glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_GREEN_VALUE, &attribs->transparentGreenValue);
416 glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_BLUE_VALUE, &attribs->transparentBlueValue);
417 glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_ALPHA_VALUE, &attribs->transparentAlphaValue);
418 }
419 else if (attribs->transparentType == GLX_TRANSPARENT_INDEX) {
420 glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_INDEX_VALUE, &attribs->transparentIndexValue);
421 }
Brian Paule06c7f32000-01-27 16:53:55 +0000422
Brian Pauld2e39bb2002-11-04 16:24:18 +0000423 /* multisample attribs */
424#ifdef GLX_ARB_multisample
425 if (strstr("GLX_ARB_multisample", ext) == 0) {
426 glXGetConfig(dpy, vInfo, GLX_SAMPLE_BUFFERS_ARB, &attribs->numMultisample);
427 glXGetConfig(dpy, vInfo, GLX_SAMPLES_ARB, &attribs->numSamples);
428 }
429#endif
430 else {
431 attribs->numSamples = 0;
432 attribs->numMultisample = 0;
433 }
Brian Paul25673f02000-03-31 18:17:51 +0000434
435#if defined(GLX_EXT_visual_rating)
436 if (ext && strstr(ext, "GLX_EXT_visual_rating")) {
437 glXGetConfig(dpy, vInfo, GLX_VISUAL_CAVEAT_EXT, &attribs->visualCaveat);
438 }
439 else {
440 attribs->visualCaveat = GLX_NONE_EXT;
441 }
442#else
443 attribs->visualCaveat = 0;
444#endif
Brian Paul76bc4402000-01-27 16:43:56 +0000445}
446
447
448static void
449print_visual_attribs_verbose(const struct visual_attribs *attribs)
450{
451 printf("Visual ID: %x depth=%d class=%s\n",
452 attribs->id, attribs->depth, visual_class_name(attribs->klass));
453 printf(" bufferSize=%d level=%d renderType=%s doubleBuffer=%d stereo=%d\n",
454 attribs->bufferSize, attribs->level, attribs->rgba ? "rgba" : "ci",
455 attribs->doubleBuffer, attribs->stereo);
456 printf(" rgba: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n",
457 attribs->redSize, attribs->greenSize,
458 attribs->blueSize, attribs->alphaSize);
459 printf(" auxBuffers=%d depthSize=%d stencilSize=%d\n",
460 attribs->auxBuffers, attribs->depthSize, attribs->stencilSize);
461 printf(" accum: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n",
462 attribs->accumRedSize, attribs->accumGreenSize,
463 attribs->accumBlueSize, attribs->accumAlphaSize);
464 printf(" multiSample=%d multiSampleBuffers=%d\n",
465 attribs->numSamples, attribs->numMultisample);
Brian Paul25673f02000-03-31 18:17:51 +0000466#ifdef GLX_EXT_visual_rating
467 if (attribs->visualCaveat == GLX_NONE_EXT || attribs->visualCaveat == 0)
Brian Paula9c53fa2000-04-03 15:45:34 +0000468 printf(" visualCaveat=None\n");
Brian Paul25673f02000-03-31 18:17:51 +0000469 else if (attribs->visualCaveat == GLX_SLOW_VISUAL_EXT)
Brian Paula9c53fa2000-04-03 15:45:34 +0000470 printf(" visualCaveat=Slow\n");
Brian Paul25673f02000-03-31 18:17:51 +0000471 else if (attribs->visualCaveat == GLX_NON_CONFORMANT_VISUAL_EXT)
Brian Paula9c53fa2000-04-03 15:45:34 +0000472 printf(" visualCaveat=Nonconformant\n");
Brian Paul25673f02000-03-31 18:17:51 +0000473#endif
Brian Paul45c56982002-10-14 13:57:23 +0000474 if (attribs->transparentType == GLX_NONE) {
475 printf(" Opaque.\n");
476 }
477 else if (attribs->transparentType == GLX_TRANSPARENT_RGB) {
478 printf(" Transparent RGB: Red=%d Green=%d Blue=%d Alpha=%d\n",attribs->transparentRedValue,attribs->transparentGreenValue,attribs->transparentBlueValue,attribs->transparentAlphaValue);
479 }
480 else if (attribs->transparentType == GLX_TRANSPARENT_INDEX) {
481 printf(" Transparent index=%d\n",attribs->transparentIndexValue);
482 }
Brian Paul76bc4402000-01-27 16:43:56 +0000483}
484
485
486static void
487print_visual_attribs_short_header(void)
488{
Brian Paula9c53fa2000-04-03 15:45:34 +0000489 printf(" visual x bf lv rg d st colorbuffer ax dp st accumbuffer ms cav\n");
490 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 +0000491 printf("----------------------------------------------------------------------\n");
Brian Paul76bc4402000-01-27 16:43:56 +0000492}
493
494
495static void
496print_visual_attribs_short(const struct visual_attribs *attribs)
497{
Brian Paula3e44f42002-03-08 19:44:28 +0000498 char *caveat = NULL;
Brian Paul25673f02000-03-31 18:17:51 +0000499#ifdef GLX_EXT_visual_rating
500 if (attribs->visualCaveat == GLX_NONE_EXT || attribs->visualCaveat == 0)
501 caveat = "None";
502 else if (attribs->visualCaveat == GLX_SLOW_VISUAL_EXT)
503 caveat = "Slow";
504 else if (attribs->visualCaveat == GLX_NON_CONFORMANT_VISUAL_EXT)
505 caveat = "Ncon";
Brian Paul28bc6cb2002-09-06 03:47:34 +0000506 else
507 caveat = "None";
Brian Paul25673f02000-03-31 18:17:51 +0000508#else
509 caveat = "None";
510#endif
511
Brian Paul76bc4402000-01-27 16:43:56 +0000512 printf("0x%2x %2d %2s %2d %2d %2d %1s %2s %2s %2d %2d %2d %2d %2d %2d %2d",
513 attribs->id,
514 attribs->depth,
515 visual_class_abbrev(attribs->klass),
Brian Paul45c56982002-10-14 13:57:23 +0000516 attribs->transparentType != GLX_NONE,
Brian Paul76bc4402000-01-27 16:43:56 +0000517 attribs->bufferSize,
518 attribs->level,
519 attribs->rgba ? "r" : "c",
520 attribs->doubleBuffer ? "y" : ".",
521 attribs->stereo ? "y" : ".",
522 attribs->redSize, attribs->greenSize,
523 attribs->blueSize, attribs->alphaSize,
524 attribs->auxBuffers,
525 attribs->depthSize,
526 attribs->stencilSize
527 );
528
Brian Paul25673f02000-03-31 18:17:51 +0000529 printf(" %2d %2d %2d %2d %2d %1d %s\n",
Brian Paul76bc4402000-01-27 16:43:56 +0000530 attribs->accumRedSize, attribs->accumGreenSize,
531 attribs->accumBlueSize, attribs->accumAlphaSize,
Brian Paul25673f02000-03-31 18:17:51 +0000532 attribs->numSamples, attribs->numMultisample,
533 caveat
Brian Paul76bc4402000-01-27 16:43:56 +0000534 );
535}
536
537
538static void
539print_visual_attribs_long_header(void)
540{
541 printf("Vis Vis Visual Trans buff lev render DB ste r g b a aux dep ste accum buffers MS MS\n");
542 printf(" ID Depth Type parent size el type reo sz sz sz sz buf th ncl r g b a num bufs\n");
543 printf("----------------------------------------------------------------------------------------------------\n");
544}
545
546
547static void
548print_visual_attribs_long(const struct visual_attribs *attribs)
549{
550 printf("0x%2x %2d %-11s %2d %2d %2d %4s %3d %3d %3d %3d %3d %3d",
551 attribs->id,
552 attribs->depth,
553 visual_class_name(attribs->klass),
Brian Paul45c56982002-10-14 13:57:23 +0000554 attribs->transparentType != GLX_NONE,
Brian Paul76bc4402000-01-27 16:43:56 +0000555 attribs->bufferSize,
556 attribs->level,
557 attribs->rgba ? "rgba" : "ci ",
558 attribs->doubleBuffer,
559 attribs->stereo,
560 attribs->redSize, attribs->greenSize,
561 attribs->blueSize, attribs->alphaSize
562 );
563
564 printf(" %3d %4d %2d %3d %3d %3d %3d %2d %2d\n",
565 attribs->auxBuffers,
566 attribs->depthSize,
567 attribs->stencilSize,
568 attribs->accumRedSize, attribs->accumGreenSize,
569 attribs->accumBlueSize, attribs->accumAlphaSize,
570 attribs->numSamples, attribs->numMultisample
571 );
572}
573
574
575static void
576print_visual_info(Display *dpy, int scrnum, InfoMode mode)
577{
Brian Paulf02a5f62002-07-12 15:54:01 +0000578 XVisualInfo theTemplate;
Brian Paul76bc4402000-01-27 16:43:56 +0000579 XVisualInfo *visuals;
580 int numVisuals;
581 long mask;
582 int i;
583
584 /* get list of all visuals on this screen */
Brian Paulf02a5f62002-07-12 15:54:01 +0000585 theTemplate.screen = scrnum;
Brian Paul76bc4402000-01-27 16:43:56 +0000586 mask = VisualScreenMask;
Brian Paulf02a5f62002-07-12 15:54:01 +0000587 visuals = XGetVisualInfo(dpy, mask, &theTemplate, &numVisuals);
Brian Paul76bc4402000-01-27 16:43:56 +0000588
589 if (mode == Verbose) {
590 for (i = 0; i < numVisuals; i++) {
591 struct visual_attribs attribs;
592 get_visual_attribs(dpy, &visuals[i], &attribs);
593 print_visual_attribs_verbose(&attribs);
594 }
595 }
596 else if (mode == Normal) {
597 print_visual_attribs_short_header();
598 for (i = 0; i < numVisuals; i++) {
599 struct visual_attribs attribs;
600 get_visual_attribs(dpy, &visuals[i], &attribs);
601 print_visual_attribs_short(&attribs);
602 }
603 }
604 else if (mode == Wide) {
605 print_visual_attribs_long_header();
606 for (i = 0; i < numVisuals; i++) {
607 struct visual_attribs attribs;
608 get_visual_attribs(dpy, &visuals[i], &attribs);
609 print_visual_attribs_long(&attribs);
610 }
611 }
612
613 XFree(visuals);
614}
615
616
Brian Paul39557c32001-03-23 21:41:44 +0000617/*
618 * Stand-alone Mesa doesn't really implement the GLX protocol so it
619 * doesn't really know the GLX attributes associated with an X visual.
620 * The first time a visual is presented to Mesa's pseudo-GLX it
621 * attaches ancilliary buffers to it (like depth and stencil).
622 * But that usually only works if glXChooseVisual is used.
623 * This function calls glXChooseVisual() to sort of "prime the pump"
624 * for Mesa's GLX so that the visuals that get reported actually
625 * reflect what applications will see.
626 * This has no effect when using true GLX.
627 */
628static void
629mesa_hack(Display *dpy, int scrnum)
630{
631 static int attribs[] = {
632 GLX_RGBA,
633 GLX_RED_SIZE, 1,
634 GLX_GREEN_SIZE, 1,
635 GLX_BLUE_SIZE, 1,
636 GLX_DEPTH_SIZE, 1,
637 GLX_STENCIL_SIZE, 1,
638 GLX_ACCUM_RED_SIZE, 1,
639 GLX_ACCUM_GREEN_SIZE, 1,
640 GLX_ACCUM_BLUE_SIZE, 1,
641 GLX_ACCUM_ALPHA_SIZE, 1,
642 GLX_DOUBLEBUFFER,
643 None
644 };
645 XVisualInfo *visinfo;
646
647 visinfo = glXChooseVisual(dpy, scrnum, attribs);
648 if (visinfo)
649 XFree(visinfo);
650}
651
652
653/*
654 * Examine all visuals to find the so-called best one.
655 * We prefer deepest RGBA buffer with depth, stencil and accum
656 * that has no caveats.
657 */
658static int
659find_best_visual(Display *dpy, int scrnum)
660{
Brian Paulf02a5f62002-07-12 15:54:01 +0000661 XVisualInfo theTemplate;
Brian Paul39557c32001-03-23 21:41:44 +0000662 XVisualInfo *visuals;
663 int numVisuals;
664 long mask;
665 int i;
666 struct visual_attribs bestVis;
667
668 /* get list of all visuals on this screen */
Brian Paulf02a5f62002-07-12 15:54:01 +0000669 theTemplate.screen = scrnum;
Brian Paul39557c32001-03-23 21:41:44 +0000670 mask = VisualScreenMask;
Brian Paulf02a5f62002-07-12 15:54:01 +0000671 visuals = XGetVisualInfo(dpy, mask, &theTemplate, &numVisuals);
Brian Paul39557c32001-03-23 21:41:44 +0000672
673 /* init bestVis with first visual info */
674 get_visual_attribs(dpy, &visuals[0], &bestVis);
675
676 /* try to find a "better" visual */
677 for (i = 1; i < numVisuals; i++) {
678 struct visual_attribs vis;
679
680 get_visual_attribs(dpy, &visuals[i], &vis);
681
682 /* always skip visuals with caveats */
683 if (vis.visualCaveat != GLX_NONE_EXT)
684 continue;
685
686 /* see if this vis is better than bestVis */
687 if ((!bestVis.supportsGL && vis.supportsGL) ||
688 (bestVis.visualCaveat != GLX_NONE_EXT) ||
689 (!bestVis.rgba && vis.rgba) ||
690 (!bestVis.doubleBuffer && vis.doubleBuffer) ||
691 (bestVis.redSize < vis.redSize) ||
692 (bestVis.greenSize < vis.greenSize) ||
693 (bestVis.blueSize < vis.blueSize) ||
694 (bestVis.alphaSize < vis.alphaSize) ||
695 (bestVis.depthSize < vis.depthSize) ||
696 (bestVis.stencilSize < vis.stencilSize) ||
697 (bestVis.accumRedSize < vis.accumRedSize)) {
698 /* found a better visual */
699 bestVis = vis;
700 }
701 }
702
703 XFree(visuals);
704
705 return bestVis.id;
706}
707
708
Brian Paul08b3ff12001-04-24 20:57:36 +0000709static void
710usage(void)
711{
712 printf("Usage: glxinfo [-v] [-t] [-h] [-i] [-b] [-display <dname>]\n");
713 printf("\t-v: Print visuals info in verbose form.\n");
714 printf("\t-t: Print verbose table.\n");
715 printf("\t-display <dname>: Print GLX visuals on specified server.\n");
716 printf("\t-h: This information.\n");
717 printf("\t-i: Force an indirect rendering context.\n");
718 printf("\t-b: Find the 'best' visual and print it's number.\n");
Brian Paul0b77a1c2003-04-09 21:50:08 +0000719 printf("\t-l: Print interesting OpenGL limits.\n");
Brian Paul08b3ff12001-04-24 20:57:36 +0000720}
721
722
Brian Paul76bc4402000-01-27 16:43:56 +0000723int
724main(int argc, char *argv[])
725{
Alan Hourihanee18599a2001-03-19 13:58:45 +0000726 char *displayName = NULL;
Brian Paul76bc4402000-01-27 16:43:56 +0000727 Display *dpy;
728 int numScreens, scrnum;
729 InfoMode mode = Normal;
Brian Paul39557c32001-03-23 21:41:44 +0000730 GLboolean findBest = GL_FALSE;
Brian Paul2f7ef5f2002-09-06 03:35:43 +0000731 GLboolean limits = GL_FALSE;
Brian Paul08b3ff12001-04-24 20:57:36 +0000732 Bool allowDirect = True;
Brian Paul76bc4402000-01-27 16:43:56 +0000733 int i;
734
735 for (i = 1; i < argc; i++) {
736 if (strcmp(argv[i], "-display") == 0 && i + 1 < argc) {
737 displayName = argv[i + 1];
738 i++;
739 }
740 else if (strcmp(argv[i], "-t") == 0) {
741 mode = Wide;
742 }
743 else if (strcmp(argv[i], "-v") == 0) {
744 mode = Verbose;
745 }
Brian Paul39557c32001-03-23 21:41:44 +0000746 else if (strcmp(argv[i], "-b") == 0) {
747 findBest = GL_TRUE;
748 }
Brian Paul08b3ff12001-04-24 20:57:36 +0000749 else if (strcmp(argv[i], "-i") == 0) {
750 allowDirect = False;
751 }
Brian Paul2f7ef5f2002-09-06 03:35:43 +0000752 else if (strcmp(argv[i], "-l") == 0) {
753 limits = GL_TRUE;
754 }
Brian Paul08b3ff12001-04-24 20:57:36 +0000755 else if (strcmp(argv[i], "-h") == 0) {
756 usage();
757 return 0;
758 }
759 else {
760 printf("Unknown option `%s'\n", argv[i]);
761 usage();
762 return 0;
763 }
Brian Paul76bc4402000-01-27 16:43:56 +0000764 }
765
766 dpy = XOpenDisplay(displayName);
767 if (!dpy) {
768 fprintf(stderr, "Error: unable to open display %s\n", displayName);
769 return -1;
770 }
771
Brian Paul39557c32001-03-23 21:41:44 +0000772 if (findBest) {
773 int b;
774 mesa_hack(dpy, 0);
775 b = find_best_visual(dpy, 0);
776 printf("%d\n", b);
777 }
778 else {
779 numScreens = ScreenCount(dpy);
Brian Paul373aea12001-04-02 22:45:07 +0000780 print_display_info(dpy);
Brian Paul39557c32001-03-23 21:41:44 +0000781 for (scrnum = 0; scrnum < numScreens; scrnum++) {
782 mesa_hack(dpy, scrnum);
Brian Paul2f7ef5f2002-09-06 03:35:43 +0000783 print_screen_info(dpy, scrnum, allowDirect, limits);
Brian Paul39557c32001-03-23 21:41:44 +0000784 printf("\n");
785 print_visual_info(dpy, scrnum, mode);
786 if (scrnum + 1 < numScreens)
787 printf("\n\n");
788 }
Brian Paul76bc4402000-01-27 16:43:56 +0000789 }
790
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000791 XCloseDisplay(dpy);
792
793 return 0;
794}