blob: dde24c48658852aca589127eb594ec103a32087c [file] [log] [blame]
Brian Paul45c56982002-10-14 13:57:23 +00001/* $Id: glxinfo.c,v 1.20 2002/10/14 13:57:23 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
425 /* multisample tests not implemented yet */
Brian Paul76bc4402000-01-27 16:43:56 +0000426 attribs->numSamples = 0;
427 attribs->numMultisample = 0;
Brian Paul25673f02000-03-31 18:17:51 +0000428
429#if defined(GLX_EXT_visual_rating)
430 if (ext && strstr(ext, "GLX_EXT_visual_rating")) {
431 glXGetConfig(dpy, vInfo, GLX_VISUAL_CAVEAT_EXT, &attribs->visualCaveat);
432 }
433 else {
434 attribs->visualCaveat = GLX_NONE_EXT;
435 }
436#else
437 attribs->visualCaveat = 0;
438#endif
Brian Paul76bc4402000-01-27 16:43:56 +0000439}
440
441
442static void
443print_visual_attribs_verbose(const struct visual_attribs *attribs)
444{
445 printf("Visual ID: %x depth=%d class=%s\n",
446 attribs->id, attribs->depth, visual_class_name(attribs->klass));
447 printf(" bufferSize=%d level=%d renderType=%s doubleBuffer=%d stereo=%d\n",
448 attribs->bufferSize, attribs->level, attribs->rgba ? "rgba" : "ci",
449 attribs->doubleBuffer, attribs->stereo);
450 printf(" rgba: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n",
451 attribs->redSize, attribs->greenSize,
452 attribs->blueSize, attribs->alphaSize);
453 printf(" auxBuffers=%d depthSize=%d stencilSize=%d\n",
454 attribs->auxBuffers, attribs->depthSize, attribs->stencilSize);
455 printf(" accum: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n",
456 attribs->accumRedSize, attribs->accumGreenSize,
457 attribs->accumBlueSize, attribs->accumAlphaSize);
458 printf(" multiSample=%d multiSampleBuffers=%d\n",
459 attribs->numSamples, attribs->numMultisample);
Brian Paul25673f02000-03-31 18:17:51 +0000460#ifdef GLX_EXT_visual_rating
461 if (attribs->visualCaveat == GLX_NONE_EXT || attribs->visualCaveat == 0)
Brian Paula9c53fa2000-04-03 15:45:34 +0000462 printf(" visualCaveat=None\n");
Brian Paul25673f02000-03-31 18:17:51 +0000463 else if (attribs->visualCaveat == GLX_SLOW_VISUAL_EXT)
Brian Paula9c53fa2000-04-03 15:45:34 +0000464 printf(" visualCaveat=Slow\n");
Brian Paul25673f02000-03-31 18:17:51 +0000465 else if (attribs->visualCaveat == GLX_NON_CONFORMANT_VISUAL_EXT)
Brian Paula9c53fa2000-04-03 15:45:34 +0000466 printf(" visualCaveat=Nonconformant\n");
Brian Paul25673f02000-03-31 18:17:51 +0000467#endif
Brian Paul45c56982002-10-14 13:57:23 +0000468 if (attribs->transparentType == GLX_NONE) {
469 printf(" Opaque.\n");
470 }
471 else if (attribs->transparentType == GLX_TRANSPARENT_RGB) {
472 printf(" Transparent RGB: Red=%d Green=%d Blue=%d Alpha=%d\n",attribs->transparentRedValue,attribs->transparentGreenValue,attribs->transparentBlueValue,attribs->transparentAlphaValue);
473 }
474 else if (attribs->transparentType == GLX_TRANSPARENT_INDEX) {
475 printf(" Transparent index=%d\n",attribs->transparentIndexValue);
476 }
Brian Paul76bc4402000-01-27 16:43:56 +0000477}
478
479
480static void
481print_visual_attribs_short_header(void)
482{
Brian Paula9c53fa2000-04-03 15:45:34 +0000483 printf(" visual x bf lv rg d st colorbuffer ax dp st accumbuffer ms cav\n");
484 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 +0000485 printf("----------------------------------------------------------------------\n");
Brian Paul76bc4402000-01-27 16:43:56 +0000486}
487
488
489static void
490print_visual_attribs_short(const struct visual_attribs *attribs)
491{
Brian Paula3e44f42002-03-08 19:44:28 +0000492 char *caveat = NULL;
Brian Paul25673f02000-03-31 18:17:51 +0000493#ifdef GLX_EXT_visual_rating
494 if (attribs->visualCaveat == GLX_NONE_EXT || attribs->visualCaveat == 0)
495 caveat = "None";
496 else if (attribs->visualCaveat == GLX_SLOW_VISUAL_EXT)
497 caveat = "Slow";
498 else if (attribs->visualCaveat == GLX_NON_CONFORMANT_VISUAL_EXT)
499 caveat = "Ncon";
Brian Paul28bc6cb2002-09-06 03:47:34 +0000500 else
501 caveat = "None";
Brian Paul25673f02000-03-31 18:17:51 +0000502#else
503 caveat = "None";
504#endif
505
Brian Paul76bc4402000-01-27 16:43:56 +0000506 printf("0x%2x %2d %2s %2d %2d %2d %1s %2s %2s %2d %2d %2d %2d %2d %2d %2d",
507 attribs->id,
508 attribs->depth,
509 visual_class_abbrev(attribs->klass),
Brian Paul45c56982002-10-14 13:57:23 +0000510 attribs->transparentType != GLX_NONE,
Brian Paul76bc4402000-01-27 16:43:56 +0000511 attribs->bufferSize,
512 attribs->level,
513 attribs->rgba ? "r" : "c",
514 attribs->doubleBuffer ? "y" : ".",
515 attribs->stereo ? "y" : ".",
516 attribs->redSize, attribs->greenSize,
517 attribs->blueSize, attribs->alphaSize,
518 attribs->auxBuffers,
519 attribs->depthSize,
520 attribs->stencilSize
521 );
522
Brian Paul25673f02000-03-31 18:17:51 +0000523 printf(" %2d %2d %2d %2d %2d %1d %s\n",
Brian Paul76bc4402000-01-27 16:43:56 +0000524 attribs->accumRedSize, attribs->accumGreenSize,
525 attribs->accumBlueSize, attribs->accumAlphaSize,
Brian Paul25673f02000-03-31 18:17:51 +0000526 attribs->numSamples, attribs->numMultisample,
527 caveat
Brian Paul76bc4402000-01-27 16:43:56 +0000528 );
529}
530
531
532static void
533print_visual_attribs_long_header(void)
534{
535 printf("Vis Vis Visual Trans buff lev render DB ste r g b a aux dep ste accum buffers MS MS\n");
536 printf(" ID Depth Type parent size el type reo sz sz sz sz buf th ncl r g b a num bufs\n");
537 printf("----------------------------------------------------------------------------------------------------\n");
538}
539
540
541static void
542print_visual_attribs_long(const struct visual_attribs *attribs)
543{
544 printf("0x%2x %2d %-11s %2d %2d %2d %4s %3d %3d %3d %3d %3d %3d",
545 attribs->id,
546 attribs->depth,
547 visual_class_name(attribs->klass),
Brian Paul45c56982002-10-14 13:57:23 +0000548 attribs->transparentType != GLX_NONE,
Brian Paul76bc4402000-01-27 16:43:56 +0000549 attribs->bufferSize,
550 attribs->level,
551 attribs->rgba ? "rgba" : "ci ",
552 attribs->doubleBuffer,
553 attribs->stereo,
554 attribs->redSize, attribs->greenSize,
555 attribs->blueSize, attribs->alphaSize
556 );
557
558 printf(" %3d %4d %2d %3d %3d %3d %3d %2d %2d\n",
559 attribs->auxBuffers,
560 attribs->depthSize,
561 attribs->stencilSize,
562 attribs->accumRedSize, attribs->accumGreenSize,
563 attribs->accumBlueSize, attribs->accumAlphaSize,
564 attribs->numSamples, attribs->numMultisample
565 );
566}
567
568
569static void
570print_visual_info(Display *dpy, int scrnum, InfoMode mode)
571{
Brian Paulf02a5f62002-07-12 15:54:01 +0000572 XVisualInfo theTemplate;
Brian Paul76bc4402000-01-27 16:43:56 +0000573 XVisualInfo *visuals;
574 int numVisuals;
575 long mask;
576 int i;
577
578 /* get list of all visuals on this screen */
Brian Paulf02a5f62002-07-12 15:54:01 +0000579 theTemplate.screen = scrnum;
Brian Paul76bc4402000-01-27 16:43:56 +0000580 mask = VisualScreenMask;
Brian Paulf02a5f62002-07-12 15:54:01 +0000581 visuals = XGetVisualInfo(dpy, mask, &theTemplate, &numVisuals);
Brian Paul76bc4402000-01-27 16:43:56 +0000582
583 if (mode == Verbose) {
584 for (i = 0; i < numVisuals; i++) {
585 struct visual_attribs attribs;
586 get_visual_attribs(dpy, &visuals[i], &attribs);
587 print_visual_attribs_verbose(&attribs);
588 }
589 }
590 else if (mode == Normal) {
591 print_visual_attribs_short_header();
592 for (i = 0; i < numVisuals; i++) {
593 struct visual_attribs attribs;
594 get_visual_attribs(dpy, &visuals[i], &attribs);
595 print_visual_attribs_short(&attribs);
596 }
597 }
598 else if (mode == Wide) {
599 print_visual_attribs_long_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_long(&attribs);
604 }
605 }
606
607 XFree(visuals);
608}
609
610
Brian Paul39557c32001-03-23 21:41:44 +0000611/*
612 * Stand-alone Mesa doesn't really implement the GLX protocol so it
613 * doesn't really know the GLX attributes associated with an X visual.
614 * The first time a visual is presented to Mesa's pseudo-GLX it
615 * attaches ancilliary buffers to it (like depth and stencil).
616 * But that usually only works if glXChooseVisual is used.
617 * This function calls glXChooseVisual() to sort of "prime the pump"
618 * for Mesa's GLX so that the visuals that get reported actually
619 * reflect what applications will see.
620 * This has no effect when using true GLX.
621 */
622static void
623mesa_hack(Display *dpy, int scrnum)
624{
625 static int attribs[] = {
626 GLX_RGBA,
627 GLX_RED_SIZE, 1,
628 GLX_GREEN_SIZE, 1,
629 GLX_BLUE_SIZE, 1,
630 GLX_DEPTH_SIZE, 1,
631 GLX_STENCIL_SIZE, 1,
632 GLX_ACCUM_RED_SIZE, 1,
633 GLX_ACCUM_GREEN_SIZE, 1,
634 GLX_ACCUM_BLUE_SIZE, 1,
635 GLX_ACCUM_ALPHA_SIZE, 1,
636 GLX_DOUBLEBUFFER,
637 None
638 };
639 XVisualInfo *visinfo;
640
641 visinfo = glXChooseVisual(dpy, scrnum, attribs);
642 if (visinfo)
643 XFree(visinfo);
644}
645
646
647/*
648 * Examine all visuals to find the so-called best one.
649 * We prefer deepest RGBA buffer with depth, stencil and accum
650 * that has no caveats.
651 */
652static int
653find_best_visual(Display *dpy, int scrnum)
654{
Brian Paulf02a5f62002-07-12 15:54:01 +0000655 XVisualInfo theTemplate;
Brian Paul39557c32001-03-23 21:41:44 +0000656 XVisualInfo *visuals;
657 int numVisuals;
658 long mask;
659 int i;
660 struct visual_attribs bestVis;
661
662 /* get list of all visuals on this screen */
Brian Paulf02a5f62002-07-12 15:54:01 +0000663 theTemplate.screen = scrnum;
Brian Paul39557c32001-03-23 21:41:44 +0000664 mask = VisualScreenMask;
Brian Paulf02a5f62002-07-12 15:54:01 +0000665 visuals = XGetVisualInfo(dpy, mask, &theTemplate, &numVisuals);
Brian Paul39557c32001-03-23 21:41:44 +0000666
667 /* init bestVis with first visual info */
668 get_visual_attribs(dpy, &visuals[0], &bestVis);
669
670 /* try to find a "better" visual */
671 for (i = 1; i < numVisuals; i++) {
672 struct visual_attribs vis;
673
674 get_visual_attribs(dpy, &visuals[i], &vis);
675
676 /* always skip visuals with caveats */
677 if (vis.visualCaveat != GLX_NONE_EXT)
678 continue;
679
680 /* see if this vis is better than bestVis */
681 if ((!bestVis.supportsGL && vis.supportsGL) ||
682 (bestVis.visualCaveat != GLX_NONE_EXT) ||
683 (!bestVis.rgba && vis.rgba) ||
684 (!bestVis.doubleBuffer && vis.doubleBuffer) ||
685 (bestVis.redSize < vis.redSize) ||
686 (bestVis.greenSize < vis.greenSize) ||
687 (bestVis.blueSize < vis.blueSize) ||
688 (bestVis.alphaSize < vis.alphaSize) ||
689 (bestVis.depthSize < vis.depthSize) ||
690 (bestVis.stencilSize < vis.stencilSize) ||
691 (bestVis.accumRedSize < vis.accumRedSize)) {
692 /* found a better visual */
693 bestVis = vis;
694 }
695 }
696
697 XFree(visuals);
698
699 return bestVis.id;
700}
701
702
Brian Paul08b3ff12001-04-24 20:57:36 +0000703static void
704usage(void)
705{
706 printf("Usage: glxinfo [-v] [-t] [-h] [-i] [-b] [-display <dname>]\n");
707 printf("\t-v: Print visuals info in verbose form.\n");
708 printf("\t-t: Print verbose table.\n");
709 printf("\t-display <dname>: Print GLX visuals on specified server.\n");
710 printf("\t-h: This information.\n");
711 printf("\t-i: Force an indirect rendering context.\n");
712 printf("\t-b: Find the 'best' visual and print it's number.\n");
Brian Paul2f7ef5f2002-09-06 03:35:43 +0000713 printf("\t-l: Print interesting OpenGLl imits.\n");
Brian Paul08b3ff12001-04-24 20:57:36 +0000714}
715
716
Brian Paul76bc4402000-01-27 16:43:56 +0000717int
718main(int argc, char *argv[])
719{
Alan Hourihanee18599a2001-03-19 13:58:45 +0000720 char *displayName = NULL;
Brian Paul76bc4402000-01-27 16:43:56 +0000721 Display *dpy;
722 int numScreens, scrnum;
723 InfoMode mode = Normal;
Brian Paul39557c32001-03-23 21:41:44 +0000724 GLboolean findBest = GL_FALSE;
Brian Paul2f7ef5f2002-09-06 03:35:43 +0000725 GLboolean limits = GL_FALSE;
Brian Paul08b3ff12001-04-24 20:57:36 +0000726 Bool allowDirect = True;
Brian Paul76bc4402000-01-27 16:43:56 +0000727 int i;
728
729 for (i = 1; i < argc; i++) {
730 if (strcmp(argv[i], "-display") == 0 && i + 1 < argc) {
731 displayName = argv[i + 1];
732 i++;
733 }
734 else if (strcmp(argv[i], "-t") == 0) {
735 mode = Wide;
736 }
737 else if (strcmp(argv[i], "-v") == 0) {
738 mode = Verbose;
739 }
Brian Paul39557c32001-03-23 21:41:44 +0000740 else if (strcmp(argv[i], "-b") == 0) {
741 findBest = GL_TRUE;
742 }
Brian Paul08b3ff12001-04-24 20:57:36 +0000743 else if (strcmp(argv[i], "-i") == 0) {
744 allowDirect = False;
745 }
Brian Paul2f7ef5f2002-09-06 03:35:43 +0000746 else if (strcmp(argv[i], "-l") == 0) {
747 limits = GL_TRUE;
748 }
Brian Paul08b3ff12001-04-24 20:57:36 +0000749 else if (strcmp(argv[i], "-h") == 0) {
750 usage();
751 return 0;
752 }
753 else {
754 printf("Unknown option `%s'\n", argv[i]);
755 usage();
756 return 0;
757 }
Brian Paul76bc4402000-01-27 16:43:56 +0000758 }
759
760 dpy = XOpenDisplay(displayName);
761 if (!dpy) {
762 fprintf(stderr, "Error: unable to open display %s\n", displayName);
763 return -1;
764 }
765
Brian Paul39557c32001-03-23 21:41:44 +0000766 if (findBest) {
767 int b;
768 mesa_hack(dpy, 0);
769 b = find_best_visual(dpy, 0);
770 printf("%d\n", b);
771 }
772 else {
773 numScreens = ScreenCount(dpy);
Brian Paul373aea12001-04-02 22:45:07 +0000774 print_display_info(dpy);
Brian Paul39557c32001-03-23 21:41:44 +0000775 for (scrnum = 0; scrnum < numScreens; scrnum++) {
776 mesa_hack(dpy, scrnum);
Brian Paul2f7ef5f2002-09-06 03:35:43 +0000777 print_screen_info(dpy, scrnum, allowDirect, limits);
Brian Paul39557c32001-03-23 21:41:44 +0000778 printf("\n");
779 print_visual_info(dpy, scrnum, mode);
780 if (scrnum + 1 < numScreens)
781 printf("\n\n");
782 }
Brian Paul76bc4402000-01-27 16:43:56 +0000783 }
784
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000785 XCloseDisplay(dpy);
786
787 return 0;
788}