Brian Paul | e691ee2 | 2000-05-08 14:53:57 +0000 | [diff] [blame^] | 1 | /* $Id: glxinfo.c,v 1.10 2000/05/08 14:53:57 brianp Exp $ */ |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 2 | |
| 3 | /* |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 4 | * Copyright (C) 1999 Brian Paul All Rights Reserved. |
| 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 |
| 31 | * |
| 32 | * Brian Paul 26 January 2000 |
| 33 | */ |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 34 | |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 35 | |
| 36 | #include <X11/Xlib.h> |
| 37 | #include <X11/Xutil.h> |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 38 | #include <GL/gl.h> |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 39 | #include <GL/glu.h> |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 40 | #include <GL/glx.h> |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 41 | #include <stdio.h> |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 42 | #include <string.h> |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 43 | |
| 44 | |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 45 | typedef enum |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 46 | { |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 47 | Normal, |
| 48 | Wide, |
| 49 | Verbose |
| 50 | } InfoMode; |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 51 | |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 52 | |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 53 | struct visual_attribs |
| 54 | { |
| 55 | /* X visual attribs */ |
| 56 | int id; |
| 57 | int klass; |
| 58 | int depth; |
| 59 | int redMask, greenMask, blueMask; |
| 60 | int colormapSize; |
| 61 | int bitsPerRGB; |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 62 | |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 63 | /* GL visual attribs */ |
| 64 | int supportsGL; |
| 65 | int transparent; |
| 66 | int bufferSize; |
| 67 | int level; |
| 68 | int rgba; |
| 69 | int doubleBuffer; |
| 70 | int stereo; |
| 71 | int auxBuffers; |
| 72 | int redSize, greenSize, blueSize, alphaSize; |
| 73 | int depthSize; |
| 74 | int stencilSize; |
| 75 | int accumRedSize, accumGreenSize, accumBlueSize, accumAlphaSize; |
| 76 | int numSamples, numMultisample; |
Brian Paul | 25673f0 | 2000-03-31 18:17:51 +0000 | [diff] [blame] | 77 | int visualCaveat; |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | |
| 81 | /* |
| 82 | * Print a list of extensions, with word-wrapping. |
| 83 | */ |
| 84 | static void |
| 85 | print_extension_list(const char *ext) |
| 86 | { |
| 87 | const char *indentString = " "; |
| 88 | const int indent = 4; |
| 89 | const int max = 79; |
| 90 | int width, i, j; |
| 91 | |
| 92 | if (!ext || !ext[0]) |
| 93 | return; |
| 94 | |
| 95 | width = indent; |
| 96 | printf(indentString); |
| 97 | i = j = 0; |
| 98 | while (1) { |
| 99 | if (ext[j] == ' ' || ext[j] == 0) { |
| 100 | /* found end of an extension name */ |
| 101 | const int len = j - i; |
| 102 | if (width + len > max) { |
| 103 | /* start a new line */ |
| 104 | printf("\n"); |
| 105 | width = indent; |
| 106 | printf(indentString); |
| 107 | } |
| 108 | /* print the extension name between ext[i] and ext[j] */ |
| 109 | while (i < j) { |
| 110 | printf("%c", ext[i]); |
| 111 | i++; |
| 112 | } |
| 113 | /* either we're all done, or we'll continue with next extension */ |
| 114 | width += len + 1; |
| 115 | if (ext[j] == 0) { |
| 116 | break; |
| 117 | } |
| 118 | else { |
| 119 | i++; |
| 120 | j++; |
Brian Paul | 7ac4350 | 2000-02-23 22:50:35 +0000 | [diff] [blame] | 121 | if (ext[j] == 0) |
| 122 | break; |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 123 | printf(", "); |
| 124 | width += 2; |
| 125 | } |
| 126 | } |
| 127 | j++; |
| 128 | } |
| 129 | printf("\n"); |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 133 | static void |
| 134 | print_screen_info(Display *dpy, int scrnum) |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 135 | { |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 136 | Window win; |
Brian Paul | 8460cc9 | 2000-02-02 20:57:51 +0000 | [diff] [blame] | 137 | int attribSingle[] = { |
| 138 | GLX_RGBA, |
| 139 | GLX_RED_SIZE, 1, |
| 140 | GLX_GREEN_SIZE, 1, |
| 141 | GLX_BLUE_SIZE, 1, |
| 142 | None }; |
| 143 | int attribDouble[] = { |
| 144 | GLX_RGBA, |
| 145 | GLX_RED_SIZE, 1, |
| 146 | GLX_GREEN_SIZE, 1, |
| 147 | GLX_BLUE_SIZE, 1, |
| 148 | GLX_DOUBLEBUFFER, |
| 149 | None }; |
| 150 | |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 151 | XSetWindowAttributes attr; |
| 152 | unsigned long mask; |
| 153 | Window root; |
| 154 | GLXContext ctx; |
| 155 | XVisualInfo *visinfo; |
| 156 | int width = 100, height = 100; |
| 157 | |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 158 | root = RootWindow(dpy, scrnum); |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 159 | |
Brian Paul | 8460cc9 | 2000-02-02 20:57:51 +0000 | [diff] [blame] | 160 | visinfo = glXChooseVisual(dpy, scrnum, attribSingle); |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 161 | if (!visinfo) { |
Brian Paul | 8460cc9 | 2000-02-02 20:57:51 +0000 | [diff] [blame] | 162 | visinfo = glXChooseVisual(dpy, scrnum, attribDouble); |
| 163 | if (!visinfo) { |
Brian Paul | 9cff558 | 2000-05-07 18:07:23 +0000 | [diff] [blame] | 164 | fprintf(stderr, "Error: couldn't find RGB GLX visual\n"); |
Brian Paul | 8460cc9 | 2000-02-02 20:57:51 +0000 | [diff] [blame] | 165 | return; |
| 166 | } |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 167 | } |
| 168 | |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 169 | attr.background_pixel = 0; |
| 170 | attr.border_pixel = 0; |
Brian Paul | 9cff558 | 2000-05-07 18:07:23 +0000 | [diff] [blame] | 171 | attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone); |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 172 | attr.event_mask = StructureNotifyMask | ExposureMask; |
| 173 | mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 174 | win = XCreateWindow(dpy, root, 0, 0, width, height, |
| 175 | 0, visinfo->depth, InputOutput, |
| 176 | visinfo->visual, mask, &attr); |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 177 | |
| 178 | ctx = glXCreateContext( dpy, visinfo, NULL, True ); |
Brian Paul | 34fb5db | 2000-04-22 20:31:23 +0000 | [diff] [blame] | 179 | if (!ctx) { |
Brian Paul | 9cff558 | 2000-05-07 18:07:23 +0000 | [diff] [blame] | 180 | fprintf(stderr, "Error: glXCreateContext failed\n"); |
Brian Paul | 34fb5db | 2000-04-22 20:31:23 +0000 | [diff] [blame] | 181 | XDestroyWindow(dpy, win); |
| 182 | return; |
| 183 | } |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 184 | |
Brian Paul | 9cff558 | 2000-05-07 18:07:23 +0000 | [diff] [blame] | 185 | if (glXMakeCurrent(dpy, win, ctx)) { |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 186 | const char *serverVendor = glXQueryServerString(dpy, scrnum, GLX_VENDOR); |
| 187 | const char *serverVersion = glXQueryServerString(dpy, scrnum, GLX_VERSION); |
| 188 | const char *serverExtensions = glXQueryServerString(dpy, scrnum, GLX_EXTENSIONS); |
Brian Paul | 34fb5db | 2000-04-22 20:31:23 +0000 | [diff] [blame] | 189 | const char *clientVendor = glXGetClientString(dpy, GLX_VENDOR); |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 190 | const char *clientVersion = glXGetClientString(dpy, GLX_VERSION); |
| 191 | const char *clientExtensions = glXGetClientString(dpy, GLX_EXTENSIONS); |
| 192 | const char *glxExtensions = glXQueryExtensionsString(dpy, scrnum); |
| 193 | const char *glVendor = (const char *) glGetString(GL_VENDOR); |
| 194 | const char *glRenderer = (const char *) glGetString(GL_RENDERER); |
| 195 | const char *glVersion = (const char *) glGetString(GL_VERSION); |
| 196 | const char *glExtensions = (const char *) glGetString(GL_EXTENSIONS); |
| 197 | const char *gluVersion = (const char *) gluGetString(GLU_VERSION); |
| 198 | const char *gluExtensions = (const char *) gluGetString(GLU_EXTENSIONS); |
| 199 | printf("display: %s screen:%d\n", DisplayString(dpy), scrnum); |
Brian Paul | e691ee2 | 2000-05-08 14:53:57 +0000 | [diff] [blame^] | 200 | printf("direct rendering: %s\n", glXIsDirect(dpy, ctx) ? "Yes" : "No"); |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 201 | printf("server glx vendor string: %s\n", serverVendor); |
| 202 | printf("server glx version string: %s\n", serverVersion); |
| 203 | printf("server glx extensions:\n"); |
| 204 | print_extension_list(serverExtensions); |
Brian Paul | 34fb5db | 2000-04-22 20:31:23 +0000 | [diff] [blame] | 205 | printf("client glx vendor string: %s\n", clientVendor); |
| 206 | printf("client glx version string: %s\n", clientVersion); |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 207 | printf("client glx extensions:\n"); |
| 208 | print_extension_list(clientExtensions); |
| 209 | printf("GLX extensions:\n"); |
| 210 | print_extension_list(glxExtensions); |
| 211 | printf("OpenGL vendor string: %s\n", glVendor); |
| 212 | printf("OpenGL renderer string: %s\n", glRenderer); |
| 213 | printf("OpenGL version string: %s\n", glVersion); |
| 214 | printf("OpenGL extensions:\n"); |
| 215 | print_extension_list(glExtensions); |
| 216 | printf("glu version: %s\n", gluVersion); |
| 217 | printf("glu extensions:\n"); |
| 218 | print_extension_list(gluExtensions); |
| 219 | } |
Brian Paul | 9cff558 | 2000-05-07 18:07:23 +0000 | [diff] [blame] | 220 | else { |
| 221 | fprintf(stderr, "Error: glXMakeCurrent failed\n"); |
| 222 | } |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 223 | |
| 224 | glXDestroyContext(dpy, ctx); |
| 225 | XDestroyWindow(dpy, win); |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | |
| 229 | static const char * |
| 230 | visual_class_name(int cls) |
| 231 | { |
| 232 | switch (cls) { |
| 233 | case StaticColor: |
| 234 | return "StaticColor"; |
| 235 | case PseudoColor: |
| 236 | return "PseudoColor"; |
| 237 | case StaticGray: |
| 238 | return "StaticGray"; |
| 239 | case GrayScale: |
| 240 | return "GrayScale"; |
| 241 | case TrueColor: |
| 242 | return "TrueColor"; |
| 243 | case DirectColor: |
| 244 | return "DirectColor"; |
| 245 | default: |
| 246 | return ""; |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | |
| 251 | static const char * |
| 252 | visual_class_abbrev(int cls) |
| 253 | { |
| 254 | switch (cls) { |
| 255 | case StaticColor: |
| 256 | return "sc"; |
| 257 | case PseudoColor: |
| 258 | return "pc"; |
| 259 | case StaticGray: |
| 260 | return "sg"; |
| 261 | case GrayScale: |
| 262 | return "gs"; |
| 263 | case TrueColor: |
| 264 | return "tc"; |
| 265 | case DirectColor: |
| 266 | return "dc"; |
| 267 | default: |
| 268 | return ""; |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | |
| 273 | static void |
| 274 | get_visual_attribs(Display *dpy, XVisualInfo *vInfo, |
| 275 | struct visual_attribs *attribs) |
| 276 | { |
Brian Paul | 25673f0 | 2000-03-31 18:17:51 +0000 | [diff] [blame] | 277 | const char *ext = glXQueryExtensionsString(dpy, vInfo->screen); |
| 278 | |
Brian Paul | a9c53fa | 2000-04-03 15:45:34 +0000 | [diff] [blame] | 279 | memset(attribs, 0, sizeof(struct visual_attribs)); |
| 280 | |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 281 | attribs->id = vInfo->visualid; |
| 282 | #if defined(__cplusplus) || defined(c_plusplus) |
| 283 | attribs->klass = vInfo->c_class; |
| 284 | #else |
| 285 | attribs->klass = vInfo->class; |
| 286 | #endif |
| 287 | attribs->depth = vInfo->depth; |
| 288 | attribs->redMask = vInfo->red_mask; |
| 289 | attribs->greenMask = vInfo->green_mask; |
| 290 | attribs->blueMask = vInfo->blue_mask; |
| 291 | attribs->colormapSize = vInfo->colormap_size; |
| 292 | attribs->bitsPerRGB = vInfo->bits_per_rgb; |
| 293 | |
Brian Paul | a9c53fa | 2000-04-03 15:45:34 +0000 | [diff] [blame] | 294 | if (glXGetConfig(dpy, vInfo, GLX_USE_GL, &attribs->supportsGL) != 0) |
| 295 | return; |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 296 | glXGetConfig(dpy, vInfo, GLX_BUFFER_SIZE, &attribs->bufferSize); |
| 297 | glXGetConfig(dpy, vInfo, GLX_LEVEL, &attribs->level); |
| 298 | glXGetConfig(dpy, vInfo, GLX_RGBA, &attribs->rgba); |
| 299 | glXGetConfig(dpy, vInfo, GLX_DOUBLEBUFFER, &attribs->doubleBuffer); |
| 300 | glXGetConfig(dpy, vInfo, GLX_STEREO, &attribs->stereo); |
| 301 | glXGetConfig(dpy, vInfo, GLX_AUX_BUFFERS, &attribs->auxBuffers); |
| 302 | glXGetConfig(dpy, vInfo, GLX_RED_SIZE, &attribs->redSize); |
| 303 | glXGetConfig(dpy, vInfo, GLX_GREEN_SIZE, &attribs->greenSize); |
| 304 | glXGetConfig(dpy, vInfo, GLX_BLUE_SIZE, &attribs->blueSize); |
| 305 | glXGetConfig(dpy, vInfo, GLX_ALPHA_SIZE, &attribs->alphaSize); |
| 306 | glXGetConfig(dpy, vInfo, GLX_DEPTH_SIZE, &attribs->depthSize); |
| 307 | glXGetConfig(dpy, vInfo, GLX_STENCIL_SIZE, &attribs->stencilSize); |
| 308 | glXGetConfig(dpy, vInfo, GLX_ACCUM_RED_SIZE, &attribs->accumRedSize); |
| 309 | glXGetConfig(dpy, vInfo, GLX_ACCUM_GREEN_SIZE, &attribs->accumGreenSize); |
| 310 | glXGetConfig(dpy, vInfo, GLX_ACCUM_BLUE_SIZE, &attribs->accumBlueSize); |
| 311 | glXGetConfig(dpy, vInfo, GLX_ACCUM_ALPHA_SIZE, &attribs->accumAlphaSize); |
| 312 | |
Brian Paul | e06c7f3 | 2000-01-27 16:53:55 +0000 | [diff] [blame] | 313 | /* transparent pixel value not implemented yet */ |
| 314 | attribs->transparent = 0; |
| 315 | |
| 316 | /* multisample tests not implemented yet */ |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 317 | attribs->numSamples = 0; |
| 318 | attribs->numMultisample = 0; |
Brian Paul | 25673f0 | 2000-03-31 18:17:51 +0000 | [diff] [blame] | 319 | |
| 320 | #if defined(GLX_EXT_visual_rating) |
| 321 | if (ext && strstr(ext, "GLX_EXT_visual_rating")) { |
| 322 | glXGetConfig(dpy, vInfo, GLX_VISUAL_CAVEAT_EXT, &attribs->visualCaveat); |
| 323 | } |
| 324 | else { |
| 325 | attribs->visualCaveat = GLX_NONE_EXT; |
| 326 | } |
| 327 | #else |
| 328 | attribs->visualCaveat = 0; |
| 329 | #endif |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | |
| 333 | static void |
| 334 | print_visual_attribs_verbose(const struct visual_attribs *attribs) |
| 335 | { |
| 336 | printf("Visual ID: %x depth=%d class=%s\n", |
| 337 | attribs->id, attribs->depth, visual_class_name(attribs->klass)); |
| 338 | printf(" bufferSize=%d level=%d renderType=%s doubleBuffer=%d stereo=%d\n", |
| 339 | attribs->bufferSize, attribs->level, attribs->rgba ? "rgba" : "ci", |
| 340 | attribs->doubleBuffer, attribs->stereo); |
| 341 | printf(" rgba: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n", |
| 342 | attribs->redSize, attribs->greenSize, |
| 343 | attribs->blueSize, attribs->alphaSize); |
| 344 | printf(" auxBuffers=%d depthSize=%d stencilSize=%d\n", |
| 345 | attribs->auxBuffers, attribs->depthSize, attribs->stencilSize); |
| 346 | printf(" accum: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n", |
| 347 | attribs->accumRedSize, attribs->accumGreenSize, |
| 348 | attribs->accumBlueSize, attribs->accumAlphaSize); |
| 349 | printf(" multiSample=%d multiSampleBuffers=%d\n", |
| 350 | attribs->numSamples, attribs->numMultisample); |
Brian Paul | 25673f0 | 2000-03-31 18:17:51 +0000 | [diff] [blame] | 351 | #ifdef GLX_EXT_visual_rating |
| 352 | if (attribs->visualCaveat == GLX_NONE_EXT || attribs->visualCaveat == 0) |
Brian Paul | a9c53fa | 2000-04-03 15:45:34 +0000 | [diff] [blame] | 353 | printf(" visualCaveat=None\n"); |
Brian Paul | 25673f0 | 2000-03-31 18:17:51 +0000 | [diff] [blame] | 354 | else if (attribs->visualCaveat == GLX_SLOW_VISUAL_EXT) |
Brian Paul | a9c53fa | 2000-04-03 15:45:34 +0000 | [diff] [blame] | 355 | printf(" visualCaveat=Slow\n"); |
Brian Paul | 25673f0 | 2000-03-31 18:17:51 +0000 | [diff] [blame] | 356 | else if (attribs->visualCaveat == GLX_NON_CONFORMANT_VISUAL_EXT) |
Brian Paul | a9c53fa | 2000-04-03 15:45:34 +0000 | [diff] [blame] | 357 | printf(" visualCaveat=Nonconformant\n"); |
Brian Paul | 25673f0 | 2000-03-31 18:17:51 +0000 | [diff] [blame] | 358 | #endif |
Brian Paul | a9c53fa | 2000-04-03 15:45:34 +0000 | [diff] [blame] | 359 | printf(" %s\n", attribs->transparent ? "Transparent." : "Opaque."); |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | |
| 363 | static void |
| 364 | print_visual_attribs_short_header(void) |
| 365 | { |
Brian Paul | a9c53fa | 2000-04-03 15:45:34 +0000 | [diff] [blame] | 366 | printf(" visual x bf lv rg d st colorbuffer ax dp st accumbuffer ms cav\n"); |
| 367 | 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] | 368 | printf("----------------------------------------------------------------------\n"); |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | |
| 372 | static void |
| 373 | print_visual_attribs_short(const struct visual_attribs *attribs) |
| 374 | { |
Brian Paul | 25673f0 | 2000-03-31 18:17:51 +0000 | [diff] [blame] | 375 | char *caveat; |
| 376 | #ifdef GLX_EXT_visual_rating |
| 377 | if (attribs->visualCaveat == GLX_NONE_EXT || attribs->visualCaveat == 0) |
| 378 | caveat = "None"; |
| 379 | else if (attribs->visualCaveat == GLX_SLOW_VISUAL_EXT) |
| 380 | caveat = "Slow"; |
| 381 | else if (attribs->visualCaveat == GLX_NON_CONFORMANT_VISUAL_EXT) |
| 382 | caveat = "Ncon"; |
| 383 | #else |
| 384 | caveat = "None"; |
| 385 | #endif |
| 386 | |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 387 | printf("0x%2x %2d %2s %2d %2d %2d %1s %2s %2s %2d %2d %2d %2d %2d %2d %2d", |
| 388 | attribs->id, |
| 389 | attribs->depth, |
| 390 | visual_class_abbrev(attribs->klass), |
| 391 | attribs->transparent, |
| 392 | attribs->bufferSize, |
| 393 | attribs->level, |
| 394 | attribs->rgba ? "r" : "c", |
| 395 | attribs->doubleBuffer ? "y" : ".", |
| 396 | attribs->stereo ? "y" : ".", |
| 397 | attribs->redSize, attribs->greenSize, |
| 398 | attribs->blueSize, attribs->alphaSize, |
| 399 | attribs->auxBuffers, |
| 400 | attribs->depthSize, |
| 401 | attribs->stencilSize |
| 402 | ); |
| 403 | |
Brian Paul | 25673f0 | 2000-03-31 18:17:51 +0000 | [diff] [blame] | 404 | printf(" %2d %2d %2d %2d %2d %1d %s\n", |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 405 | attribs->accumRedSize, attribs->accumGreenSize, |
| 406 | attribs->accumBlueSize, attribs->accumAlphaSize, |
Brian Paul | 25673f0 | 2000-03-31 18:17:51 +0000 | [diff] [blame] | 407 | attribs->numSamples, attribs->numMultisample, |
| 408 | caveat |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 409 | ); |
| 410 | } |
| 411 | |
| 412 | |
| 413 | static void |
| 414 | print_visual_attribs_long_header(void) |
| 415 | { |
| 416 | printf("Vis Vis Visual Trans buff lev render DB ste r g b a aux dep ste accum buffers MS MS\n"); |
| 417 | printf(" ID Depth Type parent size el type reo sz sz sz sz buf th ncl r g b a num bufs\n"); |
| 418 | printf("----------------------------------------------------------------------------------------------------\n"); |
| 419 | } |
| 420 | |
| 421 | |
| 422 | static void |
| 423 | print_visual_attribs_long(const struct visual_attribs *attribs) |
| 424 | { |
| 425 | printf("0x%2x %2d %-11s %2d %2d %2d %4s %3d %3d %3d %3d %3d %3d", |
| 426 | attribs->id, |
| 427 | attribs->depth, |
| 428 | visual_class_name(attribs->klass), |
| 429 | attribs->transparent, |
| 430 | attribs->bufferSize, |
| 431 | attribs->level, |
| 432 | attribs->rgba ? "rgba" : "ci ", |
| 433 | attribs->doubleBuffer, |
| 434 | attribs->stereo, |
| 435 | attribs->redSize, attribs->greenSize, |
| 436 | attribs->blueSize, attribs->alphaSize |
| 437 | ); |
| 438 | |
| 439 | printf(" %3d %4d %2d %3d %3d %3d %3d %2d %2d\n", |
| 440 | attribs->auxBuffers, |
| 441 | attribs->depthSize, |
| 442 | attribs->stencilSize, |
| 443 | attribs->accumRedSize, attribs->accumGreenSize, |
| 444 | attribs->accumBlueSize, attribs->accumAlphaSize, |
| 445 | attribs->numSamples, attribs->numMultisample |
| 446 | ); |
| 447 | } |
| 448 | |
| 449 | |
| 450 | static void |
| 451 | print_visual_info(Display *dpy, int scrnum, InfoMode mode) |
| 452 | { |
| 453 | XVisualInfo template; |
| 454 | XVisualInfo *visuals; |
| 455 | int numVisuals; |
| 456 | long mask; |
| 457 | int i; |
| 458 | |
| 459 | /* get list of all visuals on this screen */ |
| 460 | template.screen = scrnum; |
| 461 | mask = VisualScreenMask; |
| 462 | visuals = XGetVisualInfo(dpy, mask, &template, &numVisuals); |
| 463 | |
| 464 | if (mode == Verbose) { |
| 465 | for (i = 0; i < numVisuals; i++) { |
| 466 | struct visual_attribs attribs; |
| 467 | get_visual_attribs(dpy, &visuals[i], &attribs); |
| 468 | print_visual_attribs_verbose(&attribs); |
| 469 | } |
| 470 | } |
| 471 | else if (mode == Normal) { |
| 472 | print_visual_attribs_short_header(); |
| 473 | for (i = 0; i < numVisuals; i++) { |
| 474 | struct visual_attribs attribs; |
| 475 | get_visual_attribs(dpy, &visuals[i], &attribs); |
| 476 | print_visual_attribs_short(&attribs); |
| 477 | } |
| 478 | } |
| 479 | else if (mode == Wide) { |
| 480 | print_visual_attribs_long_header(); |
| 481 | for (i = 0; i < numVisuals; i++) { |
| 482 | struct visual_attribs attribs; |
| 483 | get_visual_attribs(dpy, &visuals[i], &attribs); |
| 484 | print_visual_attribs_long(&attribs); |
| 485 | } |
| 486 | } |
| 487 | |
| 488 | XFree(visuals); |
| 489 | } |
| 490 | |
| 491 | |
| 492 | int |
| 493 | main(int argc, char *argv[]) |
| 494 | { |
| 495 | char *displayName = ":0"; |
| 496 | Display *dpy; |
| 497 | int numScreens, scrnum; |
| 498 | InfoMode mode = Normal; |
| 499 | int i; |
| 500 | |
| 501 | for (i = 1; i < argc; i++) { |
| 502 | if (strcmp(argv[i], "-display") == 0 && i + 1 < argc) { |
| 503 | displayName = argv[i + 1]; |
| 504 | i++; |
| 505 | } |
| 506 | else if (strcmp(argv[i], "-t") == 0) { |
| 507 | mode = Wide; |
| 508 | } |
| 509 | else if (strcmp(argv[i], "-v") == 0) { |
| 510 | mode = Verbose; |
| 511 | } |
| 512 | } |
| 513 | |
| 514 | dpy = XOpenDisplay(displayName); |
| 515 | if (!dpy) { |
| 516 | fprintf(stderr, "Error: unable to open display %s\n", displayName); |
| 517 | return -1; |
| 518 | } |
| 519 | |
| 520 | numScreens = ScreenCount(dpy); |
| 521 | for (scrnum = 0; scrnum < numScreens; scrnum++) { |
Brian Paul | e691ee2 | 2000-05-08 14:53:57 +0000 | [diff] [blame^] | 522 | print_screen_info(dpy, scrnum); |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 523 | printf("\n"); |
Brian Paul | e691ee2 | 2000-05-08 14:53:57 +0000 | [diff] [blame^] | 524 | print_visual_info(dpy, scrnum, mode); |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 525 | if (scrnum + 1 < numScreens) |
| 526 | printf("\n\n"); |
| 527 | } |
| 528 | |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 529 | XCloseDisplay(dpy); |
| 530 | |
| 531 | return 0; |
| 532 | } |