Brian Paul | 45c5698 | 2002-10-14 13:57:23 +0000 | [diff] [blame] | 1 | /* $Id: glxinfo.c,v 1.20 2002/10/14 13:57:23 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 | |
Brian Paul | 45c5698 | 2002-10-14 13:57:23 +0000 | [diff] [blame] | 56 | #ifndef GLX_TRANSPARENT_RGB |
| 57 | #define GLX_TRANSPARENT_RGB 0x8008 |
| 58 | #endif |
Brian Paul | 39557c3 | 2001-03-23 21:41:44 +0000 | [diff] [blame] | 59 | |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 60 | typedef enum |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 61 | { |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 62 | Normal, |
| 63 | Wide, |
| 64 | Verbose |
| 65 | } InfoMode; |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 66 | |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 67 | |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 68 | struct 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 Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 77 | |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 78 | /* GL visual attribs */ |
| 79 | int supportsGL; |
Brian Paul | 45c5698 | 2002-10-14 13:57:23 +0000 | [diff] [blame] | 80 | int transparentType; |
| 81 | int transparentRedValue; |
| 82 | int transparentGreenValue; |
| 83 | int transparentBlueValue; |
| 84 | int transparentAlphaValue; |
| 85 | int transparentIndexValue; |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 86 | 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 Paul | 25673f0 | 2000-03-31 18:17:51 +0000 | [diff] [blame] | 97 | int visualCaveat; |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | |
| 101 | /* |
| 102 | * Print a list of extensions, with word-wrapping. |
| 103 | */ |
| 104 | static void |
| 105 | print_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 Paul | 7ac4350 | 2000-02-23 22:50:35 +0000 | [diff] [blame] | 141 | if (ext[j] == 0) |
| 142 | break; |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 143 | printf(", "); |
| 144 | width += 2; |
| 145 | } |
| 146 | } |
| 147 | j++; |
| 148 | } |
| 149 | printf("\n"); |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 153 | static void |
Brian Paul | 373aea1 | 2001-04-02 22:45:07 +0000 | [diff] [blame] | 154 | print_display_info(Display *dpy) |
| 155 | { |
| 156 | printf("name of display: %s\n", DisplayString(dpy)); |
| 157 | } |
| 158 | |
| 159 | |
| 160 | static void |
Brian Paul | 2f7ef5f | 2002-09-06 03:35:43 +0000 | [diff] [blame] | 161 | print_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 Paul | 2f7ef5f | 2002-09-06 03:35:43 +0000 | [diff] [blame] | 173 | { 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 | |
| 212 | static void |
| 213 | print_screen_info(Display *dpy, int scrnum, Bool allowDirect, GLboolean limits) |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 214 | { |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 215 | Window win; |
Brian Paul | 8460cc9 | 2000-02-02 20:57:51 +0000 | [diff] [blame] | 216 | 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 Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 230 | XSetWindowAttributes attr; |
| 231 | unsigned long mask; |
| 232 | Window root; |
| 233 | GLXContext ctx; |
| 234 | XVisualInfo *visinfo; |
| 235 | int width = 100, height = 100; |
| 236 | |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 237 | root = RootWindow(dpy, scrnum); |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 238 | |
Brian Paul | 8460cc9 | 2000-02-02 20:57:51 +0000 | [diff] [blame] | 239 | visinfo = glXChooseVisual(dpy, scrnum, attribSingle); |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 240 | if (!visinfo) { |
Brian Paul | 8460cc9 | 2000-02-02 20:57:51 +0000 | [diff] [blame] | 241 | visinfo = glXChooseVisual(dpy, scrnum, attribDouble); |
| 242 | if (!visinfo) { |
Brian Paul | 9cff558 | 2000-05-07 18:07:23 +0000 | [diff] [blame] | 243 | fprintf(stderr, "Error: couldn't find RGB GLX visual\n"); |
Brian Paul | 8460cc9 | 2000-02-02 20:57:51 +0000 | [diff] [blame] | 244 | return; |
| 245 | } |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 246 | } |
| 247 | |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 248 | attr.background_pixel = 0; |
| 249 | attr.border_pixel = 0; |
Brian Paul | 9cff558 | 2000-05-07 18:07:23 +0000 | [diff] [blame] | 250 | attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone); |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 251 | attr.event_mask = StructureNotifyMask | ExposureMask; |
| 252 | mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 253 | win = XCreateWindow(dpy, root, 0, 0, width, height, |
| 254 | 0, visinfo->depth, InputOutput, |
| 255 | visinfo->visual, mask, &attr); |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 256 | |
Brian Paul | 08b3ff1 | 2001-04-24 20:57:36 +0000 | [diff] [blame] | 257 | ctx = glXCreateContext( dpy, visinfo, NULL, allowDirect ); |
Brian Paul | 34fb5db | 2000-04-22 20:31:23 +0000 | [diff] [blame] | 258 | if (!ctx) { |
Brian Paul | 9cff558 | 2000-05-07 18:07:23 +0000 | [diff] [blame] | 259 | fprintf(stderr, "Error: glXCreateContext failed\n"); |
Brian Paul | 34fb5db | 2000-04-22 20:31:23 +0000 | [diff] [blame] | 260 | XDestroyWindow(dpy, win); |
| 261 | return; |
| 262 | } |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 263 | |
Brian Paul | 9cff558 | 2000-05-07 18:07:23 +0000 | [diff] [blame] | 264 | if (glXMakeCurrent(dpy, win, ctx)) { |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 265 | 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 Paul | 34fb5db | 2000-04-22 20:31:23 +0000 | [diff] [blame] | 268 | const char *clientVendor = glXGetClientString(dpy, GLX_VENDOR); |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 269 | 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 Paul | 373aea1 | 2001-04-02 22:45:07 +0000 | [diff] [blame] | 276 | char *displayName = NULL; |
| 277 | char *colon = NULL, *period = NULL; |
Brian Paul | 39557c3 | 2001-03-23 21:41:44 +0000 | [diff] [blame] | 278 | #ifdef DO_GLU |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 279 | const char *gluVersion = (const char *) gluGetString(GLU_VERSION); |
| 280 | const char *gluExtensions = (const char *) gluGetString(GLU_EXTENSIONS); |
Brian Paul | 39557c3 | 2001-03-23 21:41:44 +0000 | [diff] [blame] | 281 | #endif |
Brian Paul | 373aea1 | 2001-04-02 22:45:07 +0000 | [diff] [blame] | 282 | /* Strip the screen number from the display name, if present. */ |
Brian Paul | f02a5f6 | 2002-07-12 15:54:01 +0000 | [diff] [blame] | 283 | if (!(displayName = (char *) malloc(strlen(DisplayString(dpy)) + 1))) { |
Brian Paul | 373aea1 | 2001-04-02 22:45:07 +0000 | [diff] [blame] | 284 | 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 Paul | e691ee2 | 2000-05-08 14:53:57 +0000 | [diff] [blame] | 296 | printf("direct rendering: %s\n", glXIsDirect(dpy, ctx) ? "Yes" : "No"); |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 297 | 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 Paul | 34fb5db | 2000-04-22 20:31:23 +0000 | [diff] [blame] | 301 | printf("client glx vendor string: %s\n", clientVendor); |
| 302 | printf("client glx version string: %s\n", clientVersion); |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 303 | 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 Paul | 2f7ef5f | 2002-09-06 03:35:43 +0000 | [diff] [blame] | 312 | if (limits) |
| 313 | print_limits(); |
Brian Paul | 39557c3 | 2001-03-23 21:41:44 +0000 | [diff] [blame] | 314 | #ifdef DO_GLU |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 315 | printf("glu version: %s\n", gluVersion); |
| 316 | printf("glu extensions:\n"); |
| 317 | print_extension_list(gluExtensions); |
Brian Paul | 39557c3 | 2001-03-23 21:41:44 +0000 | [diff] [blame] | 318 | #endif |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 319 | } |
Brian Paul | 9cff558 | 2000-05-07 18:07:23 +0000 | [diff] [blame] | 320 | else { |
| 321 | fprintf(stderr, "Error: glXMakeCurrent failed\n"); |
| 322 | } |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 323 | |
| 324 | glXDestroyContext(dpy, ctx); |
| 325 | XDestroyWindow(dpy, win); |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | |
| 329 | static const char * |
| 330 | visual_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 | |
| 351 | static const char * |
| 352 | visual_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 | |
| 373 | static void |
| 374 | get_visual_attribs(Display *dpy, XVisualInfo *vInfo, |
| 375 | struct visual_attribs *attribs) |
| 376 | { |
Brian Paul | 25673f0 | 2000-03-31 18:17:51 +0000 | [diff] [blame] | 377 | const char *ext = glXQueryExtensionsString(dpy, vInfo->screen); |
| 378 | |
Brian Paul | a9c53fa | 2000-04-03 15:45:34 +0000 | [diff] [blame] | 379 | memset(attribs, 0, sizeof(struct visual_attribs)); |
| 380 | |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 381 | 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 Paul | a9c53fa | 2000-04-03 15:45:34 +0000 | [diff] [blame] | 394 | if (glXGetConfig(dpy, vInfo, GLX_USE_GL, &attribs->supportsGL) != 0) |
| 395 | return; |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 396 | 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 Paul | 45c5698 | 2002-10-14 13:57:23 +0000 | [diff] [blame] | 413 | /* 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 Paul | e06c7f3 | 2000-01-27 16:53:55 +0000 | [diff] [blame] | 424 | |
| 425 | /* multisample tests not implemented yet */ |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 426 | attribs->numSamples = 0; |
| 427 | attribs->numMultisample = 0; |
Brian Paul | 25673f0 | 2000-03-31 18:17:51 +0000 | [diff] [blame] | 428 | |
| 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 Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | |
| 442 | static void |
| 443 | print_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 Paul | 25673f0 | 2000-03-31 18:17:51 +0000 | [diff] [blame] | 460 | #ifdef GLX_EXT_visual_rating |
| 461 | if (attribs->visualCaveat == GLX_NONE_EXT || attribs->visualCaveat == 0) |
Brian Paul | a9c53fa | 2000-04-03 15:45:34 +0000 | [diff] [blame] | 462 | printf(" visualCaveat=None\n"); |
Brian Paul | 25673f0 | 2000-03-31 18:17:51 +0000 | [diff] [blame] | 463 | else if (attribs->visualCaveat == GLX_SLOW_VISUAL_EXT) |
Brian Paul | a9c53fa | 2000-04-03 15:45:34 +0000 | [diff] [blame] | 464 | printf(" visualCaveat=Slow\n"); |
Brian Paul | 25673f0 | 2000-03-31 18:17:51 +0000 | [diff] [blame] | 465 | else if (attribs->visualCaveat == GLX_NON_CONFORMANT_VISUAL_EXT) |
Brian Paul | a9c53fa | 2000-04-03 15:45:34 +0000 | [diff] [blame] | 466 | printf(" visualCaveat=Nonconformant\n"); |
Brian Paul | 25673f0 | 2000-03-31 18:17:51 +0000 | [diff] [blame] | 467 | #endif |
Brian Paul | 45c5698 | 2002-10-14 13:57:23 +0000 | [diff] [blame] | 468 | 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 Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | |
| 480 | static void |
| 481 | print_visual_attribs_short_header(void) |
| 482 | { |
Brian Paul | a9c53fa | 2000-04-03 15:45:34 +0000 | [diff] [blame] | 483 | 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 Paul | 25673f0 | 2000-03-31 18:17:51 +0000 | [diff] [blame] | 485 | printf("----------------------------------------------------------------------\n"); |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | |
| 489 | static void |
| 490 | print_visual_attribs_short(const struct visual_attribs *attribs) |
| 491 | { |
Brian Paul | a3e44f4 | 2002-03-08 19:44:28 +0000 | [diff] [blame] | 492 | char *caveat = NULL; |
Brian Paul | 25673f0 | 2000-03-31 18:17:51 +0000 | [diff] [blame] | 493 | #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 Paul | 28bc6cb | 2002-09-06 03:47:34 +0000 | [diff] [blame] | 500 | else |
| 501 | caveat = "None"; |
Brian Paul | 25673f0 | 2000-03-31 18:17:51 +0000 | [diff] [blame] | 502 | #else |
| 503 | caveat = "None"; |
| 504 | #endif |
| 505 | |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 506 | 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 Paul | 45c5698 | 2002-10-14 13:57:23 +0000 | [diff] [blame] | 510 | attribs->transparentType != GLX_NONE, |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 511 | 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 Paul | 25673f0 | 2000-03-31 18:17:51 +0000 | [diff] [blame] | 523 | printf(" %2d %2d %2d %2d %2d %1d %s\n", |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 524 | attribs->accumRedSize, attribs->accumGreenSize, |
| 525 | attribs->accumBlueSize, attribs->accumAlphaSize, |
Brian Paul | 25673f0 | 2000-03-31 18:17:51 +0000 | [diff] [blame] | 526 | attribs->numSamples, attribs->numMultisample, |
| 527 | caveat |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 528 | ); |
| 529 | } |
| 530 | |
| 531 | |
| 532 | static void |
| 533 | print_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 | |
| 541 | static void |
| 542 | print_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 Paul | 45c5698 | 2002-10-14 13:57:23 +0000 | [diff] [blame] | 548 | attribs->transparentType != GLX_NONE, |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 549 | 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 | |
| 569 | static void |
| 570 | print_visual_info(Display *dpy, int scrnum, InfoMode mode) |
| 571 | { |
Brian Paul | f02a5f6 | 2002-07-12 15:54:01 +0000 | [diff] [blame] | 572 | XVisualInfo theTemplate; |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 573 | XVisualInfo *visuals; |
| 574 | int numVisuals; |
| 575 | long mask; |
| 576 | int i; |
| 577 | |
| 578 | /* get list of all visuals on this screen */ |
Brian Paul | f02a5f6 | 2002-07-12 15:54:01 +0000 | [diff] [blame] | 579 | theTemplate.screen = scrnum; |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 580 | mask = VisualScreenMask; |
Brian Paul | f02a5f6 | 2002-07-12 15:54:01 +0000 | [diff] [blame] | 581 | visuals = XGetVisualInfo(dpy, mask, &theTemplate, &numVisuals); |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 582 | |
| 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 Paul | 39557c3 | 2001-03-23 21:41:44 +0000 | [diff] [blame] | 611 | /* |
| 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 | */ |
| 622 | static void |
| 623 | mesa_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 | */ |
| 652 | static int |
| 653 | find_best_visual(Display *dpy, int scrnum) |
| 654 | { |
Brian Paul | f02a5f6 | 2002-07-12 15:54:01 +0000 | [diff] [blame] | 655 | XVisualInfo theTemplate; |
Brian Paul | 39557c3 | 2001-03-23 21:41:44 +0000 | [diff] [blame] | 656 | 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 Paul | f02a5f6 | 2002-07-12 15:54:01 +0000 | [diff] [blame] | 663 | theTemplate.screen = scrnum; |
Brian Paul | 39557c3 | 2001-03-23 21:41:44 +0000 | [diff] [blame] | 664 | mask = VisualScreenMask; |
Brian Paul | f02a5f6 | 2002-07-12 15:54:01 +0000 | [diff] [blame] | 665 | visuals = XGetVisualInfo(dpy, mask, &theTemplate, &numVisuals); |
Brian Paul | 39557c3 | 2001-03-23 21:41:44 +0000 | [diff] [blame] | 666 | |
| 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 Paul | 08b3ff1 | 2001-04-24 20:57:36 +0000 | [diff] [blame] | 703 | static void |
| 704 | usage(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 Paul | 2f7ef5f | 2002-09-06 03:35:43 +0000 | [diff] [blame] | 713 | printf("\t-l: Print interesting OpenGLl imits.\n"); |
Brian Paul | 08b3ff1 | 2001-04-24 20:57:36 +0000 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 717 | int |
| 718 | main(int argc, char *argv[]) |
| 719 | { |
Alan Hourihane | e18599a | 2001-03-19 13:58:45 +0000 | [diff] [blame] | 720 | char *displayName = NULL; |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 721 | Display *dpy; |
| 722 | int numScreens, scrnum; |
| 723 | InfoMode mode = Normal; |
Brian Paul | 39557c3 | 2001-03-23 21:41:44 +0000 | [diff] [blame] | 724 | GLboolean findBest = GL_FALSE; |
Brian Paul | 2f7ef5f | 2002-09-06 03:35:43 +0000 | [diff] [blame] | 725 | GLboolean limits = GL_FALSE; |
Brian Paul | 08b3ff1 | 2001-04-24 20:57:36 +0000 | [diff] [blame] | 726 | Bool allowDirect = True; |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 727 | 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 Paul | 39557c3 | 2001-03-23 21:41:44 +0000 | [diff] [blame] | 740 | else if (strcmp(argv[i], "-b") == 0) { |
| 741 | findBest = GL_TRUE; |
| 742 | } |
Brian Paul | 08b3ff1 | 2001-04-24 20:57:36 +0000 | [diff] [blame] | 743 | else if (strcmp(argv[i], "-i") == 0) { |
| 744 | allowDirect = False; |
| 745 | } |
Brian Paul | 2f7ef5f | 2002-09-06 03:35:43 +0000 | [diff] [blame] | 746 | else if (strcmp(argv[i], "-l") == 0) { |
| 747 | limits = GL_TRUE; |
| 748 | } |
Brian Paul | 08b3ff1 | 2001-04-24 20:57:36 +0000 | [diff] [blame] | 749 | 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 Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 758 | } |
| 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 Paul | 39557c3 | 2001-03-23 21:41:44 +0000 | [diff] [blame] | 766 | 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 Paul | 373aea1 | 2001-04-02 22:45:07 +0000 | [diff] [blame] | 774 | print_display_info(dpy); |
Brian Paul | 39557c3 | 2001-03-23 21:41:44 +0000 | [diff] [blame] | 775 | for (scrnum = 0; scrnum < numScreens; scrnum++) { |
| 776 | mesa_hack(dpy, scrnum); |
Brian Paul | 2f7ef5f | 2002-09-06 03:35:43 +0000 | [diff] [blame] | 777 | print_screen_info(dpy, scrnum, allowDirect, limits); |
Brian Paul | 39557c3 | 2001-03-23 21:41:44 +0000 | [diff] [blame] | 778 | printf("\n"); |
| 779 | print_visual_info(dpy, scrnum, mode); |
| 780 | if (scrnum + 1 < numScreens) |
| 781 | printf("\n\n"); |
| 782 | } |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 783 | } |
| 784 | |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 785 | XCloseDisplay(dpy); |
| 786 | |
| 787 | return 0; |
| 788 | } |