Brian Paul | 28bc6cb | 2002-09-06 03:47:34 +0000 | [diff] [blame^] | 1 | /* $Id: glxinfo.c,v 1.18 2002/09/06 03:47:34 brianp Exp $ */ |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 2 | |
| 3 | /* |
Brian Paul | 2f7ef5f | 2002-09-06 03:35:43 +0000 | [diff] [blame] | 4 | * Copyright (C) 1999-2002 Brian Paul All Rights Reserved. |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 5 | * |
| 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 Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 22 | */ |
| 23 | |
| 24 | |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 25 | /* |
| 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 Paul | 39557c3 | 2001-03-23 21:41:44 +0000 | [diff] [blame] | 31 | * -b only print ID of "best" visual on screen 0 |
Brian Paul | 28bc6cb | 2002-09-06 03:47:34 +0000 | [diff] [blame^] | 32 | * -i use indirect rendering connection only |
Brian Paul | 2f7ef5f | 2002-09-06 03:35:43 +0000 | [diff] [blame] | 33 | * -l print interesting OpenGL limits (added 5 Sep 2002) |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 34 | * |
| 35 | * Brian Paul 26 January 2000 |
| 36 | */ |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 37 | |
Brian Paul | 39557c3 | 2001-03-23 21:41:44 +0000 | [diff] [blame] | 38 | #define DO_GLU /* may want to remove this for easier XFree86 building? */ |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 39 | |
| 40 | #include <X11/Xlib.h> |
| 41 | #include <X11/Xutil.h> |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 42 | #include <GL/gl.h> |
Brian Paul | 39557c3 | 2001-03-23 21:41:44 +0000 | [diff] [blame] | 43 | #ifdef DO_GLU |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 44 | #include <GL/glu.h> |
Brian Paul | 39557c3 | 2001-03-23 21:41:44 +0000 | [diff] [blame] | 45 | #endif |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 46 | #include <GL/glx.h> |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 47 | #include <stdio.h> |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 48 | #include <string.h> |
Brian Paul | 373aea1 | 2001-04-02 22:45:07 +0000 | [diff] [blame] | 49 | #include <stdlib.h> |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 50 | |
| 51 | |
Brian Paul | 39557c3 | 2001-03-23 21:41:44 +0000 | [diff] [blame] | 52 | #ifndef GLX_NONE_EXT |
| 53 | #define GLX_NONE_EXT 0x8000 |
| 54 | #endif |
| 55 | |
| 56 | |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 57 | typedef enum |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 58 | { |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 59 | Normal, |
| 60 | Wide, |
| 61 | Verbose |
| 62 | } InfoMode; |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 63 | |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 64 | |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 65 | struct 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 Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 74 | |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 75 | /* 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 Paul | 25673f0 | 2000-03-31 18:17:51 +0000 | [diff] [blame] | 89 | int visualCaveat; |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | |
| 93 | /* |
| 94 | * Print a list of extensions, with word-wrapping. |
| 95 | */ |
| 96 | static void |
| 97 | print_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 Paul | 7ac4350 | 2000-02-23 22:50:35 +0000 | [diff] [blame] | 133 | if (ext[j] == 0) |
| 134 | break; |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 135 | printf(", "); |
| 136 | width += 2; |
| 137 | } |
| 138 | } |
| 139 | j++; |
| 140 | } |
| 141 | printf("\n"); |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 145 | static void |
Brian Paul | 373aea1 | 2001-04-02 22:45:07 +0000 | [diff] [blame] | 146 | print_display_info(Display *dpy) |
| 147 | { |
| 148 | printf("name of display: %s\n", DisplayString(dpy)); |
| 149 | } |
| 150 | |
| 151 | |
| 152 | static void |
Brian Paul | 2f7ef5f | 2002-09-06 03:35:43 +0000 | [diff] [blame] | 153 | print_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" }, |
| 165 | { 1, GL_MAX_CONVOLUTION_WIDTH_EXT, "GL_MAX_CONVOLUTION_WIDTH_EXT" }, |
| 166 | { 1, GL_MAX_CONVOLUTION_HEIGHT_EXT, "GL_MAX_CONVOLUTION_HEIGHT_EXT" }, |
| 167 | { 1, GL_MAX_ELEMENTS_VERTICES, "GL_MAX_ELEMENTS_VERTICES" }, |
| 168 | { 1, GL_MAX_ELEMENTS_INDICES, "GL_MAX_ELEMENTS_INDICES" }, |
| 169 | { 1, GL_MAX_EVAL_ORDER, "GL_MAX_EVAL_ORDER" }, |
| 170 | { 1, GL_MAX_LIGHTS, "GL_MAX_LIGHTS" }, |
| 171 | { 1, GL_MAX_LIST_NESTING, "GL_MAX_LIST_NESTING" }, |
| 172 | { 1, GL_MAX_MODELVIEW_STACK_DEPTH, "GL_MAX_MODELVIEW_STACK_DEPTH" }, |
| 173 | { 1, GL_MAX_NAME_STACK_DEPTH, "GL_MAX_NAME_STACK_DEPTH" }, |
| 174 | { 1, GL_MAX_PIXEL_MAP_TABLE, "GL_MAX_PIXEL_MAP_TABLE" }, |
| 175 | { 1, GL_MAX_PROJECTION_STACK_DEPTH, "GL_MAX_PROJECTION_STACK_DEPTH" }, |
| 176 | { 1, GL_MAX_TEXTURE_STACK_DEPTH, "GL_MAX_TEXTURE_STACK_DEPTH" }, |
| 177 | { 1, GL_MAX_TEXTURE_SIZE, "GL_MAX_TEXTURE_SIZE" }, |
| 178 | { 1, GL_MAX_3D_TEXTURE_SIZE, "GL_MAX_3D_TEXTURE_SIZE" }, |
| 179 | { 1, GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB, "GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB" }, |
| 180 | { 1, GL_MAX_RECTANGLE_TEXTURE_SIZE_NV, "GL_MAX_RECTANGLE_TEXTURE_SIZE_NV" }, |
| 181 | { 1, GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB, "GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB" }, |
| 182 | { 1, GL_MAX_TEXTURE_UNITS_ARB, "GL_MAX_TEXTURE_UNITS_ARB" }, |
| 183 | { 1, GL_MAX_TEXTURE_LOD_BIAS_EXT, "GL_MAX_TEXTURE_LOD_BIAS_EXT" }, |
| 184 | { 1, GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, "GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT" }, |
| 185 | { 2, GL_MAX_VIEWPORT_DIMS, "GL_MAX_VIEWPORT_DIMS" }, |
| 186 | { 2, GL_ALIASED_LINE_WIDTH_RANGE, "GL_ALIASED_LINE_WIDTH_RANGE" }, |
| 187 | { 2, GL_SMOOTH_LINE_WIDTH_RANGE, "GL_SMOOTH_LINE_WIDTH_RANGE" }, |
| 188 | { 2, GL_ALIASED_POINT_SIZE_RANGE, "GL_ALIASED_POINT_SIZE_RANGE" }, |
| 189 | { 2, GL_SMOOTH_POINT_SIZE_RANGE, "GL_SMOOTH_POINT_SIZE_RANGE" }, |
| 190 | { 0, (GLenum) 0, NULL } |
| 191 | }; |
| 192 | GLint i, max[2]; |
| 193 | printf("OpenGL limits:\n"); |
| 194 | for (i = 0; limits[i].count; i++) { |
| 195 | glGetIntegerv(limits[i].token, max); |
| 196 | if (glGetError() == GL_NONE) { |
| 197 | if (limits[i].count == 1) |
| 198 | printf(" %s = %d\n", limits[i].name, max[0]); |
| 199 | else /* XXX fix if we ever query something with more than 2 values */ |
| 200 | printf(" %s = %d, %d\n", limits[i].name, max[0], max[1]); |
| 201 | } |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | |
| 206 | static void |
| 207 | print_screen_info(Display *dpy, int scrnum, Bool allowDirect, GLboolean limits) |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 208 | { |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 209 | Window win; |
Brian Paul | 8460cc9 | 2000-02-02 20:57:51 +0000 | [diff] [blame] | 210 | int attribSingle[] = { |
| 211 | GLX_RGBA, |
| 212 | GLX_RED_SIZE, 1, |
| 213 | GLX_GREEN_SIZE, 1, |
| 214 | GLX_BLUE_SIZE, 1, |
| 215 | None }; |
| 216 | int attribDouble[] = { |
| 217 | GLX_RGBA, |
| 218 | GLX_RED_SIZE, 1, |
| 219 | GLX_GREEN_SIZE, 1, |
| 220 | GLX_BLUE_SIZE, 1, |
| 221 | GLX_DOUBLEBUFFER, |
| 222 | None }; |
| 223 | |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 224 | XSetWindowAttributes attr; |
| 225 | unsigned long mask; |
| 226 | Window root; |
| 227 | GLXContext ctx; |
| 228 | XVisualInfo *visinfo; |
| 229 | int width = 100, height = 100; |
| 230 | |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 231 | root = RootWindow(dpy, scrnum); |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 232 | |
Brian Paul | 8460cc9 | 2000-02-02 20:57:51 +0000 | [diff] [blame] | 233 | visinfo = glXChooseVisual(dpy, scrnum, attribSingle); |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 234 | if (!visinfo) { |
Brian Paul | 8460cc9 | 2000-02-02 20:57:51 +0000 | [diff] [blame] | 235 | visinfo = glXChooseVisual(dpy, scrnum, attribDouble); |
| 236 | if (!visinfo) { |
Brian Paul | 9cff558 | 2000-05-07 18:07:23 +0000 | [diff] [blame] | 237 | fprintf(stderr, "Error: couldn't find RGB GLX visual\n"); |
Brian Paul | 8460cc9 | 2000-02-02 20:57:51 +0000 | [diff] [blame] | 238 | return; |
| 239 | } |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 240 | } |
| 241 | |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 242 | attr.background_pixel = 0; |
| 243 | attr.border_pixel = 0; |
Brian Paul | 9cff558 | 2000-05-07 18:07:23 +0000 | [diff] [blame] | 244 | attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone); |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 245 | attr.event_mask = StructureNotifyMask | ExposureMask; |
| 246 | mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 247 | win = XCreateWindow(dpy, root, 0, 0, width, height, |
| 248 | 0, visinfo->depth, InputOutput, |
| 249 | visinfo->visual, mask, &attr); |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 250 | |
Brian Paul | 08b3ff1 | 2001-04-24 20:57:36 +0000 | [diff] [blame] | 251 | ctx = glXCreateContext( dpy, visinfo, NULL, allowDirect ); |
Brian Paul | 34fb5db | 2000-04-22 20:31:23 +0000 | [diff] [blame] | 252 | if (!ctx) { |
Brian Paul | 9cff558 | 2000-05-07 18:07:23 +0000 | [diff] [blame] | 253 | fprintf(stderr, "Error: glXCreateContext failed\n"); |
Brian Paul | 34fb5db | 2000-04-22 20:31:23 +0000 | [diff] [blame] | 254 | XDestroyWindow(dpy, win); |
| 255 | return; |
| 256 | } |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 257 | |
Brian Paul | 9cff558 | 2000-05-07 18:07:23 +0000 | [diff] [blame] | 258 | if (glXMakeCurrent(dpy, win, ctx)) { |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 259 | const char *serverVendor = glXQueryServerString(dpy, scrnum, GLX_VENDOR); |
| 260 | const char *serverVersion = glXQueryServerString(dpy, scrnum, GLX_VERSION); |
| 261 | const char *serverExtensions = glXQueryServerString(dpy, scrnum, GLX_EXTENSIONS); |
Brian Paul | 34fb5db | 2000-04-22 20:31:23 +0000 | [diff] [blame] | 262 | const char *clientVendor = glXGetClientString(dpy, GLX_VENDOR); |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 263 | const char *clientVersion = glXGetClientString(dpy, GLX_VERSION); |
| 264 | const char *clientExtensions = glXGetClientString(dpy, GLX_EXTENSIONS); |
| 265 | const char *glxExtensions = glXQueryExtensionsString(dpy, scrnum); |
| 266 | const char *glVendor = (const char *) glGetString(GL_VENDOR); |
| 267 | const char *glRenderer = (const char *) glGetString(GL_RENDERER); |
| 268 | const char *glVersion = (const char *) glGetString(GL_VERSION); |
| 269 | const char *glExtensions = (const char *) glGetString(GL_EXTENSIONS); |
Brian Paul | 373aea1 | 2001-04-02 22:45:07 +0000 | [diff] [blame] | 270 | char *displayName = NULL; |
| 271 | char *colon = NULL, *period = NULL; |
Brian Paul | 39557c3 | 2001-03-23 21:41:44 +0000 | [diff] [blame] | 272 | #ifdef DO_GLU |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 273 | const char *gluVersion = (const char *) gluGetString(GLU_VERSION); |
| 274 | const char *gluExtensions = (const char *) gluGetString(GLU_EXTENSIONS); |
Brian Paul | 39557c3 | 2001-03-23 21:41:44 +0000 | [diff] [blame] | 275 | #endif |
Brian Paul | 373aea1 | 2001-04-02 22:45:07 +0000 | [diff] [blame] | 276 | /* Strip the screen number from the display name, if present. */ |
Brian Paul | f02a5f6 | 2002-07-12 15:54:01 +0000 | [diff] [blame] | 277 | if (!(displayName = (char *) malloc(strlen(DisplayString(dpy)) + 1))) { |
Brian Paul | 373aea1 | 2001-04-02 22:45:07 +0000 | [diff] [blame] | 278 | fprintf(stderr, "Error: malloc() failed\n"); |
| 279 | exit(1); |
| 280 | } |
| 281 | strcpy(displayName, DisplayString(dpy)); |
| 282 | colon = strrchr(displayName, ':'); |
| 283 | if (colon) { |
| 284 | period = strchr(colon, '.'); |
| 285 | if (period) |
| 286 | *period = '\0'; |
| 287 | } |
| 288 | printf("display: %s screen: %d\n", displayName, scrnum); |
| 289 | free(displayName); |
Brian Paul | e691ee2 | 2000-05-08 14:53:57 +0000 | [diff] [blame] | 290 | printf("direct rendering: %s\n", glXIsDirect(dpy, ctx) ? "Yes" : "No"); |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 291 | printf("server glx vendor string: %s\n", serverVendor); |
| 292 | printf("server glx version string: %s\n", serverVersion); |
| 293 | printf("server glx extensions:\n"); |
| 294 | print_extension_list(serverExtensions); |
Brian Paul | 34fb5db | 2000-04-22 20:31:23 +0000 | [diff] [blame] | 295 | printf("client glx vendor string: %s\n", clientVendor); |
| 296 | printf("client glx version string: %s\n", clientVersion); |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 297 | printf("client glx extensions:\n"); |
| 298 | print_extension_list(clientExtensions); |
| 299 | printf("GLX extensions:\n"); |
| 300 | print_extension_list(glxExtensions); |
| 301 | printf("OpenGL vendor string: %s\n", glVendor); |
| 302 | printf("OpenGL renderer string: %s\n", glRenderer); |
| 303 | printf("OpenGL version string: %s\n", glVersion); |
| 304 | printf("OpenGL extensions:\n"); |
| 305 | print_extension_list(glExtensions); |
Brian Paul | 2f7ef5f | 2002-09-06 03:35:43 +0000 | [diff] [blame] | 306 | if (limits) |
| 307 | print_limits(); |
Brian Paul | 39557c3 | 2001-03-23 21:41:44 +0000 | [diff] [blame] | 308 | #ifdef DO_GLU |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 309 | printf("glu version: %s\n", gluVersion); |
| 310 | printf("glu extensions:\n"); |
| 311 | print_extension_list(gluExtensions); |
Brian Paul | 39557c3 | 2001-03-23 21:41:44 +0000 | [diff] [blame] | 312 | #endif |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 313 | } |
Brian Paul | 9cff558 | 2000-05-07 18:07:23 +0000 | [diff] [blame] | 314 | else { |
| 315 | fprintf(stderr, "Error: glXMakeCurrent failed\n"); |
| 316 | } |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 317 | |
| 318 | glXDestroyContext(dpy, ctx); |
| 319 | XDestroyWindow(dpy, win); |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | |
| 323 | static const char * |
| 324 | visual_class_name(int cls) |
| 325 | { |
| 326 | switch (cls) { |
| 327 | case StaticColor: |
| 328 | return "StaticColor"; |
| 329 | case PseudoColor: |
| 330 | return "PseudoColor"; |
| 331 | case StaticGray: |
| 332 | return "StaticGray"; |
| 333 | case GrayScale: |
| 334 | return "GrayScale"; |
| 335 | case TrueColor: |
| 336 | return "TrueColor"; |
| 337 | case DirectColor: |
| 338 | return "DirectColor"; |
| 339 | default: |
| 340 | return ""; |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | |
| 345 | static const char * |
| 346 | visual_class_abbrev(int cls) |
| 347 | { |
| 348 | switch (cls) { |
| 349 | case StaticColor: |
| 350 | return "sc"; |
| 351 | case PseudoColor: |
| 352 | return "pc"; |
| 353 | case StaticGray: |
| 354 | return "sg"; |
| 355 | case GrayScale: |
| 356 | return "gs"; |
| 357 | case TrueColor: |
| 358 | return "tc"; |
| 359 | case DirectColor: |
| 360 | return "dc"; |
| 361 | default: |
| 362 | return ""; |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | |
| 367 | static void |
| 368 | get_visual_attribs(Display *dpy, XVisualInfo *vInfo, |
| 369 | struct visual_attribs *attribs) |
| 370 | { |
Brian Paul | 25673f0 | 2000-03-31 18:17:51 +0000 | [diff] [blame] | 371 | const char *ext = glXQueryExtensionsString(dpy, vInfo->screen); |
| 372 | |
Brian Paul | a9c53fa | 2000-04-03 15:45:34 +0000 | [diff] [blame] | 373 | memset(attribs, 0, sizeof(struct visual_attribs)); |
| 374 | |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 375 | attribs->id = vInfo->visualid; |
| 376 | #if defined(__cplusplus) || defined(c_plusplus) |
| 377 | attribs->klass = vInfo->c_class; |
| 378 | #else |
| 379 | attribs->klass = vInfo->class; |
| 380 | #endif |
| 381 | attribs->depth = vInfo->depth; |
| 382 | attribs->redMask = vInfo->red_mask; |
| 383 | attribs->greenMask = vInfo->green_mask; |
| 384 | attribs->blueMask = vInfo->blue_mask; |
| 385 | attribs->colormapSize = vInfo->colormap_size; |
| 386 | attribs->bitsPerRGB = vInfo->bits_per_rgb; |
| 387 | |
Brian Paul | a9c53fa | 2000-04-03 15:45:34 +0000 | [diff] [blame] | 388 | if (glXGetConfig(dpy, vInfo, GLX_USE_GL, &attribs->supportsGL) != 0) |
| 389 | return; |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 390 | glXGetConfig(dpy, vInfo, GLX_BUFFER_SIZE, &attribs->bufferSize); |
| 391 | glXGetConfig(dpy, vInfo, GLX_LEVEL, &attribs->level); |
| 392 | glXGetConfig(dpy, vInfo, GLX_RGBA, &attribs->rgba); |
| 393 | glXGetConfig(dpy, vInfo, GLX_DOUBLEBUFFER, &attribs->doubleBuffer); |
| 394 | glXGetConfig(dpy, vInfo, GLX_STEREO, &attribs->stereo); |
| 395 | glXGetConfig(dpy, vInfo, GLX_AUX_BUFFERS, &attribs->auxBuffers); |
| 396 | glXGetConfig(dpy, vInfo, GLX_RED_SIZE, &attribs->redSize); |
| 397 | glXGetConfig(dpy, vInfo, GLX_GREEN_SIZE, &attribs->greenSize); |
| 398 | glXGetConfig(dpy, vInfo, GLX_BLUE_SIZE, &attribs->blueSize); |
| 399 | glXGetConfig(dpy, vInfo, GLX_ALPHA_SIZE, &attribs->alphaSize); |
| 400 | glXGetConfig(dpy, vInfo, GLX_DEPTH_SIZE, &attribs->depthSize); |
| 401 | glXGetConfig(dpy, vInfo, GLX_STENCIL_SIZE, &attribs->stencilSize); |
| 402 | glXGetConfig(dpy, vInfo, GLX_ACCUM_RED_SIZE, &attribs->accumRedSize); |
| 403 | glXGetConfig(dpy, vInfo, GLX_ACCUM_GREEN_SIZE, &attribs->accumGreenSize); |
| 404 | glXGetConfig(dpy, vInfo, GLX_ACCUM_BLUE_SIZE, &attribs->accumBlueSize); |
| 405 | glXGetConfig(dpy, vInfo, GLX_ACCUM_ALPHA_SIZE, &attribs->accumAlphaSize); |
| 406 | |
Brian Paul | e06c7f3 | 2000-01-27 16:53:55 +0000 | [diff] [blame] | 407 | /* transparent pixel value not implemented yet */ |
| 408 | attribs->transparent = 0; |
| 409 | |
| 410 | /* multisample tests not implemented yet */ |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 411 | attribs->numSamples = 0; |
| 412 | attribs->numMultisample = 0; |
Brian Paul | 25673f0 | 2000-03-31 18:17:51 +0000 | [diff] [blame] | 413 | |
| 414 | #if defined(GLX_EXT_visual_rating) |
| 415 | if (ext && strstr(ext, "GLX_EXT_visual_rating")) { |
| 416 | glXGetConfig(dpy, vInfo, GLX_VISUAL_CAVEAT_EXT, &attribs->visualCaveat); |
| 417 | } |
| 418 | else { |
| 419 | attribs->visualCaveat = GLX_NONE_EXT; |
| 420 | } |
| 421 | #else |
| 422 | attribs->visualCaveat = 0; |
| 423 | #endif |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | |
| 427 | static void |
| 428 | print_visual_attribs_verbose(const struct visual_attribs *attribs) |
| 429 | { |
| 430 | printf("Visual ID: %x depth=%d class=%s\n", |
| 431 | attribs->id, attribs->depth, visual_class_name(attribs->klass)); |
| 432 | printf(" bufferSize=%d level=%d renderType=%s doubleBuffer=%d stereo=%d\n", |
| 433 | attribs->bufferSize, attribs->level, attribs->rgba ? "rgba" : "ci", |
| 434 | attribs->doubleBuffer, attribs->stereo); |
| 435 | printf(" rgba: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n", |
| 436 | attribs->redSize, attribs->greenSize, |
| 437 | attribs->blueSize, attribs->alphaSize); |
| 438 | printf(" auxBuffers=%d depthSize=%d stencilSize=%d\n", |
| 439 | attribs->auxBuffers, attribs->depthSize, attribs->stencilSize); |
| 440 | printf(" accum: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n", |
| 441 | attribs->accumRedSize, attribs->accumGreenSize, |
| 442 | attribs->accumBlueSize, attribs->accumAlphaSize); |
| 443 | printf(" multiSample=%d multiSampleBuffers=%d\n", |
| 444 | attribs->numSamples, attribs->numMultisample); |
Brian Paul | 25673f0 | 2000-03-31 18:17:51 +0000 | [diff] [blame] | 445 | #ifdef GLX_EXT_visual_rating |
| 446 | if (attribs->visualCaveat == GLX_NONE_EXT || attribs->visualCaveat == 0) |
Brian Paul | a9c53fa | 2000-04-03 15:45:34 +0000 | [diff] [blame] | 447 | printf(" visualCaveat=None\n"); |
Brian Paul | 25673f0 | 2000-03-31 18:17:51 +0000 | [diff] [blame] | 448 | else if (attribs->visualCaveat == GLX_SLOW_VISUAL_EXT) |
Brian Paul | a9c53fa | 2000-04-03 15:45:34 +0000 | [diff] [blame] | 449 | printf(" visualCaveat=Slow\n"); |
Brian Paul | 25673f0 | 2000-03-31 18:17:51 +0000 | [diff] [blame] | 450 | else if (attribs->visualCaveat == GLX_NON_CONFORMANT_VISUAL_EXT) |
Brian Paul | a9c53fa | 2000-04-03 15:45:34 +0000 | [diff] [blame] | 451 | printf(" visualCaveat=Nonconformant\n"); |
Brian Paul | 25673f0 | 2000-03-31 18:17:51 +0000 | [diff] [blame] | 452 | #endif |
Brian Paul | a9c53fa | 2000-04-03 15:45:34 +0000 | [diff] [blame] | 453 | printf(" %s\n", attribs->transparent ? "Transparent." : "Opaque."); |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | |
| 457 | static void |
| 458 | print_visual_attribs_short_header(void) |
| 459 | { |
Brian Paul | a9c53fa | 2000-04-03 15:45:34 +0000 | [diff] [blame] | 460 | printf(" visual x bf lv rg d st colorbuffer ax dp st accumbuffer ms cav\n"); |
| 461 | 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 Paul | 25673f0 | 2000-03-31 18:17:51 +0000 | [diff] [blame] | 462 | printf("----------------------------------------------------------------------\n"); |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | |
| 466 | static void |
| 467 | print_visual_attribs_short(const struct visual_attribs *attribs) |
| 468 | { |
Brian Paul | a3e44f4 | 2002-03-08 19:44:28 +0000 | [diff] [blame] | 469 | char *caveat = NULL; |
Brian Paul | 25673f0 | 2000-03-31 18:17:51 +0000 | [diff] [blame] | 470 | #ifdef GLX_EXT_visual_rating |
| 471 | if (attribs->visualCaveat == GLX_NONE_EXT || attribs->visualCaveat == 0) |
| 472 | caveat = "None"; |
| 473 | else if (attribs->visualCaveat == GLX_SLOW_VISUAL_EXT) |
| 474 | caveat = "Slow"; |
| 475 | else if (attribs->visualCaveat == GLX_NON_CONFORMANT_VISUAL_EXT) |
| 476 | caveat = "Ncon"; |
Brian Paul | 28bc6cb | 2002-09-06 03:47:34 +0000 | [diff] [blame^] | 477 | else |
| 478 | caveat = "None"; |
Brian Paul | 25673f0 | 2000-03-31 18:17:51 +0000 | [diff] [blame] | 479 | #else |
| 480 | caveat = "None"; |
| 481 | #endif |
| 482 | |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 483 | printf("0x%2x %2d %2s %2d %2d %2d %1s %2s %2s %2d %2d %2d %2d %2d %2d %2d", |
| 484 | attribs->id, |
| 485 | attribs->depth, |
| 486 | visual_class_abbrev(attribs->klass), |
| 487 | attribs->transparent, |
| 488 | attribs->bufferSize, |
| 489 | attribs->level, |
| 490 | attribs->rgba ? "r" : "c", |
| 491 | attribs->doubleBuffer ? "y" : ".", |
| 492 | attribs->stereo ? "y" : ".", |
| 493 | attribs->redSize, attribs->greenSize, |
| 494 | attribs->blueSize, attribs->alphaSize, |
| 495 | attribs->auxBuffers, |
| 496 | attribs->depthSize, |
| 497 | attribs->stencilSize |
| 498 | ); |
| 499 | |
Brian Paul | 25673f0 | 2000-03-31 18:17:51 +0000 | [diff] [blame] | 500 | printf(" %2d %2d %2d %2d %2d %1d %s\n", |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 501 | attribs->accumRedSize, attribs->accumGreenSize, |
| 502 | attribs->accumBlueSize, attribs->accumAlphaSize, |
Brian Paul | 25673f0 | 2000-03-31 18:17:51 +0000 | [diff] [blame] | 503 | attribs->numSamples, attribs->numMultisample, |
| 504 | caveat |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 505 | ); |
| 506 | } |
| 507 | |
| 508 | |
| 509 | static void |
| 510 | print_visual_attribs_long_header(void) |
| 511 | { |
| 512 | printf("Vis Vis Visual Trans buff lev render DB ste r g b a aux dep ste accum buffers MS MS\n"); |
| 513 | printf(" ID Depth Type parent size el type reo sz sz sz sz buf th ncl r g b a num bufs\n"); |
| 514 | printf("----------------------------------------------------------------------------------------------------\n"); |
| 515 | } |
| 516 | |
| 517 | |
| 518 | static void |
| 519 | print_visual_attribs_long(const struct visual_attribs *attribs) |
| 520 | { |
| 521 | printf("0x%2x %2d %-11s %2d %2d %2d %4s %3d %3d %3d %3d %3d %3d", |
| 522 | attribs->id, |
| 523 | attribs->depth, |
| 524 | visual_class_name(attribs->klass), |
| 525 | attribs->transparent, |
| 526 | attribs->bufferSize, |
| 527 | attribs->level, |
| 528 | attribs->rgba ? "rgba" : "ci ", |
| 529 | attribs->doubleBuffer, |
| 530 | attribs->stereo, |
| 531 | attribs->redSize, attribs->greenSize, |
| 532 | attribs->blueSize, attribs->alphaSize |
| 533 | ); |
| 534 | |
| 535 | printf(" %3d %4d %2d %3d %3d %3d %3d %2d %2d\n", |
| 536 | attribs->auxBuffers, |
| 537 | attribs->depthSize, |
| 538 | attribs->stencilSize, |
| 539 | attribs->accumRedSize, attribs->accumGreenSize, |
| 540 | attribs->accumBlueSize, attribs->accumAlphaSize, |
| 541 | attribs->numSamples, attribs->numMultisample |
| 542 | ); |
| 543 | } |
| 544 | |
| 545 | |
| 546 | static void |
| 547 | print_visual_info(Display *dpy, int scrnum, InfoMode mode) |
| 548 | { |
Brian Paul | f02a5f6 | 2002-07-12 15:54:01 +0000 | [diff] [blame] | 549 | XVisualInfo theTemplate; |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 550 | XVisualInfo *visuals; |
| 551 | int numVisuals; |
| 552 | long mask; |
| 553 | int i; |
| 554 | |
| 555 | /* get list of all visuals on this screen */ |
Brian Paul | f02a5f6 | 2002-07-12 15:54:01 +0000 | [diff] [blame] | 556 | theTemplate.screen = scrnum; |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 557 | mask = VisualScreenMask; |
Brian Paul | f02a5f6 | 2002-07-12 15:54:01 +0000 | [diff] [blame] | 558 | visuals = XGetVisualInfo(dpy, mask, &theTemplate, &numVisuals); |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 559 | |
| 560 | if (mode == Verbose) { |
| 561 | for (i = 0; i < numVisuals; i++) { |
| 562 | struct visual_attribs attribs; |
| 563 | get_visual_attribs(dpy, &visuals[i], &attribs); |
| 564 | print_visual_attribs_verbose(&attribs); |
| 565 | } |
| 566 | } |
| 567 | else if (mode == Normal) { |
| 568 | print_visual_attribs_short_header(); |
| 569 | for (i = 0; i < numVisuals; i++) { |
| 570 | struct visual_attribs attribs; |
| 571 | get_visual_attribs(dpy, &visuals[i], &attribs); |
| 572 | print_visual_attribs_short(&attribs); |
| 573 | } |
| 574 | } |
| 575 | else if (mode == Wide) { |
| 576 | print_visual_attribs_long_header(); |
| 577 | for (i = 0; i < numVisuals; i++) { |
| 578 | struct visual_attribs attribs; |
| 579 | get_visual_attribs(dpy, &visuals[i], &attribs); |
| 580 | print_visual_attribs_long(&attribs); |
| 581 | } |
| 582 | } |
| 583 | |
| 584 | XFree(visuals); |
| 585 | } |
| 586 | |
| 587 | |
Brian Paul | 39557c3 | 2001-03-23 21:41:44 +0000 | [diff] [blame] | 588 | /* |
| 589 | * Stand-alone Mesa doesn't really implement the GLX protocol so it |
| 590 | * doesn't really know the GLX attributes associated with an X visual. |
| 591 | * The first time a visual is presented to Mesa's pseudo-GLX it |
| 592 | * attaches ancilliary buffers to it (like depth and stencil). |
| 593 | * But that usually only works if glXChooseVisual is used. |
| 594 | * This function calls glXChooseVisual() to sort of "prime the pump" |
| 595 | * for Mesa's GLX so that the visuals that get reported actually |
| 596 | * reflect what applications will see. |
| 597 | * This has no effect when using true GLX. |
| 598 | */ |
| 599 | static void |
| 600 | mesa_hack(Display *dpy, int scrnum) |
| 601 | { |
| 602 | static int attribs[] = { |
| 603 | GLX_RGBA, |
| 604 | GLX_RED_SIZE, 1, |
| 605 | GLX_GREEN_SIZE, 1, |
| 606 | GLX_BLUE_SIZE, 1, |
| 607 | GLX_DEPTH_SIZE, 1, |
| 608 | GLX_STENCIL_SIZE, 1, |
| 609 | GLX_ACCUM_RED_SIZE, 1, |
| 610 | GLX_ACCUM_GREEN_SIZE, 1, |
| 611 | GLX_ACCUM_BLUE_SIZE, 1, |
| 612 | GLX_ACCUM_ALPHA_SIZE, 1, |
| 613 | GLX_DOUBLEBUFFER, |
| 614 | None |
| 615 | }; |
| 616 | XVisualInfo *visinfo; |
| 617 | |
| 618 | visinfo = glXChooseVisual(dpy, scrnum, attribs); |
| 619 | if (visinfo) |
| 620 | XFree(visinfo); |
| 621 | } |
| 622 | |
| 623 | |
| 624 | /* |
| 625 | * Examine all visuals to find the so-called best one. |
| 626 | * We prefer deepest RGBA buffer with depth, stencil and accum |
| 627 | * that has no caveats. |
| 628 | */ |
| 629 | static int |
| 630 | find_best_visual(Display *dpy, int scrnum) |
| 631 | { |
Brian Paul | f02a5f6 | 2002-07-12 15:54:01 +0000 | [diff] [blame] | 632 | XVisualInfo theTemplate; |
Brian Paul | 39557c3 | 2001-03-23 21:41:44 +0000 | [diff] [blame] | 633 | XVisualInfo *visuals; |
| 634 | int numVisuals; |
| 635 | long mask; |
| 636 | int i; |
| 637 | struct visual_attribs bestVis; |
| 638 | |
| 639 | /* get list of all visuals on this screen */ |
Brian Paul | f02a5f6 | 2002-07-12 15:54:01 +0000 | [diff] [blame] | 640 | theTemplate.screen = scrnum; |
Brian Paul | 39557c3 | 2001-03-23 21:41:44 +0000 | [diff] [blame] | 641 | mask = VisualScreenMask; |
Brian Paul | f02a5f6 | 2002-07-12 15:54:01 +0000 | [diff] [blame] | 642 | visuals = XGetVisualInfo(dpy, mask, &theTemplate, &numVisuals); |
Brian Paul | 39557c3 | 2001-03-23 21:41:44 +0000 | [diff] [blame] | 643 | |
| 644 | /* init bestVis with first visual info */ |
| 645 | get_visual_attribs(dpy, &visuals[0], &bestVis); |
| 646 | |
| 647 | /* try to find a "better" visual */ |
| 648 | for (i = 1; i < numVisuals; i++) { |
| 649 | struct visual_attribs vis; |
| 650 | |
| 651 | get_visual_attribs(dpy, &visuals[i], &vis); |
| 652 | |
| 653 | /* always skip visuals with caveats */ |
| 654 | if (vis.visualCaveat != GLX_NONE_EXT) |
| 655 | continue; |
| 656 | |
| 657 | /* see if this vis is better than bestVis */ |
| 658 | if ((!bestVis.supportsGL && vis.supportsGL) || |
| 659 | (bestVis.visualCaveat != GLX_NONE_EXT) || |
| 660 | (!bestVis.rgba && vis.rgba) || |
| 661 | (!bestVis.doubleBuffer && vis.doubleBuffer) || |
| 662 | (bestVis.redSize < vis.redSize) || |
| 663 | (bestVis.greenSize < vis.greenSize) || |
| 664 | (bestVis.blueSize < vis.blueSize) || |
| 665 | (bestVis.alphaSize < vis.alphaSize) || |
| 666 | (bestVis.depthSize < vis.depthSize) || |
| 667 | (bestVis.stencilSize < vis.stencilSize) || |
| 668 | (bestVis.accumRedSize < vis.accumRedSize)) { |
| 669 | /* found a better visual */ |
| 670 | bestVis = vis; |
| 671 | } |
| 672 | } |
| 673 | |
| 674 | XFree(visuals); |
| 675 | |
| 676 | return bestVis.id; |
| 677 | } |
| 678 | |
| 679 | |
Brian Paul | 08b3ff1 | 2001-04-24 20:57:36 +0000 | [diff] [blame] | 680 | static void |
| 681 | usage(void) |
| 682 | { |
| 683 | printf("Usage: glxinfo [-v] [-t] [-h] [-i] [-b] [-display <dname>]\n"); |
| 684 | printf("\t-v: Print visuals info in verbose form.\n"); |
| 685 | printf("\t-t: Print verbose table.\n"); |
| 686 | printf("\t-display <dname>: Print GLX visuals on specified server.\n"); |
| 687 | printf("\t-h: This information.\n"); |
| 688 | printf("\t-i: Force an indirect rendering context.\n"); |
| 689 | printf("\t-b: Find the 'best' visual and print it's number.\n"); |
Brian Paul | 2f7ef5f | 2002-09-06 03:35:43 +0000 | [diff] [blame] | 690 | printf("\t-l: Print interesting OpenGLl imits.\n"); |
Brian Paul | 08b3ff1 | 2001-04-24 20:57:36 +0000 | [diff] [blame] | 691 | } |
| 692 | |
| 693 | |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 694 | int |
| 695 | main(int argc, char *argv[]) |
| 696 | { |
Alan Hourihane | e18599a | 2001-03-19 13:58:45 +0000 | [diff] [blame] | 697 | char *displayName = NULL; |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 698 | Display *dpy; |
| 699 | int numScreens, scrnum; |
| 700 | InfoMode mode = Normal; |
Brian Paul | 39557c3 | 2001-03-23 21:41:44 +0000 | [diff] [blame] | 701 | GLboolean findBest = GL_FALSE; |
Brian Paul | 2f7ef5f | 2002-09-06 03:35:43 +0000 | [diff] [blame] | 702 | GLboolean limits = GL_FALSE; |
Brian Paul | 08b3ff1 | 2001-04-24 20:57:36 +0000 | [diff] [blame] | 703 | Bool allowDirect = True; |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 704 | int i; |
| 705 | |
| 706 | for (i = 1; i < argc; i++) { |
| 707 | if (strcmp(argv[i], "-display") == 0 && i + 1 < argc) { |
| 708 | displayName = argv[i + 1]; |
| 709 | i++; |
| 710 | } |
| 711 | else if (strcmp(argv[i], "-t") == 0) { |
| 712 | mode = Wide; |
| 713 | } |
| 714 | else if (strcmp(argv[i], "-v") == 0) { |
| 715 | mode = Verbose; |
| 716 | } |
Brian Paul | 39557c3 | 2001-03-23 21:41:44 +0000 | [diff] [blame] | 717 | else if (strcmp(argv[i], "-b") == 0) { |
| 718 | findBest = GL_TRUE; |
| 719 | } |
Brian Paul | 08b3ff1 | 2001-04-24 20:57:36 +0000 | [diff] [blame] | 720 | else if (strcmp(argv[i], "-i") == 0) { |
| 721 | allowDirect = False; |
| 722 | } |
Brian Paul | 2f7ef5f | 2002-09-06 03:35:43 +0000 | [diff] [blame] | 723 | else if (strcmp(argv[i], "-l") == 0) { |
| 724 | limits = GL_TRUE; |
| 725 | } |
Brian Paul | 08b3ff1 | 2001-04-24 20:57:36 +0000 | [diff] [blame] | 726 | else if (strcmp(argv[i], "-h") == 0) { |
| 727 | usage(); |
| 728 | return 0; |
| 729 | } |
| 730 | else { |
| 731 | printf("Unknown option `%s'\n", argv[i]); |
| 732 | usage(); |
| 733 | return 0; |
| 734 | } |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | dpy = XOpenDisplay(displayName); |
| 738 | if (!dpy) { |
| 739 | fprintf(stderr, "Error: unable to open display %s\n", displayName); |
| 740 | return -1; |
| 741 | } |
| 742 | |
Brian Paul | 39557c3 | 2001-03-23 21:41:44 +0000 | [diff] [blame] | 743 | if (findBest) { |
| 744 | int b; |
| 745 | mesa_hack(dpy, 0); |
| 746 | b = find_best_visual(dpy, 0); |
| 747 | printf("%d\n", b); |
| 748 | } |
| 749 | else { |
| 750 | numScreens = ScreenCount(dpy); |
Brian Paul | 373aea1 | 2001-04-02 22:45:07 +0000 | [diff] [blame] | 751 | print_display_info(dpy); |
Brian Paul | 39557c3 | 2001-03-23 21:41:44 +0000 | [diff] [blame] | 752 | for (scrnum = 0; scrnum < numScreens; scrnum++) { |
| 753 | mesa_hack(dpy, scrnum); |
Brian Paul | 2f7ef5f | 2002-09-06 03:35:43 +0000 | [diff] [blame] | 754 | print_screen_info(dpy, scrnum, allowDirect, limits); |
Brian Paul | 39557c3 | 2001-03-23 21:41:44 +0000 | [diff] [blame] | 755 | printf("\n"); |
| 756 | print_visual_info(dpy, scrnum, mode); |
| 757 | if (scrnum + 1 < numScreens) |
| 758 | printf("\n\n"); |
| 759 | } |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 760 | } |
| 761 | |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 762 | XCloseDisplay(dpy); |
| 763 | |
| 764 | return 0; |
| 765 | } |