blob: 230823eb8d42d9ea208b65882a69d940552e5ee0 [file] [log] [blame]
Brian Pauld2e39bb2002-11-04 16:24:18 +00001/* $Id: glxinfo.c,v 1.21 2002/11/04 16:24:18 brianp Exp $ */
Brian Pauld2bfe1e1999-09-16 16:40:46 +00002
3/*
Brian Paul2f7ef5f2002-09-06 03:35:43 +00004 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
Brian Paul76bc4402000-01-27 16:43:56 +00005 *
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
Brian Paul39557c32001-03-23 21:41:44 +000031 * -b only print ID of "best" visual on screen 0
Brian Paul28bc6cb2002-09-06 03:47:34 +000032 * -i use indirect rendering connection only
Brian Paul2f7ef5f2002-09-06 03:35:43 +000033 * -l print interesting OpenGL limits (added 5 Sep 2002)
Brian Paul76bc4402000-01-27 16:43:56 +000034 *
35 * Brian Paul 26 January 2000
36 */
Brian Pauld2bfe1e1999-09-16 16:40:46 +000037
Brian Paul39557c32001-03-23 21:41:44 +000038#define DO_GLU /* may want to remove this for easier XFree86 building? */
Brian Paul76bc4402000-01-27 16:43:56 +000039
40#include <X11/Xlib.h>
41#include <X11/Xutil.h>
Brian Pauld2bfe1e1999-09-16 16:40:46 +000042#include <GL/gl.h>
Brian Paul39557c32001-03-23 21:41:44 +000043#ifdef DO_GLU
Brian Pauld2bfe1e1999-09-16 16:40:46 +000044#include <GL/glu.h>
Brian Paul39557c32001-03-23 21:41:44 +000045#endif
Brian Paul76bc4402000-01-27 16:43:56 +000046#include <GL/glx.h>
Brian Pauld2bfe1e1999-09-16 16:40:46 +000047#include <stdio.h>
Brian Paul76bc4402000-01-27 16:43:56 +000048#include <string.h>
Brian Paul373aea12001-04-02 22:45:07 +000049#include <stdlib.h>
Brian Pauld2bfe1e1999-09-16 16:40:46 +000050
51
Brian Paul39557c32001-03-23 21:41:44 +000052#ifndef GLX_NONE_EXT
53#define GLX_NONE_EXT 0x8000
54#endif
55
Brian Paul45c56982002-10-14 13:57:23 +000056#ifndef GLX_TRANSPARENT_RGB
57#define GLX_TRANSPARENT_RGB 0x8008
58#endif
Brian Paul39557c32001-03-23 21:41:44 +000059
Brian Paul76bc4402000-01-27 16:43:56 +000060typedef enum
Brian Pauld2bfe1e1999-09-16 16:40:46 +000061{
Brian Paul76bc4402000-01-27 16:43:56 +000062 Normal,
63 Wide,
64 Verbose
65} InfoMode;
Brian Pauld2bfe1e1999-09-16 16:40:46 +000066
Brian Pauld2bfe1e1999-09-16 16:40:46 +000067
Brian Paul76bc4402000-01-27 16:43:56 +000068struct visual_attribs
69{
70 /* X visual attribs */
71 int id;
72 int klass;
73 int depth;
74 int redMask, greenMask, blueMask;
75 int colormapSize;
76 int bitsPerRGB;
Brian Pauld2bfe1e1999-09-16 16:40:46 +000077
Brian Paul76bc4402000-01-27 16:43:56 +000078 /* GL visual attribs */
79 int supportsGL;
Brian Paul45c56982002-10-14 13:57:23 +000080 int transparentType;
81 int transparentRedValue;
82 int transparentGreenValue;
83 int transparentBlueValue;
84 int transparentAlphaValue;
85 int transparentIndexValue;
Brian Paul76bc4402000-01-27 16:43:56 +000086 int bufferSize;
87 int level;
88 int rgba;
89 int doubleBuffer;
90 int stereo;
91 int auxBuffers;
92 int redSize, greenSize, blueSize, alphaSize;
93 int depthSize;
94 int stencilSize;
95 int accumRedSize, accumGreenSize, accumBlueSize, accumAlphaSize;
96 int numSamples, numMultisample;
Brian Paul25673f02000-03-31 18:17:51 +000097 int visualCaveat;
Brian Paul76bc4402000-01-27 16:43:56 +000098};
99
100
101/*
102 * Print a list of extensions, with word-wrapping.
103 */
104static void
105print_extension_list(const char *ext)
106{
107 const char *indentString = " ";
108 const int indent = 4;
109 const int max = 79;
110 int width, i, j;
111
112 if (!ext || !ext[0])
113 return;
114
115 width = indent;
116 printf(indentString);
117 i = j = 0;
118 while (1) {
119 if (ext[j] == ' ' || ext[j] == 0) {
120 /* found end of an extension name */
121 const int len = j - i;
122 if (width + len > max) {
123 /* start a new line */
124 printf("\n");
125 width = indent;
126 printf(indentString);
127 }
128 /* print the extension name between ext[i] and ext[j] */
129 while (i < j) {
130 printf("%c", ext[i]);
131 i++;
132 }
133 /* either we're all done, or we'll continue with next extension */
134 width += len + 1;
135 if (ext[j] == 0) {
136 break;
137 }
138 else {
139 i++;
140 j++;
Brian Paul7ac43502000-02-23 22:50:35 +0000141 if (ext[j] == 0)
142 break;
Brian Paul76bc4402000-01-27 16:43:56 +0000143 printf(", ");
144 width += 2;
145 }
146 }
147 j++;
148 }
149 printf("\n");
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000150}
151
152
Brian Paul76bc4402000-01-27 16:43:56 +0000153static void
Brian Paul373aea12001-04-02 22:45:07 +0000154print_display_info(Display *dpy)
155{
156 printf("name of display: %s\n", DisplayString(dpy));
157}
158
159
160static void
Brian Paul2f7ef5f2002-09-06 03:35:43 +0000161print_limits(void)
162{
163 struct token_name {
164 GLuint count;
165 GLenum token;
166 const char *name;
167 };
168 static const struct token_name limits[] = {
169 { 1, GL_MAX_ATTRIB_STACK_DEPTH, "GL_MAX_ATTRIB_STACK_DEPTH" },
170 { 1, GL_MAX_CLIENT_ATTRIB_STACK_DEPTH, "GL_MAX_CLIENT_ATTRIB_STACK_DEPTH" },
171 { 1, GL_MAX_CLIP_PLANES, "GL_MAX_CLIP_PLANES" },
172 { 1, GL_MAX_COLOR_MATRIX_STACK_DEPTH, "GL_MAX_COLOR_MATRIX_STACK_DEPTH" },
Brian Paul2f7ef5f2002-09-06 03:35:43 +0000173 { 1, GL_MAX_ELEMENTS_VERTICES, "GL_MAX_ELEMENTS_VERTICES" },
174 { 1, GL_MAX_ELEMENTS_INDICES, "GL_MAX_ELEMENTS_INDICES" },
175 { 1, GL_MAX_EVAL_ORDER, "GL_MAX_EVAL_ORDER" },
176 { 1, GL_MAX_LIGHTS, "GL_MAX_LIGHTS" },
177 { 1, GL_MAX_LIST_NESTING, "GL_MAX_LIST_NESTING" },
178 { 1, GL_MAX_MODELVIEW_STACK_DEPTH, "GL_MAX_MODELVIEW_STACK_DEPTH" },
179 { 1, GL_MAX_NAME_STACK_DEPTH, "GL_MAX_NAME_STACK_DEPTH" },
180 { 1, GL_MAX_PIXEL_MAP_TABLE, "GL_MAX_PIXEL_MAP_TABLE" },
181 { 1, GL_MAX_PROJECTION_STACK_DEPTH, "GL_MAX_PROJECTION_STACK_DEPTH" },
182 { 1, GL_MAX_TEXTURE_STACK_DEPTH, "GL_MAX_TEXTURE_STACK_DEPTH" },
183 { 1, GL_MAX_TEXTURE_SIZE, "GL_MAX_TEXTURE_SIZE" },
184 { 1, GL_MAX_3D_TEXTURE_SIZE, "GL_MAX_3D_TEXTURE_SIZE" },
185 { 1, GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB, "GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB" },
186 { 1, GL_MAX_RECTANGLE_TEXTURE_SIZE_NV, "GL_MAX_RECTANGLE_TEXTURE_SIZE_NV" },
187 { 1, GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB, "GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB" },
188 { 1, GL_MAX_TEXTURE_UNITS_ARB, "GL_MAX_TEXTURE_UNITS_ARB" },
189 { 1, GL_MAX_TEXTURE_LOD_BIAS_EXT, "GL_MAX_TEXTURE_LOD_BIAS_EXT" },
190 { 1, GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, "GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT" },
191 { 2, GL_MAX_VIEWPORT_DIMS, "GL_MAX_VIEWPORT_DIMS" },
192 { 2, GL_ALIASED_LINE_WIDTH_RANGE, "GL_ALIASED_LINE_WIDTH_RANGE" },
193 { 2, GL_SMOOTH_LINE_WIDTH_RANGE, "GL_SMOOTH_LINE_WIDTH_RANGE" },
194 { 2, GL_ALIASED_POINT_SIZE_RANGE, "GL_ALIASED_POINT_SIZE_RANGE" },
195 { 2, GL_SMOOTH_POINT_SIZE_RANGE, "GL_SMOOTH_POINT_SIZE_RANGE" },
196 { 0, (GLenum) 0, NULL }
197 };
198 GLint i, max[2];
199 printf("OpenGL limits:\n");
200 for (i = 0; limits[i].count; i++) {
201 glGetIntegerv(limits[i].token, max);
202 if (glGetError() == GL_NONE) {
203 if (limits[i].count == 1)
204 printf(" %s = %d\n", limits[i].name, max[0]);
205 else /* XXX fix if we ever query something with more than 2 values */
206 printf(" %s = %d, %d\n", limits[i].name, max[0], max[1]);
207 }
208 }
209}
210
211
212static void
213print_screen_info(Display *dpy, int scrnum, Bool allowDirect, GLboolean limits)
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000214{
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000215 Window win;
Brian Paul8460cc92000-02-02 20:57:51 +0000216 int attribSingle[] = {
217 GLX_RGBA,
218 GLX_RED_SIZE, 1,
219 GLX_GREEN_SIZE, 1,
220 GLX_BLUE_SIZE, 1,
221 None };
222 int attribDouble[] = {
223 GLX_RGBA,
224 GLX_RED_SIZE, 1,
225 GLX_GREEN_SIZE, 1,
226 GLX_BLUE_SIZE, 1,
227 GLX_DOUBLEBUFFER,
228 None };
229
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000230 XSetWindowAttributes attr;
231 unsigned long mask;
232 Window root;
233 GLXContext ctx;
234 XVisualInfo *visinfo;
235 int width = 100, height = 100;
236
Brian Paul76bc4402000-01-27 16:43:56 +0000237 root = RootWindow(dpy, scrnum);
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000238
Brian Paul8460cc92000-02-02 20:57:51 +0000239 visinfo = glXChooseVisual(dpy, scrnum, attribSingle);
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000240 if (!visinfo) {
Brian Paul8460cc92000-02-02 20:57:51 +0000241 visinfo = glXChooseVisual(dpy, scrnum, attribDouble);
242 if (!visinfo) {
Brian Paul9cff5582000-05-07 18:07:23 +0000243 fprintf(stderr, "Error: couldn't find RGB GLX visual\n");
Brian Paul8460cc92000-02-02 20:57:51 +0000244 return;
245 }
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000246 }
247
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000248 attr.background_pixel = 0;
249 attr.border_pixel = 0;
Brian Paul9cff5582000-05-07 18:07:23 +0000250 attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone);
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000251 attr.event_mask = StructureNotifyMask | ExposureMask;
252 mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
Brian Paul76bc4402000-01-27 16:43:56 +0000253 win = XCreateWindow(dpy, root, 0, 0, width, height,
254 0, visinfo->depth, InputOutput,
255 visinfo->visual, mask, &attr);
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000256
Brian Paul08b3ff12001-04-24 20:57:36 +0000257 ctx = glXCreateContext( dpy, visinfo, NULL, allowDirect );
Brian Paul34fb5db2000-04-22 20:31:23 +0000258 if (!ctx) {
Brian Paul9cff5582000-05-07 18:07:23 +0000259 fprintf(stderr, "Error: glXCreateContext failed\n");
Brian Paul34fb5db2000-04-22 20:31:23 +0000260 XDestroyWindow(dpy, win);
261 return;
262 }
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000263
Brian Paul9cff5582000-05-07 18:07:23 +0000264 if (glXMakeCurrent(dpy, win, ctx)) {
Brian Paul76bc4402000-01-27 16:43:56 +0000265 const char *serverVendor = glXQueryServerString(dpy, scrnum, GLX_VENDOR);
266 const char *serverVersion = glXQueryServerString(dpy, scrnum, GLX_VERSION);
267 const char *serverExtensions = glXQueryServerString(dpy, scrnum, GLX_EXTENSIONS);
Brian Paul34fb5db2000-04-22 20:31:23 +0000268 const char *clientVendor = glXGetClientString(dpy, GLX_VENDOR);
Brian Paul76bc4402000-01-27 16:43:56 +0000269 const char *clientVersion = glXGetClientString(dpy, GLX_VERSION);
270 const char *clientExtensions = glXGetClientString(dpy, GLX_EXTENSIONS);
271 const char *glxExtensions = glXQueryExtensionsString(dpy, scrnum);
272 const char *glVendor = (const char *) glGetString(GL_VENDOR);
273 const char *glRenderer = (const char *) glGetString(GL_RENDERER);
274 const char *glVersion = (const char *) glGetString(GL_VERSION);
275 const char *glExtensions = (const char *) glGetString(GL_EXTENSIONS);
Brian Paul373aea12001-04-02 22:45:07 +0000276 char *displayName = NULL;
277 char *colon = NULL, *period = NULL;
Brian Paul39557c32001-03-23 21:41:44 +0000278#ifdef DO_GLU
Brian Paul76bc4402000-01-27 16:43:56 +0000279 const char *gluVersion = (const char *) gluGetString(GLU_VERSION);
280 const char *gluExtensions = (const char *) gluGetString(GLU_EXTENSIONS);
Brian Paul39557c32001-03-23 21:41:44 +0000281#endif
Brian Paul373aea12001-04-02 22:45:07 +0000282 /* Strip the screen number from the display name, if present. */
Brian Paulf02a5f62002-07-12 15:54:01 +0000283 if (!(displayName = (char *) malloc(strlen(DisplayString(dpy)) + 1))) {
Brian Paul373aea12001-04-02 22:45:07 +0000284 fprintf(stderr, "Error: malloc() failed\n");
285 exit(1);
286 }
287 strcpy(displayName, DisplayString(dpy));
288 colon = strrchr(displayName, ':');
289 if (colon) {
290 period = strchr(colon, '.');
291 if (period)
292 *period = '\0';
293 }
294 printf("display: %s screen: %d\n", displayName, scrnum);
295 free(displayName);
Brian Paule691ee22000-05-08 14:53:57 +0000296 printf("direct rendering: %s\n", glXIsDirect(dpy, ctx) ? "Yes" : "No");
Brian Paul76bc4402000-01-27 16:43:56 +0000297 printf("server glx vendor string: %s\n", serverVendor);
298 printf("server glx version string: %s\n", serverVersion);
299 printf("server glx extensions:\n");
300 print_extension_list(serverExtensions);
Brian Paul34fb5db2000-04-22 20:31:23 +0000301 printf("client glx vendor string: %s\n", clientVendor);
302 printf("client glx version string: %s\n", clientVersion);
Brian Paul76bc4402000-01-27 16:43:56 +0000303 printf("client glx extensions:\n");
304 print_extension_list(clientExtensions);
305 printf("GLX extensions:\n");
306 print_extension_list(glxExtensions);
307 printf("OpenGL vendor string: %s\n", glVendor);
308 printf("OpenGL renderer string: %s\n", glRenderer);
309 printf("OpenGL version string: %s\n", glVersion);
310 printf("OpenGL extensions:\n");
311 print_extension_list(glExtensions);
Brian Paul2f7ef5f2002-09-06 03:35:43 +0000312 if (limits)
313 print_limits();
Brian Paul39557c32001-03-23 21:41:44 +0000314#ifdef DO_GLU
Brian Paul76bc4402000-01-27 16:43:56 +0000315 printf("glu version: %s\n", gluVersion);
316 printf("glu extensions:\n");
317 print_extension_list(gluExtensions);
Brian Paul39557c32001-03-23 21:41:44 +0000318#endif
Brian Paul76bc4402000-01-27 16:43:56 +0000319 }
Brian Paul9cff5582000-05-07 18:07:23 +0000320 else {
321 fprintf(stderr, "Error: glXMakeCurrent failed\n");
322 }
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000323
324 glXDestroyContext(dpy, ctx);
325 XDestroyWindow(dpy, win);
Brian Paul76bc4402000-01-27 16:43:56 +0000326}
327
328
329static const char *
330visual_class_name(int cls)
331{
332 switch (cls) {
333 case StaticColor:
334 return "StaticColor";
335 case PseudoColor:
336 return "PseudoColor";
337 case StaticGray:
338 return "StaticGray";
339 case GrayScale:
340 return "GrayScale";
341 case TrueColor:
342 return "TrueColor";
343 case DirectColor:
344 return "DirectColor";
345 default:
346 return "";
347 }
348}
349
350
351static const char *
352visual_class_abbrev(int cls)
353{
354 switch (cls) {
355 case StaticColor:
356 return "sc";
357 case PseudoColor:
358 return "pc";
359 case StaticGray:
360 return "sg";
361 case GrayScale:
362 return "gs";
363 case TrueColor:
364 return "tc";
365 case DirectColor:
366 return "dc";
367 default:
368 return "";
369 }
370}
371
372
373static void
374get_visual_attribs(Display *dpy, XVisualInfo *vInfo,
375 struct visual_attribs *attribs)
376{
Brian Paul25673f02000-03-31 18:17:51 +0000377 const char *ext = glXQueryExtensionsString(dpy, vInfo->screen);
378
Brian Paula9c53fa2000-04-03 15:45:34 +0000379 memset(attribs, 0, sizeof(struct visual_attribs));
380
Brian Paul76bc4402000-01-27 16:43:56 +0000381 attribs->id = vInfo->visualid;
382#if defined(__cplusplus) || defined(c_plusplus)
383 attribs->klass = vInfo->c_class;
384#else
385 attribs->klass = vInfo->class;
386#endif
387 attribs->depth = vInfo->depth;
388 attribs->redMask = vInfo->red_mask;
389 attribs->greenMask = vInfo->green_mask;
390 attribs->blueMask = vInfo->blue_mask;
391 attribs->colormapSize = vInfo->colormap_size;
392 attribs->bitsPerRGB = vInfo->bits_per_rgb;
393
Brian Paula9c53fa2000-04-03 15:45:34 +0000394 if (glXGetConfig(dpy, vInfo, GLX_USE_GL, &attribs->supportsGL) != 0)
395 return;
Brian Paul76bc4402000-01-27 16:43:56 +0000396 glXGetConfig(dpy, vInfo, GLX_BUFFER_SIZE, &attribs->bufferSize);
397 glXGetConfig(dpy, vInfo, GLX_LEVEL, &attribs->level);
398 glXGetConfig(dpy, vInfo, GLX_RGBA, &attribs->rgba);
399 glXGetConfig(dpy, vInfo, GLX_DOUBLEBUFFER, &attribs->doubleBuffer);
400 glXGetConfig(dpy, vInfo, GLX_STEREO, &attribs->stereo);
401 glXGetConfig(dpy, vInfo, GLX_AUX_BUFFERS, &attribs->auxBuffers);
402 glXGetConfig(dpy, vInfo, GLX_RED_SIZE, &attribs->redSize);
403 glXGetConfig(dpy, vInfo, GLX_GREEN_SIZE, &attribs->greenSize);
404 glXGetConfig(dpy, vInfo, GLX_BLUE_SIZE, &attribs->blueSize);
405 glXGetConfig(dpy, vInfo, GLX_ALPHA_SIZE, &attribs->alphaSize);
406 glXGetConfig(dpy, vInfo, GLX_DEPTH_SIZE, &attribs->depthSize);
407 glXGetConfig(dpy, vInfo, GLX_STENCIL_SIZE, &attribs->stencilSize);
408 glXGetConfig(dpy, vInfo, GLX_ACCUM_RED_SIZE, &attribs->accumRedSize);
409 glXGetConfig(dpy, vInfo, GLX_ACCUM_GREEN_SIZE, &attribs->accumGreenSize);
410 glXGetConfig(dpy, vInfo, GLX_ACCUM_BLUE_SIZE, &attribs->accumBlueSize);
411 glXGetConfig(dpy, vInfo, GLX_ACCUM_ALPHA_SIZE, &attribs->accumAlphaSize);
412
Brian Paul45c56982002-10-14 13:57:23 +0000413 /* get transparent pixel stuff */
414 glXGetConfig(dpy, vInfo,GLX_TRANSPARENT_TYPE, &attribs->transparentType);
415 if (attribs->transparentType == GLX_TRANSPARENT_RGB) {
416 glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_RED_VALUE, &attribs->transparentRedValue);
417 glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_GREEN_VALUE, &attribs->transparentGreenValue);
418 glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_BLUE_VALUE, &attribs->transparentBlueValue);
419 glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_ALPHA_VALUE, &attribs->transparentAlphaValue);
420 }
421 else if (attribs->transparentType == GLX_TRANSPARENT_INDEX) {
422 glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_INDEX_VALUE, &attribs->transparentIndexValue);
423 }
Brian Paule06c7f32000-01-27 16:53:55 +0000424
Brian Pauld2e39bb2002-11-04 16:24:18 +0000425 /* multisample attribs */
426#ifdef GLX_ARB_multisample
427 if (strstr("GLX_ARB_multisample", ext) == 0) {
428 glXGetConfig(dpy, vInfo, GLX_SAMPLE_BUFFERS_ARB, &attribs->numMultisample);
429 glXGetConfig(dpy, vInfo, GLX_SAMPLES_ARB, &attribs->numSamples);
430 }
431#endif
432 else {
433 attribs->numSamples = 0;
434 attribs->numMultisample = 0;
435 }
Brian Paul25673f02000-03-31 18:17:51 +0000436
437#if defined(GLX_EXT_visual_rating)
438 if (ext && strstr(ext, "GLX_EXT_visual_rating")) {
439 glXGetConfig(dpy, vInfo, GLX_VISUAL_CAVEAT_EXT, &attribs->visualCaveat);
440 }
441 else {
442 attribs->visualCaveat = GLX_NONE_EXT;
443 }
444#else
445 attribs->visualCaveat = 0;
446#endif
Brian Paul76bc4402000-01-27 16:43:56 +0000447}
448
449
450static void
451print_visual_attribs_verbose(const struct visual_attribs *attribs)
452{
453 printf("Visual ID: %x depth=%d class=%s\n",
454 attribs->id, attribs->depth, visual_class_name(attribs->klass));
455 printf(" bufferSize=%d level=%d renderType=%s doubleBuffer=%d stereo=%d\n",
456 attribs->bufferSize, attribs->level, attribs->rgba ? "rgba" : "ci",
457 attribs->doubleBuffer, attribs->stereo);
458 printf(" rgba: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n",
459 attribs->redSize, attribs->greenSize,
460 attribs->blueSize, attribs->alphaSize);
461 printf(" auxBuffers=%d depthSize=%d stencilSize=%d\n",
462 attribs->auxBuffers, attribs->depthSize, attribs->stencilSize);
463 printf(" accum: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n",
464 attribs->accumRedSize, attribs->accumGreenSize,
465 attribs->accumBlueSize, attribs->accumAlphaSize);
466 printf(" multiSample=%d multiSampleBuffers=%d\n",
467 attribs->numSamples, attribs->numMultisample);
Brian Paul25673f02000-03-31 18:17:51 +0000468#ifdef GLX_EXT_visual_rating
469 if (attribs->visualCaveat == GLX_NONE_EXT || attribs->visualCaveat == 0)
Brian Paula9c53fa2000-04-03 15:45:34 +0000470 printf(" visualCaveat=None\n");
Brian Paul25673f02000-03-31 18:17:51 +0000471 else if (attribs->visualCaveat == GLX_SLOW_VISUAL_EXT)
Brian Paula9c53fa2000-04-03 15:45:34 +0000472 printf(" visualCaveat=Slow\n");
Brian Paul25673f02000-03-31 18:17:51 +0000473 else if (attribs->visualCaveat == GLX_NON_CONFORMANT_VISUAL_EXT)
Brian Paula9c53fa2000-04-03 15:45:34 +0000474 printf(" visualCaveat=Nonconformant\n");
Brian Paul25673f02000-03-31 18:17:51 +0000475#endif
Brian Paul45c56982002-10-14 13:57:23 +0000476 if (attribs->transparentType == GLX_NONE) {
477 printf(" Opaque.\n");
478 }
479 else if (attribs->transparentType == GLX_TRANSPARENT_RGB) {
480 printf(" Transparent RGB: Red=%d Green=%d Blue=%d Alpha=%d\n",attribs->transparentRedValue,attribs->transparentGreenValue,attribs->transparentBlueValue,attribs->transparentAlphaValue);
481 }
482 else if (attribs->transparentType == GLX_TRANSPARENT_INDEX) {
483 printf(" Transparent index=%d\n",attribs->transparentIndexValue);
484 }
Brian Paul76bc4402000-01-27 16:43:56 +0000485}
486
487
488static void
489print_visual_attribs_short_header(void)
490{
Brian Paula9c53fa2000-04-03 15:45:34 +0000491 printf(" visual x bf lv rg d st colorbuffer ax dp st accumbuffer ms cav\n");
492 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 +0000493 printf("----------------------------------------------------------------------\n");
Brian Paul76bc4402000-01-27 16:43:56 +0000494}
495
496
497static void
498print_visual_attribs_short(const struct visual_attribs *attribs)
499{
Brian Paula3e44f42002-03-08 19:44:28 +0000500 char *caveat = NULL;
Brian Paul25673f02000-03-31 18:17:51 +0000501#ifdef GLX_EXT_visual_rating
502 if (attribs->visualCaveat == GLX_NONE_EXT || attribs->visualCaveat == 0)
503 caveat = "None";
504 else if (attribs->visualCaveat == GLX_SLOW_VISUAL_EXT)
505 caveat = "Slow";
506 else if (attribs->visualCaveat == GLX_NON_CONFORMANT_VISUAL_EXT)
507 caveat = "Ncon";
Brian Paul28bc6cb2002-09-06 03:47:34 +0000508 else
509 caveat = "None";
Brian Paul25673f02000-03-31 18:17:51 +0000510#else
511 caveat = "None";
512#endif
513
Brian Paul76bc4402000-01-27 16:43:56 +0000514 printf("0x%2x %2d %2s %2d %2d %2d %1s %2s %2s %2d %2d %2d %2d %2d %2d %2d",
515 attribs->id,
516 attribs->depth,
517 visual_class_abbrev(attribs->klass),
Brian Paul45c56982002-10-14 13:57:23 +0000518 attribs->transparentType != GLX_NONE,
Brian Paul76bc4402000-01-27 16:43:56 +0000519 attribs->bufferSize,
520 attribs->level,
521 attribs->rgba ? "r" : "c",
522 attribs->doubleBuffer ? "y" : ".",
523 attribs->stereo ? "y" : ".",
524 attribs->redSize, attribs->greenSize,
525 attribs->blueSize, attribs->alphaSize,
526 attribs->auxBuffers,
527 attribs->depthSize,
528 attribs->stencilSize
529 );
530
Brian Paul25673f02000-03-31 18:17:51 +0000531 printf(" %2d %2d %2d %2d %2d %1d %s\n",
Brian Paul76bc4402000-01-27 16:43:56 +0000532 attribs->accumRedSize, attribs->accumGreenSize,
533 attribs->accumBlueSize, attribs->accumAlphaSize,
Brian Paul25673f02000-03-31 18:17:51 +0000534 attribs->numSamples, attribs->numMultisample,
535 caveat
Brian Paul76bc4402000-01-27 16:43:56 +0000536 );
537}
538
539
540static void
541print_visual_attribs_long_header(void)
542{
543 printf("Vis Vis Visual Trans buff lev render DB ste r g b a aux dep ste accum buffers MS MS\n");
544 printf(" ID Depth Type parent size el type reo sz sz sz sz buf th ncl r g b a num bufs\n");
545 printf("----------------------------------------------------------------------------------------------------\n");
546}
547
548
549static void
550print_visual_attribs_long(const struct visual_attribs *attribs)
551{
552 printf("0x%2x %2d %-11s %2d %2d %2d %4s %3d %3d %3d %3d %3d %3d",
553 attribs->id,
554 attribs->depth,
555 visual_class_name(attribs->klass),
Brian Paul45c56982002-10-14 13:57:23 +0000556 attribs->transparentType != GLX_NONE,
Brian Paul76bc4402000-01-27 16:43:56 +0000557 attribs->bufferSize,
558 attribs->level,
559 attribs->rgba ? "rgba" : "ci ",
560 attribs->doubleBuffer,
561 attribs->stereo,
562 attribs->redSize, attribs->greenSize,
563 attribs->blueSize, attribs->alphaSize
564 );
565
566 printf(" %3d %4d %2d %3d %3d %3d %3d %2d %2d\n",
567 attribs->auxBuffers,
568 attribs->depthSize,
569 attribs->stencilSize,
570 attribs->accumRedSize, attribs->accumGreenSize,
571 attribs->accumBlueSize, attribs->accumAlphaSize,
572 attribs->numSamples, attribs->numMultisample
573 );
574}
575
576
577static void
578print_visual_info(Display *dpy, int scrnum, InfoMode mode)
579{
Brian Paulf02a5f62002-07-12 15:54:01 +0000580 XVisualInfo theTemplate;
Brian Paul76bc4402000-01-27 16:43:56 +0000581 XVisualInfo *visuals;
582 int numVisuals;
583 long mask;
584 int i;
585
586 /* get list of all visuals on this screen */
Brian Paulf02a5f62002-07-12 15:54:01 +0000587 theTemplate.screen = scrnum;
Brian Paul76bc4402000-01-27 16:43:56 +0000588 mask = VisualScreenMask;
Brian Paulf02a5f62002-07-12 15:54:01 +0000589 visuals = XGetVisualInfo(dpy, mask, &theTemplate, &numVisuals);
Brian Paul76bc4402000-01-27 16:43:56 +0000590
591 if (mode == Verbose) {
592 for (i = 0; i < numVisuals; i++) {
593 struct visual_attribs attribs;
594 get_visual_attribs(dpy, &visuals[i], &attribs);
595 print_visual_attribs_verbose(&attribs);
596 }
597 }
598 else if (mode == Normal) {
599 print_visual_attribs_short_header();
600 for (i = 0; i < numVisuals; i++) {
601 struct visual_attribs attribs;
602 get_visual_attribs(dpy, &visuals[i], &attribs);
603 print_visual_attribs_short(&attribs);
604 }
605 }
606 else if (mode == Wide) {
607 print_visual_attribs_long_header();
608 for (i = 0; i < numVisuals; i++) {
609 struct visual_attribs attribs;
610 get_visual_attribs(dpy, &visuals[i], &attribs);
611 print_visual_attribs_long(&attribs);
612 }
613 }
614
615 XFree(visuals);
616}
617
618
Brian Paul39557c32001-03-23 21:41:44 +0000619/*
620 * Stand-alone Mesa doesn't really implement the GLX protocol so it
621 * doesn't really know the GLX attributes associated with an X visual.
622 * The first time a visual is presented to Mesa's pseudo-GLX it
623 * attaches ancilliary buffers to it (like depth and stencil).
624 * But that usually only works if glXChooseVisual is used.
625 * This function calls glXChooseVisual() to sort of "prime the pump"
626 * for Mesa's GLX so that the visuals that get reported actually
627 * reflect what applications will see.
628 * This has no effect when using true GLX.
629 */
630static void
631mesa_hack(Display *dpy, int scrnum)
632{
633 static int attribs[] = {
634 GLX_RGBA,
635 GLX_RED_SIZE, 1,
636 GLX_GREEN_SIZE, 1,
637 GLX_BLUE_SIZE, 1,
638 GLX_DEPTH_SIZE, 1,
639 GLX_STENCIL_SIZE, 1,
640 GLX_ACCUM_RED_SIZE, 1,
641 GLX_ACCUM_GREEN_SIZE, 1,
642 GLX_ACCUM_BLUE_SIZE, 1,
643 GLX_ACCUM_ALPHA_SIZE, 1,
644 GLX_DOUBLEBUFFER,
645 None
646 };
647 XVisualInfo *visinfo;
648
649 visinfo = glXChooseVisual(dpy, scrnum, attribs);
650 if (visinfo)
651 XFree(visinfo);
652}
653
654
655/*
656 * Examine all visuals to find the so-called best one.
657 * We prefer deepest RGBA buffer with depth, stencil and accum
658 * that has no caveats.
659 */
660static int
661find_best_visual(Display *dpy, int scrnum)
662{
Brian Paulf02a5f62002-07-12 15:54:01 +0000663 XVisualInfo theTemplate;
Brian Paul39557c32001-03-23 21:41:44 +0000664 XVisualInfo *visuals;
665 int numVisuals;
666 long mask;
667 int i;
668 struct visual_attribs bestVis;
669
670 /* get list of all visuals on this screen */
Brian Paulf02a5f62002-07-12 15:54:01 +0000671 theTemplate.screen = scrnum;
Brian Paul39557c32001-03-23 21:41:44 +0000672 mask = VisualScreenMask;
Brian Paulf02a5f62002-07-12 15:54:01 +0000673 visuals = XGetVisualInfo(dpy, mask, &theTemplate, &numVisuals);
Brian Paul39557c32001-03-23 21:41:44 +0000674
675 /* init bestVis with first visual info */
676 get_visual_attribs(dpy, &visuals[0], &bestVis);
677
678 /* try to find a "better" visual */
679 for (i = 1; i < numVisuals; i++) {
680 struct visual_attribs vis;
681
682 get_visual_attribs(dpy, &visuals[i], &vis);
683
684 /* always skip visuals with caveats */
685 if (vis.visualCaveat != GLX_NONE_EXT)
686 continue;
687
688 /* see if this vis is better than bestVis */
689 if ((!bestVis.supportsGL && vis.supportsGL) ||
690 (bestVis.visualCaveat != GLX_NONE_EXT) ||
691 (!bestVis.rgba && vis.rgba) ||
692 (!bestVis.doubleBuffer && vis.doubleBuffer) ||
693 (bestVis.redSize < vis.redSize) ||
694 (bestVis.greenSize < vis.greenSize) ||
695 (bestVis.blueSize < vis.blueSize) ||
696 (bestVis.alphaSize < vis.alphaSize) ||
697 (bestVis.depthSize < vis.depthSize) ||
698 (bestVis.stencilSize < vis.stencilSize) ||
699 (bestVis.accumRedSize < vis.accumRedSize)) {
700 /* found a better visual */
701 bestVis = vis;
702 }
703 }
704
705 XFree(visuals);
706
707 return bestVis.id;
708}
709
710
Brian Paul08b3ff12001-04-24 20:57:36 +0000711static void
712usage(void)
713{
714 printf("Usage: glxinfo [-v] [-t] [-h] [-i] [-b] [-display <dname>]\n");
715 printf("\t-v: Print visuals info in verbose form.\n");
716 printf("\t-t: Print verbose table.\n");
717 printf("\t-display <dname>: Print GLX visuals on specified server.\n");
718 printf("\t-h: This information.\n");
719 printf("\t-i: Force an indirect rendering context.\n");
720 printf("\t-b: Find the 'best' visual and print it's number.\n");
Brian Paul2f7ef5f2002-09-06 03:35:43 +0000721 printf("\t-l: Print interesting OpenGLl imits.\n");
Brian Paul08b3ff12001-04-24 20:57:36 +0000722}
723
724
Brian Paul76bc4402000-01-27 16:43:56 +0000725int
726main(int argc, char *argv[])
727{
Alan Hourihanee18599a2001-03-19 13:58:45 +0000728 char *displayName = NULL;
Brian Paul76bc4402000-01-27 16:43:56 +0000729 Display *dpy;
730 int numScreens, scrnum;
731 InfoMode mode = Normal;
Brian Paul39557c32001-03-23 21:41:44 +0000732 GLboolean findBest = GL_FALSE;
Brian Paul2f7ef5f2002-09-06 03:35:43 +0000733 GLboolean limits = GL_FALSE;
Brian Paul08b3ff12001-04-24 20:57:36 +0000734 Bool allowDirect = True;
Brian Paul76bc4402000-01-27 16:43:56 +0000735 int i;
736
737 for (i = 1; i < argc; i++) {
738 if (strcmp(argv[i], "-display") == 0 && i + 1 < argc) {
739 displayName = argv[i + 1];
740 i++;
741 }
742 else if (strcmp(argv[i], "-t") == 0) {
743 mode = Wide;
744 }
745 else if (strcmp(argv[i], "-v") == 0) {
746 mode = Verbose;
747 }
Brian Paul39557c32001-03-23 21:41:44 +0000748 else if (strcmp(argv[i], "-b") == 0) {
749 findBest = GL_TRUE;
750 }
Brian Paul08b3ff12001-04-24 20:57:36 +0000751 else if (strcmp(argv[i], "-i") == 0) {
752 allowDirect = False;
753 }
Brian Paul2f7ef5f2002-09-06 03:35:43 +0000754 else if (strcmp(argv[i], "-l") == 0) {
755 limits = GL_TRUE;
756 }
Brian Paul08b3ff12001-04-24 20:57:36 +0000757 else if (strcmp(argv[i], "-h") == 0) {
758 usage();
759 return 0;
760 }
761 else {
762 printf("Unknown option `%s'\n", argv[i]);
763 usage();
764 return 0;
765 }
Brian Paul76bc4402000-01-27 16:43:56 +0000766 }
767
768 dpy = XOpenDisplay(displayName);
769 if (!dpy) {
770 fprintf(stderr, "Error: unable to open display %s\n", displayName);
771 return -1;
772 }
773
Brian Paul39557c32001-03-23 21:41:44 +0000774 if (findBest) {
775 int b;
776 mesa_hack(dpy, 0);
777 b = find_best_visual(dpy, 0);
778 printf("%d\n", b);
779 }
780 else {
781 numScreens = ScreenCount(dpy);
Brian Paul373aea12001-04-02 22:45:07 +0000782 print_display_info(dpy);
Brian Paul39557c32001-03-23 21:41:44 +0000783 for (scrnum = 0; scrnum < numScreens; scrnum++) {
784 mesa_hack(dpy, scrnum);
Brian Paul2f7ef5f2002-09-06 03:35:43 +0000785 print_screen_info(dpy, scrnum, allowDirect, limits);
Brian Paul39557c32001-03-23 21:41:44 +0000786 printf("\n");
787 print_visual_info(dpy, scrnum, mode);
788 if (scrnum + 1 < numScreens)
789 printf("\n\n");
790 }
Brian Paul76bc4402000-01-27 16:43:56 +0000791 }
792
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000793 XCloseDisplay(dpy);
794
795 return 0;
796}