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