Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 1 | /* |
Brian Paul | ad7805d | 2006-05-13 00:18:12 +0000 | [diff] [blame] | 2 | * Copyright (C) 1999-2006 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 | 2ca741a | 2006-05-15 15:35:38 +0000 | [diff] [blame] | 36 | #define GLX_GLXEXT_PROTOTYPES |
| 37 | |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 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 | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 41 | #include <GL/glx.h> |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 42 | #include <stdio.h> |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 43 | #include <string.h> |
Brian Paul | 373aea1 | 2001-04-02 22:45:07 +0000 | [diff] [blame] | 44 | #include <stdlib.h> |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 45 | |
| 46 | |
Brian Paul | 39557c3 | 2001-03-23 21:41:44 +0000 | [diff] [blame] | 47 | #ifndef GLX_NONE_EXT |
| 48 | #define GLX_NONE_EXT 0x8000 |
| 49 | #endif |
| 50 | |
Brian Paul | 45c5698 | 2002-10-14 13:57:23 +0000 | [diff] [blame] | 51 | #ifndef GLX_TRANSPARENT_RGB |
| 52 | #define GLX_TRANSPARENT_RGB 0x8008 |
| 53 | #endif |
Brian Paul | 39557c3 | 2001-03-23 21:41:44 +0000 | [diff] [blame] | 54 | |
Kristian Høgsberg | 791ad0e | 2007-10-16 16:01:34 -0400 | [diff] [blame] | 55 | #ifndef GLX_RGBA_BIT |
| 56 | #define GLX_RGBA_BIT 0x00000001 |
| 57 | #endif |
| 58 | |
| 59 | #ifndef GLX_COLOR_INDEX_BIT |
| 60 | #define GLX_COLOR_INDEX_BIT 0x00000002 |
| 61 | #endif |
Brian Paul | 2ca741a | 2006-05-15 15:35:38 +0000 | [diff] [blame] | 62 | |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 63 | typedef enum |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 64 | { |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 65 | Normal, |
| 66 | Wide, |
| 67 | Verbose |
| 68 | } InfoMode; |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 69 | |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 70 | |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 71 | struct visual_attribs |
| 72 | { |
| 73 | /* X visual attribs */ |
| 74 | int id; |
| 75 | int klass; |
| 76 | int depth; |
| 77 | int redMask, greenMask, blueMask; |
| 78 | int colormapSize; |
| 79 | int bitsPerRGB; |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 80 | |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 81 | /* GL visual attribs */ |
| 82 | int supportsGL; |
Brian Paul | 45c5698 | 2002-10-14 13:57:23 +0000 | [diff] [blame] | 83 | int transparentType; |
| 84 | int transparentRedValue; |
| 85 | int transparentGreenValue; |
| 86 | int transparentBlueValue; |
| 87 | int transparentAlphaValue; |
| 88 | int transparentIndexValue; |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 89 | int bufferSize; |
| 90 | int level; |
Kristian Høgsberg | 791ad0e | 2007-10-16 16:01:34 -0400 | [diff] [blame] | 91 | int render_type; |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 92 | int doubleBuffer; |
| 93 | int stereo; |
| 94 | int auxBuffers; |
| 95 | int redSize, greenSize, blueSize, alphaSize; |
| 96 | int depthSize; |
| 97 | int stencilSize; |
| 98 | int accumRedSize, accumGreenSize, accumBlueSize, accumAlphaSize; |
| 99 | int numSamples, numMultisample; |
Brian Paul | 25673f0 | 2000-03-31 18:17:51 +0000 | [diff] [blame] | 100 | int visualCaveat; |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 101 | }; |
| 102 | |
| 103 | |
| 104 | /* |
| 105 | * Print a list of extensions, with word-wrapping. |
| 106 | */ |
| 107 | static void |
| 108 | print_extension_list(const char *ext) |
| 109 | { |
| 110 | const char *indentString = " "; |
| 111 | const int indent = 4; |
| 112 | const int max = 79; |
| 113 | int width, i, j; |
| 114 | |
| 115 | if (!ext || !ext[0]) |
| 116 | return; |
| 117 | |
| 118 | width = indent; |
| 119 | printf(indentString); |
| 120 | i = j = 0; |
| 121 | while (1) { |
| 122 | if (ext[j] == ' ' || ext[j] == 0) { |
| 123 | /* found end of an extension name */ |
| 124 | const int len = j - i; |
| 125 | if (width + len > max) { |
| 126 | /* start a new line */ |
| 127 | printf("\n"); |
| 128 | width = indent; |
| 129 | printf(indentString); |
| 130 | } |
| 131 | /* print the extension name between ext[i] and ext[j] */ |
| 132 | while (i < j) { |
| 133 | printf("%c", ext[i]); |
| 134 | i++; |
| 135 | } |
| 136 | /* either we're all done, or we'll continue with next extension */ |
| 137 | width += len + 1; |
| 138 | if (ext[j] == 0) { |
| 139 | break; |
| 140 | } |
| 141 | else { |
| 142 | i++; |
| 143 | j++; |
Brian Paul | 7ac4350 | 2000-02-23 22:50:35 +0000 | [diff] [blame] | 144 | if (ext[j] == 0) |
| 145 | break; |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 146 | printf(", "); |
| 147 | width += 2; |
| 148 | } |
| 149 | } |
| 150 | j++; |
| 151 | } |
| 152 | printf("\n"); |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 156 | static void |
Brian Paul | 373aea1 | 2001-04-02 22:45:07 +0000 | [diff] [blame] | 157 | print_display_info(Display *dpy) |
| 158 | { |
| 159 | printf("name of display: %s\n", DisplayString(dpy)); |
| 160 | } |
| 161 | |
| 162 | |
Brian Paul | ad7805d | 2006-05-13 00:18:12 +0000 | [diff] [blame] | 163 | /** |
| 164 | * Print interesting limits for vertex/fragment programs. |
| 165 | */ |
Brian Paul | 373aea1 | 2001-04-02 22:45:07 +0000 | [diff] [blame] | 166 | static void |
Brian Paul | ad7805d | 2006-05-13 00:18:12 +0000 | [diff] [blame] | 167 | print_program_limits(GLenum target) |
| 168 | { |
| 169 | #if defined(GL_ARB_vertex_program) || defined(GL_ARB_fragment_program) |
| 170 | struct token_name { |
| 171 | GLenum token; |
| 172 | const char *name; |
| 173 | }; |
| 174 | static const struct token_name limits[] = { |
| 175 | { GL_MAX_PROGRAM_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_INSTRUCTIONS_ARB" }, |
| 176 | { GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB" }, |
| 177 | { GL_MAX_PROGRAM_TEMPORARIES_ARB, "GL_MAX_PROGRAM_TEMPORARIES_ARB" }, |
| 178 | { GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB, "GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB" }, |
| 179 | { GL_MAX_PROGRAM_PARAMETERS_ARB, "GL_MAX_PROGRAM_PARAMETERS_ARB" }, |
| 180 | { GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB, "GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB" }, |
| 181 | { GL_MAX_PROGRAM_ATTRIBS_ARB, "GL_MAX_PROGRAM_ATTRIBS_ARB" }, |
| 182 | { GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB, "GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB" }, |
| 183 | { GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB, "GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB" }, |
| 184 | { GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB, "GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB" }, |
| 185 | { GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB, "GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB" }, |
| 186 | { GL_MAX_PROGRAM_ENV_PARAMETERS_ARB, "GL_MAX_PROGRAM_ENV_PARAMETERS_ARB" }, |
| 187 | { GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB" }, |
| 188 | { GL_MAX_PROGRAM_TEX_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_TEX_INSTRUCTIONS_ARB" }, |
| 189 | { GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB, "GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB" }, |
| 190 | { GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB" }, |
| 191 | { GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB" }, |
| 192 | { GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB, "GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB" }, |
| 193 | { (GLenum) 0, NULL } |
| 194 | }; |
| 195 | PFNGLGETPROGRAMIVARBPROC GetProgramivARB_func = (PFNGLGETPROGRAMIVARBPROC) |
| 196 | glXGetProcAddressARB((GLubyte *) "glGetProgramivARB"); |
| 197 | GLint max[1]; |
| 198 | int i; |
| 199 | |
| 200 | if (target == GL_VERTEX_PROGRAM_ARB) { |
| 201 | printf(" GL_VERTEX_PROGRAM_ARB:\n"); |
| 202 | } |
| 203 | else if (target == GL_FRAGMENT_PROGRAM_ARB) { |
| 204 | printf(" GL_FRAGMENT_PROGRAM_ARB:\n"); |
| 205 | } |
| 206 | else { |
| 207 | return; /* something's wrong */ |
| 208 | } |
| 209 | |
| 210 | for (i = 0; limits[i].token; i++) { |
| 211 | GetProgramivARB_func(target, limits[i].token, max); |
| 212 | if (glGetError() == GL_NO_ERROR) { |
| 213 | printf(" %s = %d\n", limits[i].name, max[0]); |
| 214 | } |
| 215 | } |
Brian Paul | 2ca741a | 2006-05-15 15:35:38 +0000 | [diff] [blame] | 216 | #endif /* GL_ARB_vertex_program / GL_ARB_fragment_program */ |
Brian Paul | ad7805d | 2006-05-13 00:18:12 +0000 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | |
| 220 | /** |
| 221 | * Print interesting limits for vertex/fragment shaders. |
| 222 | */ |
| 223 | static void |
| 224 | print_shader_limits(GLenum target) |
| 225 | { |
| 226 | struct token_name { |
| 227 | GLenum token; |
| 228 | const char *name; |
| 229 | }; |
| 230 | #if defined(GL_ARB_vertex_shader) |
| 231 | static const struct token_name vertex_limits[] = { |
| 232 | { GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB, "GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB" }, |
| 233 | { GL_MAX_VARYING_FLOATS_ARB, "GL_MAX_VARYING_FLOATS_ARB" }, |
| 234 | { GL_MAX_VERTEX_ATTRIBS_ARB, "GL_MAX_VERTEX_ATTRIBS_ARB" }, |
| 235 | { GL_MAX_TEXTURE_IMAGE_UNITS_ARB, "GL_MAX_TEXTURE_IMAGE_UNITS_ARB" }, |
| 236 | { GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB, "GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB" }, |
| 237 | { GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB, "GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB" }, |
| 238 | { GL_MAX_TEXTURE_COORDS_ARB, "GL_MAX_TEXTURE_COORDS_ARB" }, |
| 239 | { (GLenum) 0, NULL } |
| 240 | }; |
| 241 | #endif |
| 242 | #if defined(GL_ARB_fragment_shader) |
| 243 | static const struct token_name fragment_limits[] = { |
| 244 | { GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB, "GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB" }, |
| 245 | { GL_MAX_TEXTURE_COORDS_ARB, "GL_MAX_TEXTURE_COORDS_ARB" }, |
| 246 | { GL_MAX_TEXTURE_IMAGE_UNITS_ARB, "GL_MAX_TEXTURE_IMAGE_UNITS_ARB" }, |
| 247 | { (GLenum) 0, NULL } |
| 248 | }; |
| 249 | #endif |
| 250 | GLint max[1]; |
| 251 | int i; |
| 252 | |
| 253 | #if defined(GL_ARB_vertex_shader) |
| 254 | if (target == GL_VERTEX_SHADER_ARB) { |
| 255 | printf(" GL_VERTEX_SHADER_ARB:\n"); |
| 256 | for (i = 0; vertex_limits[i].token; i++) { |
| 257 | glGetIntegerv(vertex_limits[i].token, max); |
| 258 | if (glGetError() == GL_NO_ERROR) { |
| 259 | printf(" %s = %d\n", vertex_limits[i].name, max[0]); |
| 260 | } |
| 261 | } |
| 262 | } |
| 263 | #endif |
| 264 | #if defined(GL_ARB_fragment_shader) |
| 265 | if (target == GL_FRAGMENT_SHADER_ARB) { |
| 266 | printf(" GL_FRAGMENT_SHADER_ARB:\n"); |
| 267 | for (i = 0; fragment_limits[i].token; i++) { |
| 268 | glGetIntegerv(fragment_limits[i].token, max); |
| 269 | if (glGetError() == GL_NO_ERROR) { |
| 270 | printf(" %s = %d\n", fragment_limits[i].name, max[0]); |
| 271 | } |
| 272 | } |
| 273 | } |
| 274 | #endif |
| 275 | } |
| 276 | |
| 277 | |
| 278 | /** |
| 279 | * Print interesting OpenGL implementation limits. |
| 280 | */ |
| 281 | static void |
| 282 | print_limits(const char *extensions) |
Brian Paul | 2f7ef5f | 2002-09-06 03:35:43 +0000 | [diff] [blame] | 283 | { |
| 284 | struct token_name { |
| 285 | GLuint count; |
| 286 | GLenum token; |
| 287 | const char *name; |
| 288 | }; |
| 289 | static const struct token_name limits[] = { |
| 290 | { 1, GL_MAX_ATTRIB_STACK_DEPTH, "GL_MAX_ATTRIB_STACK_DEPTH" }, |
| 291 | { 1, GL_MAX_CLIENT_ATTRIB_STACK_DEPTH, "GL_MAX_CLIENT_ATTRIB_STACK_DEPTH" }, |
| 292 | { 1, GL_MAX_CLIP_PLANES, "GL_MAX_CLIP_PLANES" }, |
| 293 | { 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] | 294 | { 1, GL_MAX_ELEMENTS_VERTICES, "GL_MAX_ELEMENTS_VERTICES" }, |
| 295 | { 1, GL_MAX_ELEMENTS_INDICES, "GL_MAX_ELEMENTS_INDICES" }, |
| 296 | { 1, GL_MAX_EVAL_ORDER, "GL_MAX_EVAL_ORDER" }, |
| 297 | { 1, GL_MAX_LIGHTS, "GL_MAX_LIGHTS" }, |
| 298 | { 1, GL_MAX_LIST_NESTING, "GL_MAX_LIST_NESTING" }, |
| 299 | { 1, GL_MAX_MODELVIEW_STACK_DEPTH, "GL_MAX_MODELVIEW_STACK_DEPTH" }, |
| 300 | { 1, GL_MAX_NAME_STACK_DEPTH, "GL_MAX_NAME_STACK_DEPTH" }, |
| 301 | { 1, GL_MAX_PIXEL_MAP_TABLE, "GL_MAX_PIXEL_MAP_TABLE" }, |
| 302 | { 1, GL_MAX_PROJECTION_STACK_DEPTH, "GL_MAX_PROJECTION_STACK_DEPTH" }, |
| 303 | { 1, GL_MAX_TEXTURE_STACK_DEPTH, "GL_MAX_TEXTURE_STACK_DEPTH" }, |
| 304 | { 1, GL_MAX_TEXTURE_SIZE, "GL_MAX_TEXTURE_SIZE" }, |
| 305 | { 1, GL_MAX_3D_TEXTURE_SIZE, "GL_MAX_3D_TEXTURE_SIZE" }, |
Brian Paul | 2f7ef5f | 2002-09-06 03:35:43 +0000 | [diff] [blame] | 306 | { 2, GL_MAX_VIEWPORT_DIMS, "GL_MAX_VIEWPORT_DIMS" }, |
| 307 | { 2, GL_ALIASED_LINE_WIDTH_RANGE, "GL_ALIASED_LINE_WIDTH_RANGE" }, |
| 308 | { 2, GL_SMOOTH_LINE_WIDTH_RANGE, "GL_SMOOTH_LINE_WIDTH_RANGE" }, |
| 309 | { 2, GL_ALIASED_POINT_SIZE_RANGE, "GL_ALIASED_POINT_SIZE_RANGE" }, |
| 310 | { 2, GL_SMOOTH_POINT_SIZE_RANGE, "GL_SMOOTH_POINT_SIZE_RANGE" }, |
Brian Paul | ad7805d | 2006-05-13 00:18:12 +0000 | [diff] [blame] | 311 | #if defined(GL_ARB_texture_cube_map) |
| 312 | { 1, GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB, "GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB" }, |
| 313 | #endif |
| 314 | #if defined(GLX_NV_texture_rectangle) |
| 315 | { 1, GL_MAX_RECTANGLE_TEXTURE_SIZE_NV, "GL_MAX_RECTANGLE_TEXTURE_SIZE_NV" }, |
| 316 | #endif |
| 317 | #if defined(GL_ARB_texture_compression) |
| 318 | { 1, GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB, "GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB" }, |
| 319 | #endif |
| 320 | #if defined(GL_ARB_multitexture) |
| 321 | { 1, GL_MAX_TEXTURE_UNITS_ARB, "GL_MAX_TEXTURE_UNITS_ARB" }, |
| 322 | #endif |
| 323 | #if defined(GL_EXT_texture_lod_bias) |
| 324 | { 1, GL_MAX_TEXTURE_LOD_BIAS_EXT, "GL_MAX_TEXTURE_LOD_BIAS_EXT" }, |
| 325 | #endif |
| 326 | #if defined(GL_EXT_texture_filter_anisotropic) |
| 327 | { 1, GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, "GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT" }, |
| 328 | #endif |
| 329 | #if defined(GL_ARB_draw_buffers) |
| 330 | { 1, GL_MAX_DRAW_BUFFERS_ARB, "GL_MAX_DRAW_BUFFERS_ARB" }, |
| 331 | #endif |
Brian Paul | 2f7ef5f | 2002-09-06 03:35:43 +0000 | [diff] [blame] | 332 | { 0, (GLenum) 0, NULL } |
| 333 | }; |
| 334 | GLint i, max[2]; |
Brian Paul | ad7805d | 2006-05-13 00:18:12 +0000 | [diff] [blame] | 335 | |
Brian Paul | 2f7ef5f | 2002-09-06 03:35:43 +0000 | [diff] [blame] | 336 | printf("OpenGL limits:\n"); |
| 337 | for (i = 0; limits[i].count; i++) { |
| 338 | glGetIntegerv(limits[i].token, max); |
Brian Paul | ad7805d | 2006-05-13 00:18:12 +0000 | [diff] [blame] | 339 | if (glGetError() == GL_NO_ERROR) { |
Brian Paul | 2f7ef5f | 2002-09-06 03:35:43 +0000 | [diff] [blame] | 340 | if (limits[i].count == 1) |
| 341 | printf(" %s = %d\n", limits[i].name, max[0]); |
| 342 | else /* XXX fix if we ever query something with more than 2 values */ |
| 343 | printf(" %s = %d, %d\n", limits[i].name, max[0], max[1]); |
| 344 | } |
| 345 | } |
Brian Paul | ad7805d | 2006-05-13 00:18:12 +0000 | [diff] [blame] | 346 | |
Brian Paul | f2afdca | 2004-08-10 15:32:25 +0000 | [diff] [blame] | 347 | /* these don't fit into the above mechanism, unfortunately */ |
| 348 | glGetConvolutionParameteriv(GL_CONVOLUTION_2D, GL_MAX_CONVOLUTION_WIDTH, max); |
| 349 | glGetConvolutionParameteriv(GL_CONVOLUTION_2D, GL_MAX_CONVOLUTION_HEIGHT, max+1); |
| 350 | if (glGetError() == GL_NONE) { |
| 351 | printf(" GL_MAX_CONVOLUTION_WIDTH/HEIGHT = %d, %d\n", max[0], max[1]); |
| 352 | } |
| 353 | |
Brian Paul | 2ca741a | 2006-05-15 15:35:38 +0000 | [diff] [blame] | 354 | #if defined(GL_ARB_vertex_program) |
Brian Paul | ad7805d | 2006-05-13 00:18:12 +0000 | [diff] [blame] | 355 | if (strstr(extensions, "GL_ARB_vertex_program")) { |
| 356 | print_program_limits(GL_VERTEX_PROGRAM_ARB); |
| 357 | } |
Brian Paul | 2ca741a | 2006-05-15 15:35:38 +0000 | [diff] [blame] | 358 | #endif |
| 359 | #if defined(GL_ARB_fragment_program) |
Brian Paul | ad7805d | 2006-05-13 00:18:12 +0000 | [diff] [blame] | 360 | if (strstr(extensions, "GL_ARB_fragment_program")) { |
| 361 | print_program_limits(GL_FRAGMENT_PROGRAM_ARB); |
| 362 | } |
Brian Paul | 2ca741a | 2006-05-15 15:35:38 +0000 | [diff] [blame] | 363 | #endif |
| 364 | #if defined(GL_ARB_vertex_shader) |
Brian Paul | ad7805d | 2006-05-13 00:18:12 +0000 | [diff] [blame] | 365 | if (strstr(extensions, "GL_ARB_vertex_shader")) { |
| 366 | print_shader_limits(GL_VERTEX_SHADER_ARB); |
| 367 | } |
Brian Paul | 2ca741a | 2006-05-15 15:35:38 +0000 | [diff] [blame] | 368 | #endif |
| 369 | #if defined(GL_ARB_fragment_shader) |
Brian Paul | ad7805d | 2006-05-13 00:18:12 +0000 | [diff] [blame] | 370 | if (strstr(extensions, "GL_ARB_fragment_shader")) { |
| 371 | print_shader_limits(GL_FRAGMENT_SHADER_ARB); |
| 372 | } |
Brian Paul | 2ca741a | 2006-05-15 15:35:38 +0000 | [diff] [blame] | 373 | #endif |
Brian Paul | 2f7ef5f | 2002-09-06 03:35:43 +0000 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | |
| 377 | static void |
| 378 | print_screen_info(Display *dpy, int scrnum, Bool allowDirect, GLboolean limits) |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 379 | { |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 380 | Window win; |
Brian Paul | 8460cc9 | 2000-02-02 20:57:51 +0000 | [diff] [blame] | 381 | int attribSingle[] = { |
| 382 | GLX_RGBA, |
| 383 | GLX_RED_SIZE, 1, |
| 384 | GLX_GREEN_SIZE, 1, |
| 385 | GLX_BLUE_SIZE, 1, |
| 386 | None }; |
| 387 | int attribDouble[] = { |
| 388 | GLX_RGBA, |
| 389 | GLX_RED_SIZE, 1, |
| 390 | GLX_GREEN_SIZE, 1, |
| 391 | GLX_BLUE_SIZE, 1, |
| 392 | GLX_DOUBLEBUFFER, |
| 393 | None }; |
| 394 | |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 395 | XSetWindowAttributes attr; |
| 396 | unsigned long mask; |
| 397 | Window root; |
Kristian Høgsberg | a074857 | 2007-10-18 15:19:08 -0400 | [diff] [blame] | 398 | GLXContext ctx = NULL; |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 399 | XVisualInfo *visinfo; |
| 400 | int width = 100, height = 100; |
| 401 | |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 402 | root = RootWindow(dpy, scrnum); |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 403 | |
Brian Paul | 8460cc9 | 2000-02-02 20:57:51 +0000 | [diff] [blame] | 404 | visinfo = glXChooseVisual(dpy, scrnum, attribSingle); |
Kristian Høgsberg | a074857 | 2007-10-18 15:19:08 -0400 | [diff] [blame] | 405 | if (!visinfo) |
Brian Paul | 8460cc9 | 2000-02-02 20:57:51 +0000 | [diff] [blame] | 406 | visinfo = glXChooseVisual(dpy, scrnum, attribDouble); |
Kristian Høgsberg | a074857 | 2007-10-18 15:19:08 -0400 | [diff] [blame] | 407 | |
| 408 | if (visinfo) |
| 409 | ctx = glXCreateContext( dpy, visinfo, NULL, allowDirect ); |
| 410 | |
| 411 | #ifdef GLX_VERSION_1_3 |
| 412 | { |
| 413 | int fbAttribSingle[] = { |
| 414 | GLX_RENDER_TYPE, GLX_RGBA_BIT, |
| 415 | GLX_RED_SIZE, 1, |
| 416 | GLX_GREEN_SIZE, 1, |
| 417 | GLX_BLUE_SIZE, 1, |
| 418 | GLX_DOUBLEBUFFER, GL_TRUE, |
| 419 | None }; |
| 420 | int fbAttribDouble[] = { |
| 421 | GLX_RENDER_TYPE, GLX_RGBA_BIT, |
| 422 | GLX_RED_SIZE, 1, |
| 423 | GLX_GREEN_SIZE, 1, |
| 424 | GLX_BLUE_SIZE, 1, |
| 425 | None }; |
| 426 | GLXFBConfig *configs = NULL; |
| 427 | int nConfigs; |
| 428 | |
| 429 | if (!visinfo) |
| 430 | configs = glXChooseFBConfig(dpy, scrnum, fbAttribSingle, &nConfigs); |
| 431 | if (!visinfo) |
| 432 | configs = glXChooseFBConfig(dpy, scrnum, fbAttribDouble, &nConfigs); |
| 433 | |
| 434 | if (configs) { |
| 435 | visinfo = glXGetVisualFromFBConfig(dpy, configs[0]); |
| 436 | ctx = glXCreateNewContext(dpy, configs[0], GLX_RGBA_TYPE, NULL, allowDirect); |
| 437 | XFree(configs); |
Brian Paul | 8460cc9 | 2000-02-02 20:57:51 +0000 | [diff] [blame] | 438 | } |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 439 | } |
Kristian Høgsberg | a074857 | 2007-10-18 15:19:08 -0400 | [diff] [blame] | 440 | #endif |
| 441 | |
| 442 | if (!visinfo) { |
| 443 | fprintf(stderr, "Error: couldn't find RGB GLX visual or fbconfig\n"); |
| 444 | return; |
| 445 | } |
| 446 | |
| 447 | if (!ctx) { |
| 448 | fprintf(stderr, "Error: glXCreateContext failed\n"); |
| 449 | XFree(visinfo); |
Kristian Høgsberg | a074857 | 2007-10-18 15:19:08 -0400 | [diff] [blame] | 450 | return; |
| 451 | } |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 452 | |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 453 | attr.background_pixel = 0; |
| 454 | attr.border_pixel = 0; |
Brian Paul | 9cff558 | 2000-05-07 18:07:23 +0000 | [diff] [blame] | 455 | attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone); |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 456 | attr.event_mask = StructureNotifyMask | ExposureMask; |
| 457 | mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 458 | win = XCreateWindow(dpy, root, 0, 0, width, height, |
| 459 | 0, visinfo->depth, InputOutput, |
| 460 | visinfo->visual, mask, &attr); |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 461 | |
Brian Paul | 9cff558 | 2000-05-07 18:07:23 +0000 | [diff] [blame] | 462 | if (glXMakeCurrent(dpy, win, ctx)) { |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 463 | const char *serverVendor = glXQueryServerString(dpy, scrnum, GLX_VENDOR); |
| 464 | const char *serverVersion = glXQueryServerString(dpy, scrnum, GLX_VERSION); |
| 465 | const char *serverExtensions = glXQueryServerString(dpy, scrnum, GLX_EXTENSIONS); |
Brian Paul | 34fb5db | 2000-04-22 20:31:23 +0000 | [diff] [blame] | 466 | const char *clientVendor = glXGetClientString(dpy, GLX_VENDOR); |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 467 | const char *clientVersion = glXGetClientString(dpy, GLX_VERSION); |
| 468 | const char *clientExtensions = glXGetClientString(dpy, GLX_EXTENSIONS); |
| 469 | const char *glxExtensions = glXQueryExtensionsString(dpy, scrnum); |
| 470 | const char *glVendor = (const char *) glGetString(GL_VENDOR); |
| 471 | const char *glRenderer = (const char *) glGetString(GL_RENDERER); |
| 472 | const char *glVersion = (const char *) glGetString(GL_VERSION); |
| 473 | const char *glExtensions = (const char *) glGetString(GL_EXTENSIONS); |
Ian Romanick | c00fbd5 | 2004-02-23 17:37:36 +0000 | [diff] [blame] | 474 | int glxVersionMajor; |
| 475 | int glxVersionMinor; |
Brian Paul | 373aea1 | 2001-04-02 22:45:07 +0000 | [diff] [blame] | 476 | char *displayName = NULL; |
| 477 | char *colon = NULL, *period = NULL; |
Ian Romanick | c00fbd5 | 2004-02-23 17:37:36 +0000 | [diff] [blame] | 478 | |
| 479 | if (! glXQueryVersion( dpy, & glxVersionMajor, & glxVersionMinor )) { |
| 480 | fprintf(stderr, "Error: glXQueryVersion failed\n"); |
| 481 | exit(1); |
| 482 | } |
| 483 | |
Brian Paul | 373aea1 | 2001-04-02 22:45:07 +0000 | [diff] [blame] | 484 | /* Strip the screen number from the display name, if present. */ |
Brian Paul | f02a5f6 | 2002-07-12 15:54:01 +0000 | [diff] [blame] | 485 | if (!(displayName = (char *) malloc(strlen(DisplayString(dpy)) + 1))) { |
Brian Paul | 373aea1 | 2001-04-02 22:45:07 +0000 | [diff] [blame] | 486 | fprintf(stderr, "Error: malloc() failed\n"); |
| 487 | exit(1); |
| 488 | } |
| 489 | strcpy(displayName, DisplayString(dpy)); |
| 490 | colon = strrchr(displayName, ':'); |
| 491 | if (colon) { |
| 492 | period = strchr(colon, '.'); |
| 493 | if (period) |
| 494 | *period = '\0'; |
| 495 | } |
| 496 | printf("display: %s screen: %d\n", displayName, scrnum); |
| 497 | free(displayName); |
Michel Dänzer | b46e359 | 2006-12-06 14:54:43 +0100 | [diff] [blame] | 498 | printf("direct rendering: "); |
| 499 | if (glXIsDirect(dpy, ctx)) { |
| 500 | printf("Yes\n"); |
| 501 | } else { |
| 502 | if (!allowDirect) { |
| 503 | printf("No (-i specified)\n"); |
| 504 | } else if (getenv("LIBGL_ALWAYS_INDIRECT")) { |
| 505 | printf("No (LIBGL_ALWAYS_INDIRECT set)\n"); |
| 506 | } else { |
| 507 | printf("No (If you want to find out why, try setting " |
| 508 | "LIBGL_DEBUG=verbose)\n"); |
| 509 | } |
| 510 | } |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 511 | printf("server glx vendor string: %s\n", serverVendor); |
| 512 | printf("server glx version string: %s\n", serverVersion); |
| 513 | printf("server glx extensions:\n"); |
| 514 | print_extension_list(serverExtensions); |
Brian Paul | 34fb5db | 2000-04-22 20:31:23 +0000 | [diff] [blame] | 515 | printf("client glx vendor string: %s\n", clientVendor); |
| 516 | printf("client glx version string: %s\n", clientVersion); |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 517 | printf("client glx extensions:\n"); |
| 518 | print_extension_list(clientExtensions); |
Ian Romanick | c00fbd5 | 2004-02-23 17:37:36 +0000 | [diff] [blame] | 519 | printf("GLX version: %u.%u\n", glxVersionMajor, glxVersionMinor); |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 520 | printf("GLX extensions:\n"); |
| 521 | print_extension_list(glxExtensions); |
| 522 | printf("OpenGL vendor string: %s\n", glVendor); |
| 523 | printf("OpenGL renderer string: %s\n", glRenderer); |
| 524 | printf("OpenGL version string: %s\n", glVersion); |
Brian Paul | 51bfb6a | 2008-07-24 14:27:11 -0600 | [diff] [blame] | 525 | #ifdef GL_VERSION_2_0 |
| 526 | if (glVersion[0] >= '2' && glVersion[1] == '.') { |
| 527 | char *v = (char *) glGetString(GL_SHADING_LANGUAGE_VERSION); |
| 528 | printf("OpenGL shading language version string: %s\n", v); |
| 529 | } |
| 530 | #endif |
| 531 | |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 532 | printf("OpenGL extensions:\n"); |
| 533 | print_extension_list(glExtensions); |
Brian Paul | 2f7ef5f | 2002-09-06 03:35:43 +0000 | [diff] [blame] | 534 | if (limits) |
Brian Paul | ad7805d | 2006-05-13 00:18:12 +0000 | [diff] [blame] | 535 | print_limits(glExtensions); |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 536 | } |
Brian Paul | 9cff558 | 2000-05-07 18:07:23 +0000 | [diff] [blame] | 537 | else { |
| 538 | fprintf(stderr, "Error: glXMakeCurrent failed\n"); |
| 539 | } |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 540 | |
| 541 | glXDestroyContext(dpy, ctx); |
Brian Paul | 361bccb | 2006-01-16 16:17:18 +0000 | [diff] [blame] | 542 | XFree(visinfo); |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 543 | XDestroyWindow(dpy, win); |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | |
| 547 | static const char * |
| 548 | visual_class_name(int cls) |
| 549 | { |
| 550 | switch (cls) { |
| 551 | case StaticColor: |
| 552 | return "StaticColor"; |
| 553 | case PseudoColor: |
| 554 | return "PseudoColor"; |
| 555 | case StaticGray: |
| 556 | return "StaticGray"; |
| 557 | case GrayScale: |
| 558 | return "GrayScale"; |
| 559 | case TrueColor: |
| 560 | return "TrueColor"; |
| 561 | case DirectColor: |
| 562 | return "DirectColor"; |
| 563 | default: |
| 564 | return ""; |
| 565 | } |
| 566 | } |
| 567 | |
| 568 | |
| 569 | static const char * |
| 570 | visual_class_abbrev(int cls) |
| 571 | { |
| 572 | switch (cls) { |
| 573 | case StaticColor: |
| 574 | return "sc"; |
| 575 | case PseudoColor: |
| 576 | return "pc"; |
| 577 | case StaticGray: |
| 578 | return "sg"; |
| 579 | case GrayScale: |
| 580 | return "gs"; |
| 581 | case TrueColor: |
| 582 | return "tc"; |
| 583 | case DirectColor: |
| 584 | return "dc"; |
| 585 | default: |
| 586 | return ""; |
| 587 | } |
| 588 | } |
| 589 | |
Kristian Høgsberg | 791ad0e | 2007-10-16 16:01:34 -0400 | [diff] [blame] | 590 | static const char * |
| 591 | visual_render_type_name(int type) |
| 592 | { |
| 593 | switch (type) { |
| 594 | case GLX_RGBA_BIT: |
| 595 | return "rgba"; |
| 596 | case GLX_COLOR_INDEX_BIT: |
| 597 | return "ci"; |
| 598 | case GLX_RGBA_BIT | GLX_COLOR_INDEX_BIT: |
| 599 | return "rgba|ci"; |
| 600 | default: |
| 601 | return ""; |
| 602 | } |
| 603 | } |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 604 | |
Kristian Høgsberg | f7d1d55 | 2007-10-15 20:12:01 -0400 | [diff] [blame] | 605 | static GLboolean |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 606 | get_visual_attribs(Display *dpy, XVisualInfo *vInfo, |
| 607 | struct visual_attribs *attribs) |
| 608 | { |
Brian Paul | 25673f0 | 2000-03-31 18:17:51 +0000 | [diff] [blame] | 609 | const char *ext = glXQueryExtensionsString(dpy, vInfo->screen); |
Kristian Høgsberg | 791ad0e | 2007-10-16 16:01:34 -0400 | [diff] [blame] | 610 | int rgba; |
Brian Paul | 25673f0 | 2000-03-31 18:17:51 +0000 | [diff] [blame] | 611 | |
Brian Paul | a9c53fa | 2000-04-03 15:45:34 +0000 | [diff] [blame] | 612 | memset(attribs, 0, sizeof(struct visual_attribs)); |
| 613 | |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 614 | attribs->id = vInfo->visualid; |
| 615 | #if defined(__cplusplus) || defined(c_plusplus) |
| 616 | attribs->klass = vInfo->c_class; |
| 617 | #else |
| 618 | attribs->klass = vInfo->class; |
| 619 | #endif |
| 620 | attribs->depth = vInfo->depth; |
| 621 | attribs->redMask = vInfo->red_mask; |
| 622 | attribs->greenMask = vInfo->green_mask; |
| 623 | attribs->blueMask = vInfo->blue_mask; |
| 624 | attribs->colormapSize = vInfo->colormap_size; |
| 625 | attribs->bitsPerRGB = vInfo->bits_per_rgb; |
| 626 | |
Kristian Høgsberg | 791ad0e | 2007-10-16 16:01:34 -0400 | [diff] [blame] | 627 | if (glXGetConfig(dpy, vInfo, GLX_USE_GL, &attribs->supportsGL) != 0 || |
| 628 | !attribs->supportsGL) |
Kristian Høgsberg | f7d1d55 | 2007-10-15 20:12:01 -0400 | [diff] [blame] | 629 | return GL_FALSE; |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 630 | glXGetConfig(dpy, vInfo, GLX_BUFFER_SIZE, &attribs->bufferSize); |
| 631 | glXGetConfig(dpy, vInfo, GLX_LEVEL, &attribs->level); |
Kristian Høgsberg | 791ad0e | 2007-10-16 16:01:34 -0400 | [diff] [blame] | 632 | glXGetConfig(dpy, vInfo, GLX_RGBA, &rgba); |
| 633 | if (rgba) |
| 634 | attribs->render_type = GLX_RGBA_BIT; |
| 635 | else |
| 636 | attribs->render_type = GLX_COLOR_INDEX_BIT; |
| 637 | |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 638 | glXGetConfig(dpy, vInfo, GLX_DOUBLEBUFFER, &attribs->doubleBuffer); |
| 639 | glXGetConfig(dpy, vInfo, GLX_STEREO, &attribs->stereo); |
| 640 | glXGetConfig(dpy, vInfo, GLX_AUX_BUFFERS, &attribs->auxBuffers); |
| 641 | glXGetConfig(dpy, vInfo, GLX_RED_SIZE, &attribs->redSize); |
| 642 | glXGetConfig(dpy, vInfo, GLX_GREEN_SIZE, &attribs->greenSize); |
| 643 | glXGetConfig(dpy, vInfo, GLX_BLUE_SIZE, &attribs->blueSize); |
| 644 | glXGetConfig(dpy, vInfo, GLX_ALPHA_SIZE, &attribs->alphaSize); |
| 645 | glXGetConfig(dpy, vInfo, GLX_DEPTH_SIZE, &attribs->depthSize); |
| 646 | glXGetConfig(dpy, vInfo, GLX_STENCIL_SIZE, &attribs->stencilSize); |
| 647 | glXGetConfig(dpy, vInfo, GLX_ACCUM_RED_SIZE, &attribs->accumRedSize); |
| 648 | glXGetConfig(dpy, vInfo, GLX_ACCUM_GREEN_SIZE, &attribs->accumGreenSize); |
| 649 | glXGetConfig(dpy, vInfo, GLX_ACCUM_BLUE_SIZE, &attribs->accumBlueSize); |
| 650 | glXGetConfig(dpy, vInfo, GLX_ACCUM_ALPHA_SIZE, &attribs->accumAlphaSize); |
| 651 | |
Brian Paul | 45c5698 | 2002-10-14 13:57:23 +0000 | [diff] [blame] | 652 | /* get transparent pixel stuff */ |
| 653 | glXGetConfig(dpy, vInfo,GLX_TRANSPARENT_TYPE, &attribs->transparentType); |
| 654 | if (attribs->transparentType == GLX_TRANSPARENT_RGB) { |
| 655 | glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_RED_VALUE, &attribs->transparentRedValue); |
| 656 | glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_GREEN_VALUE, &attribs->transparentGreenValue); |
| 657 | glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_BLUE_VALUE, &attribs->transparentBlueValue); |
| 658 | glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_ALPHA_VALUE, &attribs->transparentAlphaValue); |
| 659 | } |
| 660 | else if (attribs->transparentType == GLX_TRANSPARENT_INDEX) { |
| 661 | glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_INDEX_VALUE, &attribs->transparentIndexValue); |
| 662 | } |
Brian Paul | e06c7f3 | 2000-01-27 16:53:55 +0000 | [diff] [blame] | 663 | |
Brian Paul | d2e39bb | 2002-11-04 16:24:18 +0000 | [diff] [blame] | 664 | /* multisample attribs */ |
| 665 | #ifdef GLX_ARB_multisample |
Adam Jackson | e1ae5b8 | 2008-01-22 14:57:20 -0500 | [diff] [blame] | 666 | if (ext && strstr(ext, "GLX_ARB_multisample")) { |
Brian Paul | d2e39bb | 2002-11-04 16:24:18 +0000 | [diff] [blame] | 667 | glXGetConfig(dpy, vInfo, GLX_SAMPLE_BUFFERS_ARB, &attribs->numMultisample); |
| 668 | glXGetConfig(dpy, vInfo, GLX_SAMPLES_ARB, &attribs->numSamples); |
| 669 | } |
| 670 | #endif |
| 671 | else { |
| 672 | attribs->numSamples = 0; |
| 673 | attribs->numMultisample = 0; |
| 674 | } |
Brian Paul | 25673f0 | 2000-03-31 18:17:51 +0000 | [diff] [blame] | 675 | |
| 676 | #if defined(GLX_EXT_visual_rating) |
| 677 | if (ext && strstr(ext, "GLX_EXT_visual_rating")) { |
| 678 | glXGetConfig(dpy, vInfo, GLX_VISUAL_CAVEAT_EXT, &attribs->visualCaveat); |
| 679 | } |
| 680 | else { |
| 681 | attribs->visualCaveat = GLX_NONE_EXT; |
| 682 | } |
| 683 | #else |
| 684 | attribs->visualCaveat = 0; |
| 685 | #endif |
Kristian Høgsberg | f7d1d55 | 2007-10-15 20:12:01 -0400 | [diff] [blame] | 686 | |
| 687 | return GL_TRUE; |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 688 | } |
| 689 | |
Kristian Høgsberg | 791ad0e | 2007-10-16 16:01:34 -0400 | [diff] [blame] | 690 | #ifdef GLX_VERSION_1_3 |
| 691 | |
| 692 | static int |
| 693 | glx_token_to_visual_class(int visual_type) |
| 694 | { |
| 695 | switch (visual_type) { |
| 696 | case GLX_TRUE_COLOR: |
| 697 | return TrueColor; |
| 698 | case GLX_DIRECT_COLOR: |
| 699 | return DirectColor; |
| 700 | case GLX_PSEUDO_COLOR: |
| 701 | return PseudoColor; |
| 702 | case GLX_STATIC_COLOR: |
| 703 | return StaticColor; |
| 704 | case GLX_GRAY_SCALE: |
| 705 | return GrayScale; |
| 706 | case GLX_STATIC_GRAY: |
| 707 | return StaticGray; |
| 708 | case GLX_NONE: |
| 709 | default: |
| 710 | return None; |
| 711 | } |
| 712 | } |
| 713 | |
| 714 | static GLboolean |
| 715 | get_fbconfig_attribs(Display *dpy, GLXFBConfig fbconfig, |
| 716 | struct visual_attribs *attribs) |
| 717 | { |
| 718 | int visual_type; |
| 719 | |
| 720 | memset(attribs, 0, sizeof(struct visual_attribs)); |
| 721 | |
| 722 | glXGetFBConfigAttrib(dpy, fbconfig, GLX_FBCONFIG_ID, &attribs->id); |
| 723 | |
Kristian Høgsberg | 791ad0e | 2007-10-16 16:01:34 -0400 | [diff] [blame] | 724 | #if 0 |
| 725 | attribs->depth = vInfo->depth; |
| 726 | attribs->redMask = vInfo->red_mask; |
| 727 | attribs->greenMask = vInfo->green_mask; |
| 728 | attribs->blueMask = vInfo->blue_mask; |
| 729 | attribs->colormapSize = vInfo->colormap_size; |
| 730 | attribs->bitsPerRGB = vInfo->bits_per_rgb; |
| 731 | #endif |
| 732 | |
| 733 | glXGetFBConfigAttrib(dpy, fbconfig, GLX_X_VISUAL_TYPE, &visual_type); |
| 734 | attribs->klass = glx_token_to_visual_class(visual_type); |
| 735 | |
| 736 | glXGetFBConfigAttrib(dpy, fbconfig, GLX_BUFFER_SIZE, &attribs->bufferSize); |
| 737 | glXGetFBConfigAttrib(dpy, fbconfig, GLX_LEVEL, &attribs->level); |
| 738 | glXGetFBConfigAttrib(dpy, fbconfig, GLX_RENDER_TYPE, &attribs->render_type); |
| 739 | glXGetFBConfigAttrib(dpy, fbconfig, GLX_DOUBLEBUFFER, &attribs->doubleBuffer); |
| 740 | glXGetFBConfigAttrib(dpy, fbconfig, GLX_STEREO, &attribs->stereo); |
| 741 | glXGetFBConfigAttrib(dpy, fbconfig, GLX_AUX_BUFFERS, &attribs->auxBuffers); |
| 742 | |
| 743 | glXGetFBConfigAttrib(dpy, fbconfig, GLX_RED_SIZE, &attribs->redSize); |
| 744 | glXGetFBConfigAttrib(dpy, fbconfig, GLX_GREEN_SIZE, &attribs->greenSize); |
| 745 | glXGetFBConfigAttrib(dpy, fbconfig, GLX_BLUE_SIZE, &attribs->blueSize); |
| 746 | glXGetFBConfigAttrib(dpy, fbconfig, GLX_ALPHA_SIZE, &attribs->alphaSize); |
| 747 | glXGetFBConfigAttrib(dpy, fbconfig, GLX_DEPTH_SIZE, &attribs->depthSize); |
| 748 | glXGetFBConfigAttrib(dpy, fbconfig, GLX_STENCIL_SIZE, &attribs->stencilSize); |
| 749 | |
| 750 | glXGetFBConfigAttrib(dpy, fbconfig, GLX_ACCUM_RED_SIZE, &attribs->accumRedSize); |
| 751 | glXGetFBConfigAttrib(dpy, fbconfig, GLX_ACCUM_GREEN_SIZE, &attribs->accumGreenSize); |
| 752 | glXGetFBConfigAttrib(dpy, fbconfig, GLX_ACCUM_BLUE_SIZE, &attribs->accumBlueSize); |
| 753 | glXGetFBConfigAttrib(dpy, fbconfig, GLX_ACCUM_ALPHA_SIZE, &attribs->accumAlphaSize); |
| 754 | |
| 755 | /* get transparent pixel stuff */ |
| 756 | glXGetFBConfigAttrib(dpy, fbconfig,GLX_TRANSPARENT_TYPE, &attribs->transparentType); |
| 757 | if (attribs->transparentType == GLX_TRANSPARENT_RGB) { |
| 758 | glXGetFBConfigAttrib(dpy, fbconfig, GLX_TRANSPARENT_RED_VALUE, &attribs->transparentRedValue); |
| 759 | glXGetFBConfigAttrib(dpy, fbconfig, GLX_TRANSPARENT_GREEN_VALUE, &attribs->transparentGreenValue); |
| 760 | glXGetFBConfigAttrib(dpy, fbconfig, GLX_TRANSPARENT_BLUE_VALUE, &attribs->transparentBlueValue); |
| 761 | glXGetFBConfigAttrib(dpy, fbconfig, GLX_TRANSPARENT_ALPHA_VALUE, &attribs->transparentAlphaValue); |
| 762 | } |
| 763 | else if (attribs->transparentType == GLX_TRANSPARENT_INDEX) { |
| 764 | glXGetFBConfigAttrib(dpy, fbconfig, GLX_TRANSPARENT_INDEX_VALUE, &attribs->transparentIndexValue); |
| 765 | } |
| 766 | |
| 767 | glXGetFBConfigAttrib(dpy, fbconfig, GLX_SAMPLE_BUFFERS, &attribs->numMultisample); |
| 768 | glXGetFBConfigAttrib(dpy, fbconfig, GLX_SAMPLES, &attribs->numSamples); |
| 769 | glXGetFBConfigAttrib(dpy, fbconfig, GLX_CONFIG_CAVEAT, &attribs->visualCaveat); |
| 770 | |
| 771 | return GL_TRUE; |
| 772 | } |
| 773 | |
| 774 | #endif |
| 775 | |
| 776 | |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 777 | |
| 778 | static void |
| 779 | print_visual_attribs_verbose(const struct visual_attribs *attribs) |
| 780 | { |
| 781 | printf("Visual ID: %x depth=%d class=%s\n", |
| 782 | attribs->id, attribs->depth, visual_class_name(attribs->klass)); |
| 783 | printf(" bufferSize=%d level=%d renderType=%s doubleBuffer=%d stereo=%d\n", |
Kristian Høgsberg | 791ad0e | 2007-10-16 16:01:34 -0400 | [diff] [blame] | 784 | attribs->bufferSize, attribs->level, |
| 785 | visual_render_type_name(attribs->render_type), |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 786 | attribs->doubleBuffer, attribs->stereo); |
| 787 | printf(" rgba: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n", |
| 788 | attribs->redSize, attribs->greenSize, |
| 789 | attribs->blueSize, attribs->alphaSize); |
| 790 | printf(" auxBuffers=%d depthSize=%d stencilSize=%d\n", |
| 791 | attribs->auxBuffers, attribs->depthSize, attribs->stencilSize); |
| 792 | printf(" accum: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n", |
| 793 | attribs->accumRedSize, attribs->accumGreenSize, |
| 794 | attribs->accumBlueSize, attribs->accumAlphaSize); |
| 795 | printf(" multiSample=%d multiSampleBuffers=%d\n", |
| 796 | attribs->numSamples, attribs->numMultisample); |
Brian Paul | 25673f0 | 2000-03-31 18:17:51 +0000 | [diff] [blame] | 797 | #ifdef GLX_EXT_visual_rating |
| 798 | if (attribs->visualCaveat == GLX_NONE_EXT || attribs->visualCaveat == 0) |
Brian Paul | a9c53fa | 2000-04-03 15:45:34 +0000 | [diff] [blame] | 799 | printf(" visualCaveat=None\n"); |
Brian Paul | 25673f0 | 2000-03-31 18:17:51 +0000 | [diff] [blame] | 800 | else if (attribs->visualCaveat == GLX_SLOW_VISUAL_EXT) |
Brian Paul | a9c53fa | 2000-04-03 15:45:34 +0000 | [diff] [blame] | 801 | printf(" visualCaveat=Slow\n"); |
Brian Paul | 25673f0 | 2000-03-31 18:17:51 +0000 | [diff] [blame] | 802 | else if (attribs->visualCaveat == GLX_NON_CONFORMANT_VISUAL_EXT) |
Brian Paul | a9c53fa | 2000-04-03 15:45:34 +0000 | [diff] [blame] | 803 | printf(" visualCaveat=Nonconformant\n"); |
Brian Paul | 25673f0 | 2000-03-31 18:17:51 +0000 | [diff] [blame] | 804 | #endif |
Brian Paul | 45c5698 | 2002-10-14 13:57:23 +0000 | [diff] [blame] | 805 | if (attribs->transparentType == GLX_NONE) { |
| 806 | printf(" Opaque.\n"); |
| 807 | } |
| 808 | else if (attribs->transparentType == GLX_TRANSPARENT_RGB) { |
| 809 | printf(" Transparent RGB: Red=%d Green=%d Blue=%d Alpha=%d\n",attribs->transparentRedValue,attribs->transparentGreenValue,attribs->transparentBlueValue,attribs->transparentAlphaValue); |
| 810 | } |
| 811 | else if (attribs->transparentType == GLX_TRANSPARENT_INDEX) { |
| 812 | printf(" Transparent index=%d\n",attribs->transparentIndexValue); |
| 813 | } |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 814 | } |
| 815 | |
| 816 | |
| 817 | static void |
| 818 | print_visual_attribs_short_header(void) |
| 819 | { |
Brian Paul | a9c53fa | 2000-04-03 15:45:34 +0000 | [diff] [blame] | 820 | printf(" visual x bf lv rg d st colorbuffer ax dp st accumbuffer ms cav\n"); |
| 821 | 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] | 822 | printf("----------------------------------------------------------------------\n"); |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 823 | } |
| 824 | |
| 825 | |
| 826 | static void |
| 827 | print_visual_attribs_short(const struct visual_attribs *attribs) |
| 828 | { |
Brian Paul | a3e44f4 | 2002-03-08 19:44:28 +0000 | [diff] [blame] | 829 | char *caveat = NULL; |
Brian Paul | 25673f0 | 2000-03-31 18:17:51 +0000 | [diff] [blame] | 830 | #ifdef GLX_EXT_visual_rating |
| 831 | if (attribs->visualCaveat == GLX_NONE_EXT || attribs->visualCaveat == 0) |
| 832 | caveat = "None"; |
| 833 | else if (attribs->visualCaveat == GLX_SLOW_VISUAL_EXT) |
| 834 | caveat = "Slow"; |
| 835 | else if (attribs->visualCaveat == GLX_NON_CONFORMANT_VISUAL_EXT) |
| 836 | caveat = "Ncon"; |
Brian Paul | 28bc6cb | 2002-09-06 03:47:34 +0000 | [diff] [blame] | 837 | else |
| 838 | caveat = "None"; |
Brian Paul | 25673f0 | 2000-03-31 18:17:51 +0000 | [diff] [blame] | 839 | #else |
| 840 | caveat = "None"; |
| 841 | #endif |
| 842 | |
Kristian Høgsberg | 791ad0e | 2007-10-16 16:01:34 -0400 | [diff] [blame] | 843 | printf("0x%02x %2d %2s %2d %2d %2d %c%c %c %c %2d %2d %2d %2d %2d %2d %2d", |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 844 | attribs->id, |
| 845 | attribs->depth, |
| 846 | visual_class_abbrev(attribs->klass), |
Brian Paul | 45c5698 | 2002-10-14 13:57:23 +0000 | [diff] [blame] | 847 | attribs->transparentType != GLX_NONE, |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 848 | attribs->bufferSize, |
| 849 | attribs->level, |
Kristian Høgsberg | 791ad0e | 2007-10-16 16:01:34 -0400 | [diff] [blame] | 850 | (attribs->render_type & GLX_RGBA_BIT) ? 'r' : ' ', |
| 851 | (attribs->render_type & GLX_COLOR_INDEX_BIT) ? 'c' : ' ', |
| 852 | attribs->doubleBuffer ? 'y' : '.', |
| 853 | attribs->stereo ? 'y' : '.', |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 854 | attribs->redSize, attribs->greenSize, |
| 855 | attribs->blueSize, attribs->alphaSize, |
| 856 | attribs->auxBuffers, |
| 857 | attribs->depthSize, |
| 858 | attribs->stencilSize |
| 859 | ); |
| 860 | |
Brian Paul | 25673f0 | 2000-03-31 18:17:51 +0000 | [diff] [blame] | 861 | printf(" %2d %2d %2d %2d %2d %1d %s\n", |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 862 | attribs->accumRedSize, attribs->accumGreenSize, |
| 863 | attribs->accumBlueSize, attribs->accumAlphaSize, |
Brian Paul | 25673f0 | 2000-03-31 18:17:51 +0000 | [diff] [blame] | 864 | attribs->numSamples, attribs->numMultisample, |
| 865 | caveat |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 866 | ); |
| 867 | } |
| 868 | |
| 869 | |
| 870 | static void |
| 871 | print_visual_attribs_long_header(void) |
| 872 | { |
| 873 | printf("Vis Vis Visual Trans buff lev render DB ste r g b a aux dep ste accum buffers MS MS\n"); |
| 874 | printf(" ID Depth Type parent size el type reo sz sz sz sz buf th ncl r g b a num bufs\n"); |
| 875 | printf("----------------------------------------------------------------------------------------------------\n"); |
| 876 | } |
| 877 | |
| 878 | |
| 879 | static void |
| 880 | print_visual_attribs_long(const struct visual_attribs *attribs) |
| 881 | { |
| 882 | printf("0x%2x %2d %-11s %2d %2d %2d %4s %3d %3d %3d %3d %3d %3d", |
| 883 | attribs->id, |
| 884 | attribs->depth, |
| 885 | visual_class_name(attribs->klass), |
Brian Paul | 45c5698 | 2002-10-14 13:57:23 +0000 | [diff] [blame] | 886 | attribs->transparentType != GLX_NONE, |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 887 | attribs->bufferSize, |
| 888 | attribs->level, |
Kristian Høgsberg | 791ad0e | 2007-10-16 16:01:34 -0400 | [diff] [blame] | 889 | visual_render_type_name(attribs->render_type), |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 890 | attribs->doubleBuffer, |
| 891 | attribs->stereo, |
| 892 | attribs->redSize, attribs->greenSize, |
| 893 | attribs->blueSize, attribs->alphaSize |
| 894 | ); |
| 895 | |
| 896 | printf(" %3d %4d %2d %3d %3d %3d %3d %2d %2d\n", |
| 897 | attribs->auxBuffers, |
| 898 | attribs->depthSize, |
| 899 | attribs->stencilSize, |
| 900 | attribs->accumRedSize, attribs->accumGreenSize, |
| 901 | attribs->accumBlueSize, attribs->accumAlphaSize, |
| 902 | attribs->numSamples, attribs->numMultisample |
| 903 | ); |
| 904 | } |
| 905 | |
| 906 | |
| 907 | static void |
| 908 | print_visual_info(Display *dpy, int scrnum, InfoMode mode) |
| 909 | { |
Brian Paul | f02a5f6 | 2002-07-12 15:54:01 +0000 | [diff] [blame] | 910 | XVisualInfo theTemplate; |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 911 | XVisualInfo *visuals; |
Kristian Høgsberg | 791ad0e | 2007-10-16 16:01:34 -0400 | [diff] [blame] | 912 | int numVisuals, numGlxVisuals; |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 913 | long mask; |
| 914 | int i; |
Kristian Høgsberg | 791ad0e | 2007-10-16 16:01:34 -0400 | [diff] [blame] | 915 | struct visual_attribs attribs; |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 916 | |
| 917 | /* get list of all visuals on this screen */ |
Brian Paul | f02a5f6 | 2002-07-12 15:54:01 +0000 | [diff] [blame] | 918 | theTemplate.screen = scrnum; |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 919 | mask = VisualScreenMask; |
Brian Paul | f02a5f6 | 2002-07-12 15:54:01 +0000 | [diff] [blame] | 920 | visuals = XGetVisualInfo(dpy, mask, &theTemplate, &numVisuals); |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 921 | |
Kristian Høgsberg | 791ad0e | 2007-10-16 16:01:34 -0400 | [diff] [blame] | 922 | numGlxVisuals = 0; |
| 923 | for (i = 0; i < numVisuals; i++) { |
| 924 | if (get_visual_attribs(dpy, &visuals[i], &attribs)) |
| 925 | numGlxVisuals++; |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 926 | } |
Kristian Høgsberg | 791ad0e | 2007-10-16 16:01:34 -0400 | [diff] [blame] | 927 | |
| 928 | if (numGlxVisuals == 0) |
| 929 | return; |
| 930 | |
| 931 | printf("%d GLX Visuals\n", numGlxVisuals); |
| 932 | |
| 933 | if (mode == Normal) |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 934 | print_visual_attribs_short_header(); |
Kristian Høgsberg | 791ad0e | 2007-10-16 16:01:34 -0400 | [diff] [blame] | 935 | else if (mode == Wide) |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 936 | print_visual_attribs_long_header(); |
Kristian Høgsberg | 791ad0e | 2007-10-16 16:01:34 -0400 | [diff] [blame] | 937 | |
| 938 | for (i = 0; i < numVisuals; i++) { |
| 939 | if (!get_visual_attribs(dpy, &visuals[i], &attribs)) |
| 940 | continue; |
| 941 | |
| 942 | if (mode == Verbose) |
| 943 | print_visual_attribs_verbose(&attribs); |
| 944 | else if (mode == Normal) |
| 945 | print_visual_attribs_short(&attribs); |
| 946 | else if (mode == Wide) |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 947 | print_visual_attribs_long(&attribs); |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 948 | } |
Kristian Høgsberg | 791ad0e | 2007-10-16 16:01:34 -0400 | [diff] [blame] | 949 | printf("\n"); |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 950 | |
| 951 | XFree(visuals); |
| 952 | } |
| 953 | |
Kristian Høgsberg | 791ad0e | 2007-10-16 16:01:34 -0400 | [diff] [blame] | 954 | #ifdef GLX_VERSION_1_3 |
| 955 | |
| 956 | static void |
| 957 | print_fbconfig_info(Display *dpy, int scrnum, InfoMode mode) |
| 958 | { |
| 959 | int numFBConfigs; |
| 960 | struct visual_attribs attribs; |
| 961 | GLXFBConfig *fbconfigs; |
| 962 | int i; |
| 963 | |
| 964 | /* get list of all fbconfigs on this screen */ |
| 965 | fbconfigs = glXGetFBConfigs(dpy, scrnum, &numFBConfigs); |
| 966 | |
| 967 | if (numFBConfigs == 0) |
| 968 | return; |
| 969 | |
Kristian Høgsberg | a5b4bb3 | 2007-10-17 14:43:35 -0400 | [diff] [blame] | 970 | printf("%d GLXFBConfigs:\n", numFBConfigs); |
Kristian Høgsberg | 791ad0e | 2007-10-16 16:01:34 -0400 | [diff] [blame] | 971 | if (mode == Normal) |
| 972 | print_visual_attribs_short_header(); |
| 973 | else if (mode == Wide) |
| 974 | print_visual_attribs_long_header(); |
| 975 | |
| 976 | for (i = 0; i < numFBConfigs; i++) { |
| 977 | get_fbconfig_attribs(dpy, fbconfigs[i], &attribs); |
| 978 | |
| 979 | if (mode == Verbose) |
| 980 | print_visual_attribs_verbose(&attribs); |
| 981 | else if (mode == Normal) |
| 982 | print_visual_attribs_short(&attribs); |
| 983 | else if (mode == Wide) |
| 984 | print_visual_attribs_long(&attribs); |
| 985 | } |
| 986 | printf("\n"); |
| 987 | |
| 988 | XFree(fbconfigs); |
| 989 | } |
| 990 | |
| 991 | #endif |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 992 | |
Brian Paul | 39557c3 | 2001-03-23 21:41:44 +0000 | [diff] [blame] | 993 | /* |
| 994 | * Stand-alone Mesa doesn't really implement the GLX protocol so it |
| 995 | * doesn't really know the GLX attributes associated with an X visual. |
| 996 | * The first time a visual is presented to Mesa's pseudo-GLX it |
| 997 | * attaches ancilliary buffers to it (like depth and stencil). |
| 998 | * But that usually only works if glXChooseVisual is used. |
| 999 | * This function calls glXChooseVisual() to sort of "prime the pump" |
| 1000 | * for Mesa's GLX so that the visuals that get reported actually |
| 1001 | * reflect what applications will see. |
| 1002 | * This has no effect when using true GLX. |
| 1003 | */ |
| 1004 | static void |
| 1005 | mesa_hack(Display *dpy, int scrnum) |
| 1006 | { |
| 1007 | static int attribs[] = { |
| 1008 | GLX_RGBA, |
| 1009 | GLX_RED_SIZE, 1, |
| 1010 | GLX_GREEN_SIZE, 1, |
| 1011 | GLX_BLUE_SIZE, 1, |
| 1012 | GLX_DEPTH_SIZE, 1, |
| 1013 | GLX_STENCIL_SIZE, 1, |
| 1014 | GLX_ACCUM_RED_SIZE, 1, |
| 1015 | GLX_ACCUM_GREEN_SIZE, 1, |
| 1016 | GLX_ACCUM_BLUE_SIZE, 1, |
| 1017 | GLX_ACCUM_ALPHA_SIZE, 1, |
| 1018 | GLX_DOUBLEBUFFER, |
| 1019 | None |
| 1020 | }; |
| 1021 | XVisualInfo *visinfo; |
| 1022 | |
| 1023 | visinfo = glXChooseVisual(dpy, scrnum, attribs); |
| 1024 | if (visinfo) |
| 1025 | XFree(visinfo); |
| 1026 | } |
| 1027 | |
| 1028 | |
| 1029 | /* |
| 1030 | * Examine all visuals to find the so-called best one. |
| 1031 | * We prefer deepest RGBA buffer with depth, stencil and accum |
| 1032 | * that has no caveats. |
| 1033 | */ |
| 1034 | static int |
| 1035 | find_best_visual(Display *dpy, int scrnum) |
| 1036 | { |
Brian Paul | f02a5f6 | 2002-07-12 15:54:01 +0000 | [diff] [blame] | 1037 | XVisualInfo theTemplate; |
Brian Paul | 39557c3 | 2001-03-23 21:41:44 +0000 | [diff] [blame] | 1038 | XVisualInfo *visuals; |
| 1039 | int numVisuals; |
| 1040 | long mask; |
| 1041 | int i; |
| 1042 | struct visual_attribs bestVis; |
| 1043 | |
| 1044 | /* get list of all visuals on this screen */ |
Brian Paul | f02a5f6 | 2002-07-12 15:54:01 +0000 | [diff] [blame] | 1045 | theTemplate.screen = scrnum; |
Brian Paul | 39557c3 | 2001-03-23 21:41:44 +0000 | [diff] [blame] | 1046 | mask = VisualScreenMask; |
Brian Paul | f02a5f6 | 2002-07-12 15:54:01 +0000 | [diff] [blame] | 1047 | visuals = XGetVisualInfo(dpy, mask, &theTemplate, &numVisuals); |
Brian Paul | 39557c3 | 2001-03-23 21:41:44 +0000 | [diff] [blame] | 1048 | |
| 1049 | /* init bestVis with first visual info */ |
| 1050 | get_visual_attribs(dpy, &visuals[0], &bestVis); |
| 1051 | |
| 1052 | /* try to find a "better" visual */ |
| 1053 | for (i = 1; i < numVisuals; i++) { |
| 1054 | struct visual_attribs vis; |
| 1055 | |
| 1056 | get_visual_attribs(dpy, &visuals[i], &vis); |
| 1057 | |
| 1058 | /* always skip visuals with caveats */ |
| 1059 | if (vis.visualCaveat != GLX_NONE_EXT) |
| 1060 | continue; |
| 1061 | |
| 1062 | /* see if this vis is better than bestVis */ |
| 1063 | if ((!bestVis.supportsGL && vis.supportsGL) || |
| 1064 | (bestVis.visualCaveat != GLX_NONE_EXT) || |
Kristian Høgsberg | 791ad0e | 2007-10-16 16:01:34 -0400 | [diff] [blame] | 1065 | (!(bestVis.render_type & GLX_RGBA_BIT) && (vis.render_type & GLX_RGBA_BIT)) || |
Brian Paul | 39557c3 | 2001-03-23 21:41:44 +0000 | [diff] [blame] | 1066 | (!bestVis.doubleBuffer && vis.doubleBuffer) || |
| 1067 | (bestVis.redSize < vis.redSize) || |
| 1068 | (bestVis.greenSize < vis.greenSize) || |
| 1069 | (bestVis.blueSize < vis.blueSize) || |
| 1070 | (bestVis.alphaSize < vis.alphaSize) || |
| 1071 | (bestVis.depthSize < vis.depthSize) || |
| 1072 | (bestVis.stencilSize < vis.stencilSize) || |
| 1073 | (bestVis.accumRedSize < vis.accumRedSize)) { |
| 1074 | /* found a better visual */ |
| 1075 | bestVis = vis; |
| 1076 | } |
| 1077 | } |
| 1078 | |
| 1079 | XFree(visuals); |
| 1080 | |
| 1081 | return bestVis.id; |
| 1082 | } |
| 1083 | |
| 1084 | |
Brian Paul | 08b3ff1 | 2001-04-24 20:57:36 +0000 | [diff] [blame] | 1085 | static void |
| 1086 | usage(void) |
| 1087 | { |
| 1088 | printf("Usage: glxinfo [-v] [-t] [-h] [-i] [-b] [-display <dname>]\n"); |
| 1089 | printf("\t-v: Print visuals info in verbose form.\n"); |
| 1090 | printf("\t-t: Print verbose table.\n"); |
| 1091 | printf("\t-display <dname>: Print GLX visuals on specified server.\n"); |
| 1092 | printf("\t-h: This information.\n"); |
| 1093 | printf("\t-i: Force an indirect rendering context.\n"); |
| 1094 | 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] | 1095 | printf("\t-l: Print interesting OpenGL limits.\n"); |
Brian Paul | 08b3ff1 | 2001-04-24 20:57:36 +0000 | [diff] [blame] | 1096 | } |
| 1097 | |
| 1098 | |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 1099 | int |
| 1100 | main(int argc, char *argv[]) |
| 1101 | { |
Alan Hourihane | e18599a | 2001-03-19 13:58:45 +0000 | [diff] [blame] | 1102 | char *displayName = NULL; |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 1103 | Display *dpy; |
| 1104 | int numScreens, scrnum; |
| 1105 | InfoMode mode = Normal; |
Brian Paul | 39557c3 | 2001-03-23 21:41:44 +0000 | [diff] [blame] | 1106 | GLboolean findBest = GL_FALSE; |
Brian Paul | 2f7ef5f | 2002-09-06 03:35:43 +0000 | [diff] [blame] | 1107 | GLboolean limits = GL_FALSE; |
Brian Paul | 08b3ff1 | 2001-04-24 20:57:36 +0000 | [diff] [blame] | 1108 | Bool allowDirect = True; |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 1109 | int i; |
| 1110 | |
| 1111 | for (i = 1; i < argc; i++) { |
| 1112 | if (strcmp(argv[i], "-display") == 0 && i + 1 < argc) { |
| 1113 | displayName = argv[i + 1]; |
| 1114 | i++; |
| 1115 | } |
| 1116 | else if (strcmp(argv[i], "-t") == 0) { |
| 1117 | mode = Wide; |
| 1118 | } |
| 1119 | else if (strcmp(argv[i], "-v") == 0) { |
| 1120 | mode = Verbose; |
| 1121 | } |
Brian Paul | 39557c3 | 2001-03-23 21:41:44 +0000 | [diff] [blame] | 1122 | else if (strcmp(argv[i], "-b") == 0) { |
| 1123 | findBest = GL_TRUE; |
| 1124 | } |
Brian Paul | 08b3ff1 | 2001-04-24 20:57:36 +0000 | [diff] [blame] | 1125 | else if (strcmp(argv[i], "-i") == 0) { |
| 1126 | allowDirect = False; |
| 1127 | } |
Brian Paul | 2f7ef5f | 2002-09-06 03:35:43 +0000 | [diff] [blame] | 1128 | else if (strcmp(argv[i], "-l") == 0) { |
| 1129 | limits = GL_TRUE; |
| 1130 | } |
Brian Paul | 08b3ff1 | 2001-04-24 20:57:36 +0000 | [diff] [blame] | 1131 | else if (strcmp(argv[i], "-h") == 0) { |
| 1132 | usage(); |
| 1133 | return 0; |
| 1134 | } |
| 1135 | else { |
| 1136 | printf("Unknown option `%s'\n", argv[i]); |
| 1137 | usage(); |
| 1138 | return 0; |
| 1139 | } |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 1140 | } |
| 1141 | |
| 1142 | dpy = XOpenDisplay(displayName); |
| 1143 | if (!dpy) { |
Brian | 73eee24 | 2006-12-13 08:30:26 -0700 | [diff] [blame] | 1144 | fprintf(stderr, "Error: unable to open display %s\n", XDisplayName(displayName)); |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 1145 | return -1; |
| 1146 | } |
| 1147 | |
Brian Paul | 39557c3 | 2001-03-23 21:41:44 +0000 | [diff] [blame] | 1148 | if (findBest) { |
| 1149 | int b; |
| 1150 | mesa_hack(dpy, 0); |
| 1151 | b = find_best_visual(dpy, 0); |
| 1152 | printf("%d\n", b); |
| 1153 | } |
| 1154 | else { |
| 1155 | numScreens = ScreenCount(dpy); |
Brian Paul | 373aea1 | 2001-04-02 22:45:07 +0000 | [diff] [blame] | 1156 | print_display_info(dpy); |
Brian Paul | 39557c3 | 2001-03-23 21:41:44 +0000 | [diff] [blame] | 1157 | for (scrnum = 0; scrnum < numScreens; scrnum++) { |
| 1158 | mesa_hack(dpy, scrnum); |
Brian Paul | 2f7ef5f | 2002-09-06 03:35:43 +0000 | [diff] [blame] | 1159 | print_screen_info(dpy, scrnum, allowDirect, limits); |
Brian Paul | 39557c3 | 2001-03-23 21:41:44 +0000 | [diff] [blame] | 1160 | printf("\n"); |
| 1161 | print_visual_info(dpy, scrnum, mode); |
Kristian Høgsberg | 87966ba | 2007-10-17 10:14:55 -0400 | [diff] [blame] | 1162 | #ifdef GLX_VERSION_1_3 |
Kristian Høgsberg | 791ad0e | 2007-10-16 16:01:34 -0400 | [diff] [blame] | 1163 | print_fbconfig_info(dpy, scrnum, mode); |
Kristian Høgsberg | 87966ba | 2007-10-17 10:14:55 -0400 | [diff] [blame] | 1164 | #endif |
Brian Paul | 39557c3 | 2001-03-23 21:41:44 +0000 | [diff] [blame] | 1165 | if (scrnum + 1 < numScreens) |
| 1166 | printf("\n\n"); |
| 1167 | } |
Brian Paul | 76bc440 | 2000-01-27 16:43:56 +0000 | [diff] [blame] | 1168 | } |
| 1169 | |
Brian Paul | d2bfe1e | 1999-09-16 16:40:46 +0000 | [diff] [blame] | 1170 | XCloseDisplay(dpy); |
| 1171 | |
| 1172 | return 0; |
| 1173 | } |