blob: 06c1980b0ce907912137e55f26d6564fb0b45b10 [file] [log] [blame]
Brian Paul57df24a2002-09-06 12:58:56 +00001/* $Id: glxinfo.c,v 1.19 2002/09/06 12:58:56 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
56
Brian Paul76bc4402000-01-27 16:43:56 +000057typedef enum
Brian Pauld2bfe1e1999-09-16 16:40:46 +000058{
Brian Paul76bc4402000-01-27 16:43:56 +000059 Normal,
60 Wide,
61 Verbose
62} InfoMode;
Brian Pauld2bfe1e1999-09-16 16:40:46 +000063
Brian Pauld2bfe1e1999-09-16 16:40:46 +000064
Brian Paul76bc4402000-01-27 16:43:56 +000065struct visual_attribs
66{
67 /* X visual attribs */
68 int id;
69 int klass;
70 int depth;
71 int redMask, greenMask, blueMask;
72 int colormapSize;
73 int bitsPerRGB;
Brian Pauld2bfe1e1999-09-16 16:40:46 +000074
Brian Paul76bc4402000-01-27 16:43:56 +000075 /* GL visual attribs */
76 int supportsGL;
77 int transparent;
78 int bufferSize;
79 int level;
80 int rgba;
81 int doubleBuffer;
82 int stereo;
83 int auxBuffers;
84 int redSize, greenSize, blueSize, alphaSize;
85 int depthSize;
86 int stencilSize;
87 int accumRedSize, accumGreenSize, accumBlueSize, accumAlphaSize;
88 int numSamples, numMultisample;
Brian Paul25673f02000-03-31 18:17:51 +000089 int visualCaveat;
Brian Paul76bc4402000-01-27 16:43:56 +000090};
91
92
93/*
94 * Print a list of extensions, with word-wrapping.
95 */
96static void
97print_extension_list(const char *ext)
98{
99 const char *indentString = " ";
100 const int indent = 4;
101 const int max = 79;
102 int width, i, j;
103
104 if (!ext || !ext[0])
105 return;
106
107 width = indent;
108 printf(indentString);
109 i = j = 0;
110 while (1) {
111 if (ext[j] == ' ' || ext[j] == 0) {
112 /* found end of an extension name */
113 const int len = j - i;
114 if (width + len > max) {
115 /* start a new line */
116 printf("\n");
117 width = indent;
118 printf(indentString);
119 }
120 /* print the extension name between ext[i] and ext[j] */
121 while (i < j) {
122 printf("%c", ext[i]);
123 i++;
124 }
125 /* either we're all done, or we'll continue with next extension */
126 width += len + 1;
127 if (ext[j] == 0) {
128 break;
129 }
130 else {
131 i++;
132 j++;
Brian Paul7ac43502000-02-23 22:50:35 +0000133 if (ext[j] == 0)
134 break;
Brian Paul76bc4402000-01-27 16:43:56 +0000135 printf(", ");
136 width += 2;
137 }
138 }
139 j++;
140 }
141 printf("\n");
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000142}
143
144
Brian Paul76bc4402000-01-27 16:43:56 +0000145static void
Brian Paul373aea12001-04-02 22:45:07 +0000146print_display_info(Display *dpy)
147{
148 printf("name of display: %s\n", DisplayString(dpy));
149}
150
151
152static void
Brian Paul2f7ef5f2002-09-06 03:35:43 +0000153print_limits(void)
154{
155 struct token_name {
156 GLuint count;
157 GLenum token;
158 const char *name;
159 };
160 static const struct token_name limits[] = {
161 { 1, GL_MAX_ATTRIB_STACK_DEPTH, "GL_MAX_ATTRIB_STACK_DEPTH" },
162 { 1, GL_MAX_CLIENT_ATTRIB_STACK_DEPTH, "GL_MAX_CLIENT_ATTRIB_STACK_DEPTH" },
163 { 1, GL_MAX_CLIP_PLANES, "GL_MAX_CLIP_PLANES" },
164 { 1, GL_MAX_COLOR_MATRIX_STACK_DEPTH, "GL_MAX_COLOR_MATRIX_STACK_DEPTH" },
Brian Paul2f7ef5f2002-09-06 03:35:43 +0000165 { 1, GL_MAX_ELEMENTS_VERTICES, "GL_MAX_ELEMENTS_VERTICES" },
166 { 1, GL_MAX_ELEMENTS_INDICES, "GL_MAX_ELEMENTS_INDICES" },
167 { 1, GL_MAX_EVAL_ORDER, "GL_MAX_EVAL_ORDER" },
168 { 1, GL_MAX_LIGHTS, "GL_MAX_LIGHTS" },
169 { 1, GL_MAX_LIST_NESTING, "GL_MAX_LIST_NESTING" },
170 { 1, GL_MAX_MODELVIEW_STACK_DEPTH, "GL_MAX_MODELVIEW_STACK_DEPTH" },
171 { 1, GL_MAX_NAME_STACK_DEPTH, "GL_MAX_NAME_STACK_DEPTH" },
172 { 1, GL_MAX_PIXEL_MAP_TABLE, "GL_MAX_PIXEL_MAP_TABLE" },
173 { 1, GL_MAX_PROJECTION_STACK_DEPTH, "GL_MAX_PROJECTION_STACK_DEPTH" },
174 { 1, GL_MAX_TEXTURE_STACK_DEPTH, "GL_MAX_TEXTURE_STACK_DEPTH" },
175 { 1, GL_MAX_TEXTURE_SIZE, "GL_MAX_TEXTURE_SIZE" },
176 { 1, GL_MAX_3D_TEXTURE_SIZE, "GL_MAX_3D_TEXTURE_SIZE" },
177 { 1, GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB, "GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB" },
178 { 1, GL_MAX_RECTANGLE_TEXTURE_SIZE_NV, "GL_MAX_RECTANGLE_TEXTURE_SIZE_NV" },
179 { 1, GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB, "GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB" },
180 { 1, GL_MAX_TEXTURE_UNITS_ARB, "GL_MAX_TEXTURE_UNITS_ARB" },
181 { 1, GL_MAX_TEXTURE_LOD_BIAS_EXT, "GL_MAX_TEXTURE_LOD_BIAS_EXT" },
182 { 1, GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, "GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT" },
183 { 2, GL_MAX_VIEWPORT_DIMS, "GL_MAX_VIEWPORT_DIMS" },
184 { 2, GL_ALIASED_LINE_WIDTH_RANGE, "GL_ALIASED_LINE_WIDTH_RANGE" },
185 { 2, GL_SMOOTH_LINE_WIDTH_RANGE, "GL_SMOOTH_LINE_WIDTH_RANGE" },
186 { 2, GL_ALIASED_POINT_SIZE_RANGE, "GL_ALIASED_POINT_SIZE_RANGE" },
187 { 2, GL_SMOOTH_POINT_SIZE_RANGE, "GL_SMOOTH_POINT_SIZE_RANGE" },
188 { 0, (GLenum) 0, NULL }
189 };
190 GLint i, max[2];
191 printf("OpenGL limits:\n");
192 for (i = 0; limits[i].count; i++) {
193 glGetIntegerv(limits[i].token, max);
194 if (glGetError() == GL_NONE) {
195 if (limits[i].count == 1)
196 printf(" %s = %d\n", limits[i].name, max[0]);
197 else /* XXX fix if we ever query something with more than 2 values */
198 printf(" %s = %d, %d\n", limits[i].name, max[0], max[1]);
199 }
200 }
201}
202
203
204static void
205print_screen_info(Display *dpy, int scrnum, Bool allowDirect, GLboolean limits)
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000206{
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000207 Window win;
Brian Paul8460cc92000-02-02 20:57:51 +0000208 int attribSingle[] = {
209 GLX_RGBA,
210 GLX_RED_SIZE, 1,
211 GLX_GREEN_SIZE, 1,
212 GLX_BLUE_SIZE, 1,
213 None };
214 int attribDouble[] = {
215 GLX_RGBA,
216 GLX_RED_SIZE, 1,
217 GLX_GREEN_SIZE, 1,
218 GLX_BLUE_SIZE, 1,
219 GLX_DOUBLEBUFFER,
220 None };
221
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000222 XSetWindowAttributes attr;
223 unsigned long mask;
224 Window root;
225 GLXContext ctx;
226 XVisualInfo *visinfo;
227 int width = 100, height = 100;
228
Brian Paul76bc4402000-01-27 16:43:56 +0000229 root = RootWindow(dpy, scrnum);
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000230
Brian Paul8460cc92000-02-02 20:57:51 +0000231 visinfo = glXChooseVisual(dpy, scrnum, attribSingle);
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000232 if (!visinfo) {
Brian Paul8460cc92000-02-02 20:57:51 +0000233 visinfo = glXChooseVisual(dpy, scrnum, attribDouble);
234 if (!visinfo) {
Brian Paul9cff5582000-05-07 18:07:23 +0000235 fprintf(stderr, "Error: couldn't find RGB GLX visual\n");
Brian Paul8460cc92000-02-02 20:57:51 +0000236 return;
237 }
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000238 }
239
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000240 attr.background_pixel = 0;
241 attr.border_pixel = 0;
Brian Paul9cff5582000-05-07 18:07:23 +0000242 attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone);
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000243 attr.event_mask = StructureNotifyMask | ExposureMask;
244 mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
Brian Paul76bc4402000-01-27 16:43:56 +0000245 win = XCreateWindow(dpy, root, 0, 0, width, height,
246 0, visinfo->depth, InputOutput,
247 visinfo->visual, mask, &attr);
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000248
Brian Paul08b3ff12001-04-24 20:57:36 +0000249 ctx = glXCreateContext( dpy, visinfo, NULL, allowDirect );
Brian Paul34fb5db2000-04-22 20:31:23 +0000250 if (!ctx) {
Brian Paul9cff5582000-05-07 18:07:23 +0000251 fprintf(stderr, "Error: glXCreateContext failed\n");
Brian Paul34fb5db2000-04-22 20:31:23 +0000252 XDestroyWindow(dpy, win);
253 return;
254 }
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000255
Brian Paul9cff5582000-05-07 18:07:23 +0000256 if (glXMakeCurrent(dpy, win, ctx)) {
Brian Paul76bc4402000-01-27 16:43:56 +0000257 const char *serverVendor = glXQueryServerString(dpy, scrnum, GLX_VENDOR);
258 const char *serverVersion = glXQueryServerString(dpy, scrnum, GLX_VERSION);
259 const char *serverExtensions = glXQueryServerString(dpy, scrnum, GLX_EXTENSIONS);
Brian Paul34fb5db2000-04-22 20:31:23 +0000260 const char *clientVendor = glXGetClientString(dpy, GLX_VENDOR);
Brian Paul76bc4402000-01-27 16:43:56 +0000261 const char *clientVersion = glXGetClientString(dpy, GLX_VERSION);
262 const char *clientExtensions = glXGetClientString(dpy, GLX_EXTENSIONS);
263 const char *glxExtensions = glXQueryExtensionsString(dpy, scrnum);
264 const char *glVendor = (const char *) glGetString(GL_VENDOR);
265 const char *glRenderer = (const char *) glGetString(GL_RENDERER);
266 const char *glVersion = (const char *) glGetString(GL_VERSION);
267 const char *glExtensions = (const char *) glGetString(GL_EXTENSIONS);
Brian Paul373aea12001-04-02 22:45:07 +0000268 char *displayName = NULL;
269 char *colon = NULL, *period = NULL;
Brian Paul39557c32001-03-23 21:41:44 +0000270#ifdef DO_GLU
Brian Paul76bc4402000-01-27 16:43:56 +0000271 const char *gluVersion = (const char *) gluGetString(GLU_VERSION);
272 const char *gluExtensions = (const char *) gluGetString(GLU_EXTENSIONS);
Brian Paul39557c32001-03-23 21:41:44 +0000273#endif
Brian Paul373aea12001-04-02 22:45:07 +0000274 /* Strip the screen number from the display name, if present. */
Brian Paulf02a5f62002-07-12 15:54:01 +0000275 if (!(displayName = (char *) malloc(strlen(DisplayString(dpy)) + 1))) {
Brian Paul373aea12001-04-02 22:45:07 +0000276 fprintf(stderr, "Error: malloc() failed\n");
277 exit(1);
278 }
279 strcpy(displayName, DisplayString(dpy));
280 colon = strrchr(displayName, ':');
281 if (colon) {
282 period = strchr(colon, '.');
283 if (period)
284 *period = '\0';
285 }
286 printf("display: %s screen: %d\n", displayName, scrnum);
287 free(displayName);
Brian Paule691ee22000-05-08 14:53:57 +0000288 printf("direct rendering: %s\n", glXIsDirect(dpy, ctx) ? "Yes" : "No");
Brian Paul76bc4402000-01-27 16:43:56 +0000289 printf("server glx vendor string: %s\n", serverVendor);
290 printf("server glx version string: %s\n", serverVersion);
291 printf("server glx extensions:\n");
292 print_extension_list(serverExtensions);
Brian Paul34fb5db2000-04-22 20:31:23 +0000293 printf("client glx vendor string: %s\n", clientVendor);
294 printf("client glx version string: %s\n", clientVersion);
Brian Paul76bc4402000-01-27 16:43:56 +0000295 printf("client glx extensions:\n");
296 print_extension_list(clientExtensions);
297 printf("GLX extensions:\n");
298 print_extension_list(glxExtensions);
299 printf("OpenGL vendor string: %s\n", glVendor);
300 printf("OpenGL renderer string: %s\n", glRenderer);
301 printf("OpenGL version string: %s\n", glVersion);
302 printf("OpenGL extensions:\n");
303 print_extension_list(glExtensions);
Brian Paul2f7ef5f2002-09-06 03:35:43 +0000304 if (limits)
305 print_limits();
Brian Paul39557c32001-03-23 21:41:44 +0000306#ifdef DO_GLU
Brian Paul76bc4402000-01-27 16:43:56 +0000307 printf("glu version: %s\n", gluVersion);
308 printf("glu extensions:\n");
309 print_extension_list(gluExtensions);
Brian Paul39557c32001-03-23 21:41:44 +0000310#endif
Brian Paul76bc4402000-01-27 16:43:56 +0000311 }
Brian Paul9cff5582000-05-07 18:07:23 +0000312 else {
313 fprintf(stderr, "Error: glXMakeCurrent failed\n");
314 }
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000315
316 glXDestroyContext(dpy, ctx);
317 XDestroyWindow(dpy, win);
Brian Paul76bc4402000-01-27 16:43:56 +0000318}
319
320
321static const char *
322visual_class_name(int cls)
323{
324 switch (cls) {
325 case StaticColor:
326 return "StaticColor";
327 case PseudoColor:
328 return "PseudoColor";
329 case StaticGray:
330 return "StaticGray";
331 case GrayScale:
332 return "GrayScale";
333 case TrueColor:
334 return "TrueColor";
335 case DirectColor:
336 return "DirectColor";
337 default:
338 return "";
339 }
340}
341
342
343static const char *
344visual_class_abbrev(int cls)
345{
346 switch (cls) {
347 case StaticColor:
348 return "sc";
349 case PseudoColor:
350 return "pc";
351 case StaticGray:
352 return "sg";
353 case GrayScale:
354 return "gs";
355 case TrueColor:
356 return "tc";
357 case DirectColor:
358 return "dc";
359 default:
360 return "";
361 }
362}
363
364
365static void
366get_visual_attribs(Display *dpy, XVisualInfo *vInfo,
367 struct visual_attribs *attribs)
368{
Brian Paul25673f02000-03-31 18:17:51 +0000369 const char *ext = glXQueryExtensionsString(dpy, vInfo->screen);
370
Brian Paula9c53fa2000-04-03 15:45:34 +0000371 memset(attribs, 0, sizeof(struct visual_attribs));
372
Brian Paul76bc4402000-01-27 16:43:56 +0000373 attribs->id = vInfo->visualid;
374#if defined(__cplusplus) || defined(c_plusplus)
375 attribs->klass = vInfo->c_class;
376#else
377 attribs->klass = vInfo->class;
378#endif
379 attribs->depth = vInfo->depth;
380 attribs->redMask = vInfo->red_mask;
381 attribs->greenMask = vInfo->green_mask;
382 attribs->blueMask = vInfo->blue_mask;
383 attribs->colormapSize = vInfo->colormap_size;
384 attribs->bitsPerRGB = vInfo->bits_per_rgb;
385
Brian Paula9c53fa2000-04-03 15:45:34 +0000386 if (glXGetConfig(dpy, vInfo, GLX_USE_GL, &attribs->supportsGL) != 0)
387 return;
Brian Paul76bc4402000-01-27 16:43:56 +0000388 glXGetConfig(dpy, vInfo, GLX_BUFFER_SIZE, &attribs->bufferSize);
389 glXGetConfig(dpy, vInfo, GLX_LEVEL, &attribs->level);
390 glXGetConfig(dpy, vInfo, GLX_RGBA, &attribs->rgba);
391 glXGetConfig(dpy, vInfo, GLX_DOUBLEBUFFER, &attribs->doubleBuffer);
392 glXGetConfig(dpy, vInfo, GLX_STEREO, &attribs->stereo);
393 glXGetConfig(dpy, vInfo, GLX_AUX_BUFFERS, &attribs->auxBuffers);
394 glXGetConfig(dpy, vInfo, GLX_RED_SIZE, &attribs->redSize);
395 glXGetConfig(dpy, vInfo, GLX_GREEN_SIZE, &attribs->greenSize);
396 glXGetConfig(dpy, vInfo, GLX_BLUE_SIZE, &attribs->blueSize);
397 glXGetConfig(dpy, vInfo, GLX_ALPHA_SIZE, &attribs->alphaSize);
398 glXGetConfig(dpy, vInfo, GLX_DEPTH_SIZE, &attribs->depthSize);
399 glXGetConfig(dpy, vInfo, GLX_STENCIL_SIZE, &attribs->stencilSize);
400 glXGetConfig(dpy, vInfo, GLX_ACCUM_RED_SIZE, &attribs->accumRedSize);
401 glXGetConfig(dpy, vInfo, GLX_ACCUM_GREEN_SIZE, &attribs->accumGreenSize);
402 glXGetConfig(dpy, vInfo, GLX_ACCUM_BLUE_SIZE, &attribs->accumBlueSize);
403 glXGetConfig(dpy, vInfo, GLX_ACCUM_ALPHA_SIZE, &attribs->accumAlphaSize);
404
Brian Paule06c7f32000-01-27 16:53:55 +0000405 /* transparent pixel value not implemented yet */
406 attribs->transparent = 0;
407
408 /* multisample tests not implemented yet */
Brian Paul76bc4402000-01-27 16:43:56 +0000409 attribs->numSamples = 0;
410 attribs->numMultisample = 0;
Brian Paul25673f02000-03-31 18:17:51 +0000411
412#if defined(GLX_EXT_visual_rating)
413 if (ext && strstr(ext, "GLX_EXT_visual_rating")) {
414 glXGetConfig(dpy, vInfo, GLX_VISUAL_CAVEAT_EXT, &attribs->visualCaveat);
415 }
416 else {
417 attribs->visualCaveat = GLX_NONE_EXT;
418 }
419#else
420 attribs->visualCaveat = 0;
421#endif
Brian Paul76bc4402000-01-27 16:43:56 +0000422}
423
424
425static void
426print_visual_attribs_verbose(const struct visual_attribs *attribs)
427{
428 printf("Visual ID: %x depth=%d class=%s\n",
429 attribs->id, attribs->depth, visual_class_name(attribs->klass));
430 printf(" bufferSize=%d level=%d renderType=%s doubleBuffer=%d stereo=%d\n",
431 attribs->bufferSize, attribs->level, attribs->rgba ? "rgba" : "ci",
432 attribs->doubleBuffer, attribs->stereo);
433 printf(" rgba: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n",
434 attribs->redSize, attribs->greenSize,
435 attribs->blueSize, attribs->alphaSize);
436 printf(" auxBuffers=%d depthSize=%d stencilSize=%d\n",
437 attribs->auxBuffers, attribs->depthSize, attribs->stencilSize);
438 printf(" accum: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n",
439 attribs->accumRedSize, attribs->accumGreenSize,
440 attribs->accumBlueSize, attribs->accumAlphaSize);
441 printf(" multiSample=%d multiSampleBuffers=%d\n",
442 attribs->numSamples, attribs->numMultisample);
Brian Paul25673f02000-03-31 18:17:51 +0000443#ifdef GLX_EXT_visual_rating
444 if (attribs->visualCaveat == GLX_NONE_EXT || attribs->visualCaveat == 0)
Brian Paula9c53fa2000-04-03 15:45:34 +0000445 printf(" visualCaveat=None\n");
Brian Paul25673f02000-03-31 18:17:51 +0000446 else if (attribs->visualCaveat == GLX_SLOW_VISUAL_EXT)
Brian Paula9c53fa2000-04-03 15:45:34 +0000447 printf(" visualCaveat=Slow\n");
Brian Paul25673f02000-03-31 18:17:51 +0000448 else if (attribs->visualCaveat == GLX_NON_CONFORMANT_VISUAL_EXT)
Brian Paula9c53fa2000-04-03 15:45:34 +0000449 printf(" visualCaveat=Nonconformant\n");
Brian Paul25673f02000-03-31 18:17:51 +0000450#endif
Brian Paula9c53fa2000-04-03 15:45:34 +0000451 printf(" %s\n", attribs->transparent ? "Transparent." : "Opaque.");
Brian Paul76bc4402000-01-27 16:43:56 +0000452}
453
454
455static void
456print_visual_attribs_short_header(void)
457{
Brian Paula9c53fa2000-04-03 15:45:34 +0000458 printf(" visual x bf lv rg d st colorbuffer ax dp st accumbuffer ms cav\n");
459 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 +0000460 printf("----------------------------------------------------------------------\n");
Brian Paul76bc4402000-01-27 16:43:56 +0000461}
462
463
464static void
465print_visual_attribs_short(const struct visual_attribs *attribs)
466{
Brian Paula3e44f42002-03-08 19:44:28 +0000467 char *caveat = NULL;
Brian Paul25673f02000-03-31 18:17:51 +0000468#ifdef GLX_EXT_visual_rating
469 if (attribs->visualCaveat == GLX_NONE_EXT || attribs->visualCaveat == 0)
470 caveat = "None";
471 else if (attribs->visualCaveat == GLX_SLOW_VISUAL_EXT)
472 caveat = "Slow";
473 else if (attribs->visualCaveat == GLX_NON_CONFORMANT_VISUAL_EXT)
474 caveat = "Ncon";
Brian Paul28bc6cb2002-09-06 03:47:34 +0000475 else
476 caveat = "None";
Brian Paul25673f02000-03-31 18:17:51 +0000477#else
478 caveat = "None";
479#endif
480
Brian Paul76bc4402000-01-27 16:43:56 +0000481 printf("0x%2x %2d %2s %2d %2d %2d %1s %2s %2s %2d %2d %2d %2d %2d %2d %2d",
482 attribs->id,
483 attribs->depth,
484 visual_class_abbrev(attribs->klass),
485 attribs->transparent,
486 attribs->bufferSize,
487 attribs->level,
488 attribs->rgba ? "r" : "c",
489 attribs->doubleBuffer ? "y" : ".",
490 attribs->stereo ? "y" : ".",
491 attribs->redSize, attribs->greenSize,
492 attribs->blueSize, attribs->alphaSize,
493 attribs->auxBuffers,
494 attribs->depthSize,
495 attribs->stencilSize
496 );
497
Brian Paul25673f02000-03-31 18:17:51 +0000498 printf(" %2d %2d %2d %2d %2d %1d %s\n",
Brian Paul76bc4402000-01-27 16:43:56 +0000499 attribs->accumRedSize, attribs->accumGreenSize,
500 attribs->accumBlueSize, attribs->accumAlphaSize,
Brian Paul25673f02000-03-31 18:17:51 +0000501 attribs->numSamples, attribs->numMultisample,
502 caveat
Brian Paul76bc4402000-01-27 16:43:56 +0000503 );
504}
505
506
507static void
508print_visual_attribs_long_header(void)
509{
510 printf("Vis Vis Visual Trans buff lev render DB ste r g b a aux dep ste accum buffers MS MS\n");
511 printf(" ID Depth Type parent size el type reo sz sz sz sz buf th ncl r g b a num bufs\n");
512 printf("----------------------------------------------------------------------------------------------------\n");
513}
514
515
516static void
517print_visual_attribs_long(const struct visual_attribs *attribs)
518{
519 printf("0x%2x %2d %-11s %2d %2d %2d %4s %3d %3d %3d %3d %3d %3d",
520 attribs->id,
521 attribs->depth,
522 visual_class_name(attribs->klass),
523 attribs->transparent,
524 attribs->bufferSize,
525 attribs->level,
526 attribs->rgba ? "rgba" : "ci ",
527 attribs->doubleBuffer,
528 attribs->stereo,
529 attribs->redSize, attribs->greenSize,
530 attribs->blueSize, attribs->alphaSize
531 );
532
533 printf(" %3d %4d %2d %3d %3d %3d %3d %2d %2d\n",
534 attribs->auxBuffers,
535 attribs->depthSize,
536 attribs->stencilSize,
537 attribs->accumRedSize, attribs->accumGreenSize,
538 attribs->accumBlueSize, attribs->accumAlphaSize,
539 attribs->numSamples, attribs->numMultisample
540 );
541}
542
543
544static void
545print_visual_info(Display *dpy, int scrnum, InfoMode mode)
546{
Brian Paulf02a5f62002-07-12 15:54:01 +0000547 XVisualInfo theTemplate;
Brian Paul76bc4402000-01-27 16:43:56 +0000548 XVisualInfo *visuals;
549 int numVisuals;
550 long mask;
551 int i;
552
553 /* get list of all visuals on this screen */
Brian Paulf02a5f62002-07-12 15:54:01 +0000554 theTemplate.screen = scrnum;
Brian Paul76bc4402000-01-27 16:43:56 +0000555 mask = VisualScreenMask;
Brian Paulf02a5f62002-07-12 15:54:01 +0000556 visuals = XGetVisualInfo(dpy, mask, &theTemplate, &numVisuals);
Brian Paul76bc4402000-01-27 16:43:56 +0000557
558 if (mode == Verbose) {
559 for (i = 0; i < numVisuals; i++) {
560 struct visual_attribs attribs;
561 get_visual_attribs(dpy, &visuals[i], &attribs);
562 print_visual_attribs_verbose(&attribs);
563 }
564 }
565 else if (mode == Normal) {
566 print_visual_attribs_short_header();
567 for (i = 0; i < numVisuals; i++) {
568 struct visual_attribs attribs;
569 get_visual_attribs(dpy, &visuals[i], &attribs);
570 print_visual_attribs_short(&attribs);
571 }
572 }
573 else if (mode == Wide) {
574 print_visual_attribs_long_header();
575 for (i = 0; i < numVisuals; i++) {
576 struct visual_attribs attribs;
577 get_visual_attribs(dpy, &visuals[i], &attribs);
578 print_visual_attribs_long(&attribs);
579 }
580 }
581
582 XFree(visuals);
583}
584
585
Brian Paul39557c32001-03-23 21:41:44 +0000586/*
587 * Stand-alone Mesa doesn't really implement the GLX protocol so it
588 * doesn't really know the GLX attributes associated with an X visual.
589 * The first time a visual is presented to Mesa's pseudo-GLX it
590 * attaches ancilliary buffers to it (like depth and stencil).
591 * But that usually only works if glXChooseVisual is used.
592 * This function calls glXChooseVisual() to sort of "prime the pump"
593 * for Mesa's GLX so that the visuals that get reported actually
594 * reflect what applications will see.
595 * This has no effect when using true GLX.
596 */
597static void
598mesa_hack(Display *dpy, int scrnum)
599{
600 static int attribs[] = {
601 GLX_RGBA,
602 GLX_RED_SIZE, 1,
603 GLX_GREEN_SIZE, 1,
604 GLX_BLUE_SIZE, 1,
605 GLX_DEPTH_SIZE, 1,
606 GLX_STENCIL_SIZE, 1,
607 GLX_ACCUM_RED_SIZE, 1,
608 GLX_ACCUM_GREEN_SIZE, 1,
609 GLX_ACCUM_BLUE_SIZE, 1,
610 GLX_ACCUM_ALPHA_SIZE, 1,
611 GLX_DOUBLEBUFFER,
612 None
613 };
614 XVisualInfo *visinfo;
615
616 visinfo = glXChooseVisual(dpy, scrnum, attribs);
617 if (visinfo)
618 XFree(visinfo);
619}
620
621
622/*
623 * Examine all visuals to find the so-called best one.
624 * We prefer deepest RGBA buffer with depth, stencil and accum
625 * that has no caveats.
626 */
627static int
628find_best_visual(Display *dpy, int scrnum)
629{
Brian Paulf02a5f62002-07-12 15:54:01 +0000630 XVisualInfo theTemplate;
Brian Paul39557c32001-03-23 21:41:44 +0000631 XVisualInfo *visuals;
632 int numVisuals;
633 long mask;
634 int i;
635 struct visual_attribs bestVis;
636
637 /* get list of all visuals on this screen */
Brian Paulf02a5f62002-07-12 15:54:01 +0000638 theTemplate.screen = scrnum;
Brian Paul39557c32001-03-23 21:41:44 +0000639 mask = VisualScreenMask;
Brian Paulf02a5f62002-07-12 15:54:01 +0000640 visuals = XGetVisualInfo(dpy, mask, &theTemplate, &numVisuals);
Brian Paul39557c32001-03-23 21:41:44 +0000641
642 /* init bestVis with first visual info */
643 get_visual_attribs(dpy, &visuals[0], &bestVis);
644
645 /* try to find a "better" visual */
646 for (i = 1; i < numVisuals; i++) {
647 struct visual_attribs vis;
648
649 get_visual_attribs(dpy, &visuals[i], &vis);
650
651 /* always skip visuals with caveats */
652 if (vis.visualCaveat != GLX_NONE_EXT)
653 continue;
654
655 /* see if this vis is better than bestVis */
656 if ((!bestVis.supportsGL && vis.supportsGL) ||
657 (bestVis.visualCaveat != GLX_NONE_EXT) ||
658 (!bestVis.rgba && vis.rgba) ||
659 (!bestVis.doubleBuffer && vis.doubleBuffer) ||
660 (bestVis.redSize < vis.redSize) ||
661 (bestVis.greenSize < vis.greenSize) ||
662 (bestVis.blueSize < vis.blueSize) ||
663 (bestVis.alphaSize < vis.alphaSize) ||
664 (bestVis.depthSize < vis.depthSize) ||
665 (bestVis.stencilSize < vis.stencilSize) ||
666 (bestVis.accumRedSize < vis.accumRedSize)) {
667 /* found a better visual */
668 bestVis = vis;
669 }
670 }
671
672 XFree(visuals);
673
674 return bestVis.id;
675}
676
677
Brian Paul08b3ff12001-04-24 20:57:36 +0000678static void
679usage(void)
680{
681 printf("Usage: glxinfo [-v] [-t] [-h] [-i] [-b] [-display <dname>]\n");
682 printf("\t-v: Print visuals info in verbose form.\n");
683 printf("\t-t: Print verbose table.\n");
684 printf("\t-display <dname>: Print GLX visuals on specified server.\n");
685 printf("\t-h: This information.\n");
686 printf("\t-i: Force an indirect rendering context.\n");
687 printf("\t-b: Find the 'best' visual and print it's number.\n");
Brian Paul2f7ef5f2002-09-06 03:35:43 +0000688 printf("\t-l: Print interesting OpenGLl imits.\n");
Brian Paul08b3ff12001-04-24 20:57:36 +0000689}
690
691
Brian Paul76bc4402000-01-27 16:43:56 +0000692int
693main(int argc, char *argv[])
694{
Alan Hourihanee18599a2001-03-19 13:58:45 +0000695 char *displayName = NULL;
Brian Paul76bc4402000-01-27 16:43:56 +0000696 Display *dpy;
697 int numScreens, scrnum;
698 InfoMode mode = Normal;
Brian Paul39557c32001-03-23 21:41:44 +0000699 GLboolean findBest = GL_FALSE;
Brian Paul2f7ef5f2002-09-06 03:35:43 +0000700 GLboolean limits = GL_FALSE;
Brian Paul08b3ff12001-04-24 20:57:36 +0000701 Bool allowDirect = True;
Brian Paul76bc4402000-01-27 16:43:56 +0000702 int i;
703
704 for (i = 1; i < argc; i++) {
705 if (strcmp(argv[i], "-display") == 0 && i + 1 < argc) {
706 displayName = argv[i + 1];
707 i++;
708 }
709 else if (strcmp(argv[i], "-t") == 0) {
710 mode = Wide;
711 }
712 else if (strcmp(argv[i], "-v") == 0) {
713 mode = Verbose;
714 }
Brian Paul39557c32001-03-23 21:41:44 +0000715 else if (strcmp(argv[i], "-b") == 0) {
716 findBest = GL_TRUE;
717 }
Brian Paul08b3ff12001-04-24 20:57:36 +0000718 else if (strcmp(argv[i], "-i") == 0) {
719 allowDirect = False;
720 }
Brian Paul2f7ef5f2002-09-06 03:35:43 +0000721 else if (strcmp(argv[i], "-l") == 0) {
722 limits = GL_TRUE;
723 }
Brian Paul08b3ff12001-04-24 20:57:36 +0000724 else if (strcmp(argv[i], "-h") == 0) {
725 usage();
726 return 0;
727 }
728 else {
729 printf("Unknown option `%s'\n", argv[i]);
730 usage();
731 return 0;
732 }
Brian Paul76bc4402000-01-27 16:43:56 +0000733 }
734
735 dpy = XOpenDisplay(displayName);
736 if (!dpy) {
737 fprintf(stderr, "Error: unable to open display %s\n", displayName);
738 return -1;
739 }
740
Brian Paul39557c32001-03-23 21:41:44 +0000741 if (findBest) {
742 int b;
743 mesa_hack(dpy, 0);
744 b = find_best_visual(dpy, 0);
745 printf("%d\n", b);
746 }
747 else {
748 numScreens = ScreenCount(dpy);
Brian Paul373aea12001-04-02 22:45:07 +0000749 print_display_info(dpy);
Brian Paul39557c32001-03-23 21:41:44 +0000750 for (scrnum = 0; scrnum < numScreens; scrnum++) {
751 mesa_hack(dpy, scrnum);
Brian Paul2f7ef5f2002-09-06 03:35:43 +0000752 print_screen_info(dpy, scrnum, allowDirect, limits);
Brian Paul39557c32001-03-23 21:41:44 +0000753 printf("\n");
754 print_visual_info(dpy, scrnum, mode);
755 if (scrnum + 1 < numScreens)
756 printf("\n\n");
757 }
Brian Paul76bc4402000-01-27 16:43:56 +0000758 }
759
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000760 XCloseDisplay(dpy);
761
762 return 0;
763}