blob: 25dc3986ed75f25287f48ae44aa8a85a6ba8ceea [file] [log] [blame]
Brian Pauld2bfe1e1999-09-16 16:40:46 +00001/*
Brian Paulad7805d2006-05-13 00:18:12 +00002 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
Brian Paul76bc4402000-01-27 16:43:56 +00003 *
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 Pauld2bfe1e1999-09-16 16:40:46 +000020 */
21
22
Brian Paul76bc4402000-01-27 16:43:56 +000023/*
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 Paul39557c32001-03-23 21:41:44 +000029 * -b only print ID of "best" visual on screen 0
Brian Paul28bc6cb2002-09-06 03:47:34 +000030 * -i use indirect rendering connection only
Brian Paul2f7ef5f2002-09-06 03:35:43 +000031 * -l print interesting OpenGL limits (added 5 Sep 2002)
Brian Paul76bc4402000-01-27 16:43:56 +000032 *
33 * Brian Paul 26 January 2000
34 */
Brian Pauld2bfe1e1999-09-16 16:40:46 +000035
Brian Paul76bc4402000-01-27 16:43:56 +000036#include <X11/Xlib.h>
37#include <X11/Xutil.h>
Brian Pauld2bfe1e1999-09-16 16:40:46 +000038#include <GL/gl.h>
Brian Paul76bc4402000-01-27 16:43:56 +000039#include <GL/glx.h>
Brian Pauld2bfe1e1999-09-16 16:40:46 +000040#include <stdio.h>
Brian Paul76bc4402000-01-27 16:43:56 +000041#include <string.h>
Brian Paul373aea12001-04-02 22:45:07 +000042#include <stdlib.h>
Brian Pauld2bfe1e1999-09-16 16:40:46 +000043
44
Brian Paul39557c32001-03-23 21:41:44 +000045#ifndef GLX_NONE_EXT
46#define GLX_NONE_EXT 0x8000
47#endif
48
Brian Paul45c56982002-10-14 13:57:23 +000049#ifndef GLX_TRANSPARENT_RGB
50#define GLX_TRANSPARENT_RGB 0x8008
51#endif
Brian Paul39557c32001-03-23 21:41:44 +000052
Brian Paul76bc4402000-01-27 16:43:56 +000053typedef enum
Brian Pauld2bfe1e1999-09-16 16:40:46 +000054{
Brian Paul76bc4402000-01-27 16:43:56 +000055 Normal,
56 Wide,
57 Verbose
58} InfoMode;
Brian Pauld2bfe1e1999-09-16 16:40:46 +000059
Brian Pauld2bfe1e1999-09-16 16:40:46 +000060
Brian Paul76bc4402000-01-27 16:43:56 +000061struct visual_attribs
62{
63 /* X visual attribs */
64 int id;
65 int klass;
66 int depth;
67 int redMask, greenMask, blueMask;
68 int colormapSize;
69 int bitsPerRGB;
Brian Pauld2bfe1e1999-09-16 16:40:46 +000070
Brian Paul76bc4402000-01-27 16:43:56 +000071 /* GL visual attribs */
72 int supportsGL;
Brian Paul45c56982002-10-14 13:57:23 +000073 int transparentType;
74 int transparentRedValue;
75 int transparentGreenValue;
76 int transparentBlueValue;
77 int transparentAlphaValue;
78 int transparentIndexValue;
Brian Paul76bc4402000-01-27 16:43:56 +000079 int bufferSize;
80 int level;
81 int rgba;
82 int doubleBuffer;
83 int stereo;
84 int auxBuffers;
85 int redSize, greenSize, blueSize, alphaSize;
86 int depthSize;
87 int stencilSize;
88 int accumRedSize, accumGreenSize, accumBlueSize, accumAlphaSize;
89 int numSamples, numMultisample;
Brian Paul25673f02000-03-31 18:17:51 +000090 int visualCaveat;
Brian Paul76bc4402000-01-27 16:43:56 +000091};
92
93
94/*
95 * Print a list of extensions, with word-wrapping.
96 */
97static void
98print_extension_list(const char *ext)
99{
100 const char *indentString = " ";
101 const int indent = 4;
102 const int max = 79;
103 int width, i, j;
104
105 if (!ext || !ext[0])
106 return;
107
108 width = indent;
109 printf(indentString);
110 i = j = 0;
111 while (1) {
112 if (ext[j] == ' ' || ext[j] == 0) {
113 /* found end of an extension name */
114 const int len = j - i;
115 if (width + len > max) {
116 /* start a new line */
117 printf("\n");
118 width = indent;
119 printf(indentString);
120 }
121 /* print the extension name between ext[i] and ext[j] */
122 while (i < j) {
123 printf("%c", ext[i]);
124 i++;
125 }
126 /* either we're all done, or we'll continue with next extension */
127 width += len + 1;
128 if (ext[j] == 0) {
129 break;
130 }
131 else {
132 i++;
133 j++;
Brian Paul7ac43502000-02-23 22:50:35 +0000134 if (ext[j] == 0)
135 break;
Brian Paul76bc4402000-01-27 16:43:56 +0000136 printf(", ");
137 width += 2;
138 }
139 }
140 j++;
141 }
142 printf("\n");
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000143}
144
145
Brian Paul76bc4402000-01-27 16:43:56 +0000146static void
Brian Paul373aea12001-04-02 22:45:07 +0000147print_display_info(Display *dpy)
148{
149 printf("name of display: %s\n", DisplayString(dpy));
150}
151
152
Brian Paulad7805d2006-05-13 00:18:12 +0000153/**
154 * Print interesting limits for vertex/fragment programs.
155 */
Brian Paul373aea12001-04-02 22:45:07 +0000156static void
Brian Paulad7805d2006-05-13 00:18:12 +0000157print_program_limits(GLenum target)
158{
159#if defined(GL_ARB_vertex_program) || defined(GL_ARB_fragment_program)
160 struct token_name {
161 GLenum token;
162 const char *name;
163 };
164 static const struct token_name limits[] = {
165 { GL_MAX_PROGRAM_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_INSTRUCTIONS_ARB" },
166 { GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB" },
167 { GL_MAX_PROGRAM_TEMPORARIES_ARB, "GL_MAX_PROGRAM_TEMPORARIES_ARB" },
168 { GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB, "GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB" },
169 { GL_MAX_PROGRAM_PARAMETERS_ARB, "GL_MAX_PROGRAM_PARAMETERS_ARB" },
170 { GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB, "GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB" },
171 { GL_MAX_PROGRAM_ATTRIBS_ARB, "GL_MAX_PROGRAM_ATTRIBS_ARB" },
172 { GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB, "GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB" },
173 { GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB, "GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB" },
174 { GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB, "GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB" },
175 { GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB, "GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB" },
176 { GL_MAX_PROGRAM_ENV_PARAMETERS_ARB, "GL_MAX_PROGRAM_ENV_PARAMETERS_ARB" },
177 { GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB" },
178 { GL_MAX_PROGRAM_TEX_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_TEX_INSTRUCTIONS_ARB" },
179 { GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB, "GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB" },
180 { GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB" },
181 { GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB" },
182 { GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB, "GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB" },
183 { (GLenum) 0, NULL }
184 };
185 PFNGLGETPROGRAMIVARBPROC GetProgramivARB_func = (PFNGLGETPROGRAMIVARBPROC)
186 glXGetProcAddressARB((GLubyte *) "glGetProgramivARB");
187 GLint max[1];
188 int i;
189
190 if (target == GL_VERTEX_PROGRAM_ARB) {
191 printf(" GL_VERTEX_PROGRAM_ARB:\n");
192 }
193 else if (target == GL_FRAGMENT_PROGRAM_ARB) {
194 printf(" GL_FRAGMENT_PROGRAM_ARB:\n");
195 }
196 else {
197 return; /* something's wrong */
198 }
199
200 for (i = 0; limits[i].token; i++) {
201 GetProgramivARB_func(target, limits[i].token, max);
202 if (glGetError() == GL_NO_ERROR) {
203 printf(" %s = %d\n", limits[i].name, max[0]);
204 }
205 }
206#endif /* GL_ARB_vertex_program */
207}
208
209
210/**
211 * Print interesting limits for vertex/fragment shaders.
212 */
213static void
214print_shader_limits(GLenum target)
215{
216 struct token_name {
217 GLenum token;
218 const char *name;
219 };
220#if defined(GL_ARB_vertex_shader)
221 static const struct token_name vertex_limits[] = {
222 { GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB, "GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB" },
223 { GL_MAX_VARYING_FLOATS_ARB, "GL_MAX_VARYING_FLOATS_ARB" },
224 { GL_MAX_VERTEX_ATTRIBS_ARB, "GL_MAX_VERTEX_ATTRIBS_ARB" },
225 { GL_MAX_TEXTURE_IMAGE_UNITS_ARB, "GL_MAX_TEXTURE_IMAGE_UNITS_ARB" },
226 { GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB, "GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB" },
227 { GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB, "GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB" },
228 { GL_MAX_TEXTURE_COORDS_ARB, "GL_MAX_TEXTURE_COORDS_ARB" },
229 { (GLenum) 0, NULL }
230 };
231#endif
232#if defined(GL_ARB_fragment_shader)
233 static const struct token_name fragment_limits[] = {
234 { GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB, "GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB" },
235 { GL_MAX_TEXTURE_COORDS_ARB, "GL_MAX_TEXTURE_COORDS_ARB" },
236 { GL_MAX_TEXTURE_IMAGE_UNITS_ARB, "GL_MAX_TEXTURE_IMAGE_UNITS_ARB" },
237 { (GLenum) 0, NULL }
238 };
239#endif
240 GLint max[1];
241 int i;
242
243#if defined(GL_ARB_vertex_shader)
244 if (target == GL_VERTEX_SHADER_ARB) {
245 printf(" GL_VERTEX_SHADER_ARB:\n");
246 for (i = 0; vertex_limits[i].token; i++) {
247 glGetIntegerv(vertex_limits[i].token, max);
248 if (glGetError() == GL_NO_ERROR) {
249 printf(" %s = %d\n", vertex_limits[i].name, max[0]);
250 }
251 }
252 }
253#endif
254#if defined(GL_ARB_fragment_shader)
255 if (target == GL_FRAGMENT_SHADER_ARB) {
256 printf(" GL_FRAGMENT_SHADER_ARB:\n");
257 for (i = 0; fragment_limits[i].token; i++) {
258 glGetIntegerv(fragment_limits[i].token, max);
259 if (glGetError() == GL_NO_ERROR) {
260 printf(" %s = %d\n", fragment_limits[i].name, max[0]);
261 }
262 }
263 }
264#endif
265}
266
267
268/**
269 * Print interesting OpenGL implementation limits.
270 */
271static void
272print_limits(const char *extensions)
Brian Paul2f7ef5f2002-09-06 03:35:43 +0000273{
274 struct token_name {
275 GLuint count;
276 GLenum token;
277 const char *name;
278 };
279 static const struct token_name limits[] = {
280 { 1, GL_MAX_ATTRIB_STACK_DEPTH, "GL_MAX_ATTRIB_STACK_DEPTH" },
281 { 1, GL_MAX_CLIENT_ATTRIB_STACK_DEPTH, "GL_MAX_CLIENT_ATTRIB_STACK_DEPTH" },
282 { 1, GL_MAX_CLIP_PLANES, "GL_MAX_CLIP_PLANES" },
283 { 1, GL_MAX_COLOR_MATRIX_STACK_DEPTH, "GL_MAX_COLOR_MATRIX_STACK_DEPTH" },
Brian Paul2f7ef5f2002-09-06 03:35:43 +0000284 { 1, GL_MAX_ELEMENTS_VERTICES, "GL_MAX_ELEMENTS_VERTICES" },
285 { 1, GL_MAX_ELEMENTS_INDICES, "GL_MAX_ELEMENTS_INDICES" },
286 { 1, GL_MAX_EVAL_ORDER, "GL_MAX_EVAL_ORDER" },
287 { 1, GL_MAX_LIGHTS, "GL_MAX_LIGHTS" },
288 { 1, GL_MAX_LIST_NESTING, "GL_MAX_LIST_NESTING" },
289 { 1, GL_MAX_MODELVIEW_STACK_DEPTH, "GL_MAX_MODELVIEW_STACK_DEPTH" },
290 { 1, GL_MAX_NAME_STACK_DEPTH, "GL_MAX_NAME_STACK_DEPTH" },
291 { 1, GL_MAX_PIXEL_MAP_TABLE, "GL_MAX_PIXEL_MAP_TABLE" },
292 { 1, GL_MAX_PROJECTION_STACK_DEPTH, "GL_MAX_PROJECTION_STACK_DEPTH" },
293 { 1, GL_MAX_TEXTURE_STACK_DEPTH, "GL_MAX_TEXTURE_STACK_DEPTH" },
294 { 1, GL_MAX_TEXTURE_SIZE, "GL_MAX_TEXTURE_SIZE" },
295 { 1, GL_MAX_3D_TEXTURE_SIZE, "GL_MAX_3D_TEXTURE_SIZE" },
Brian Paul2f7ef5f2002-09-06 03:35:43 +0000296 { 2, GL_MAX_VIEWPORT_DIMS, "GL_MAX_VIEWPORT_DIMS" },
297 { 2, GL_ALIASED_LINE_WIDTH_RANGE, "GL_ALIASED_LINE_WIDTH_RANGE" },
298 { 2, GL_SMOOTH_LINE_WIDTH_RANGE, "GL_SMOOTH_LINE_WIDTH_RANGE" },
299 { 2, GL_ALIASED_POINT_SIZE_RANGE, "GL_ALIASED_POINT_SIZE_RANGE" },
300 { 2, GL_SMOOTH_POINT_SIZE_RANGE, "GL_SMOOTH_POINT_SIZE_RANGE" },
Brian Paulad7805d2006-05-13 00:18:12 +0000301#if defined(GL_ARB_texture_cube_map)
302 { 1, GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB, "GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB" },
303#endif
304#if defined(GLX_NV_texture_rectangle)
305 { 1, GL_MAX_RECTANGLE_TEXTURE_SIZE_NV, "GL_MAX_RECTANGLE_TEXTURE_SIZE_NV" },
306#endif
307#if defined(GL_ARB_texture_compression)
308 { 1, GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB, "GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB" },
309#endif
310#if defined(GL_ARB_multitexture)
311 { 1, GL_MAX_TEXTURE_UNITS_ARB, "GL_MAX_TEXTURE_UNITS_ARB" },
312#endif
313#if defined(GL_EXT_texture_lod_bias)
314 { 1, GL_MAX_TEXTURE_LOD_BIAS_EXT, "GL_MAX_TEXTURE_LOD_BIAS_EXT" },
315#endif
316#if defined(GL_EXT_texture_filter_anisotropic)
317 { 1, GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, "GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT" },
318#endif
319#if defined(GL_ARB_draw_buffers)
320 { 1, GL_MAX_DRAW_BUFFERS_ARB, "GL_MAX_DRAW_BUFFERS_ARB" },
321#endif
Brian Paul2f7ef5f2002-09-06 03:35:43 +0000322 { 0, (GLenum) 0, NULL }
323 };
324 GLint i, max[2];
Brian Paulad7805d2006-05-13 00:18:12 +0000325
Brian Paul2f7ef5f2002-09-06 03:35:43 +0000326 printf("OpenGL limits:\n");
327 for (i = 0; limits[i].count; i++) {
328 glGetIntegerv(limits[i].token, max);
Brian Paulad7805d2006-05-13 00:18:12 +0000329 if (glGetError() == GL_NO_ERROR) {
Brian Paul2f7ef5f2002-09-06 03:35:43 +0000330 if (limits[i].count == 1)
331 printf(" %s = %d\n", limits[i].name, max[0]);
332 else /* XXX fix if we ever query something with more than 2 values */
333 printf(" %s = %d, %d\n", limits[i].name, max[0], max[1]);
334 }
335 }
Brian Paulad7805d2006-05-13 00:18:12 +0000336
Brian Paulf2afdca2004-08-10 15:32:25 +0000337 /* these don't fit into the above mechanism, unfortunately */
338 glGetConvolutionParameteriv(GL_CONVOLUTION_2D, GL_MAX_CONVOLUTION_WIDTH, max);
339 glGetConvolutionParameteriv(GL_CONVOLUTION_2D, GL_MAX_CONVOLUTION_HEIGHT, max+1);
340 if (glGetError() == GL_NONE) {
341 printf(" GL_MAX_CONVOLUTION_WIDTH/HEIGHT = %d, %d\n", max[0], max[1]);
342 }
343
Brian Paulad7805d2006-05-13 00:18:12 +0000344 if (strstr(extensions, "GL_ARB_vertex_program")) {
345 print_program_limits(GL_VERTEX_PROGRAM_ARB);
346 }
347 if (strstr(extensions, "GL_ARB_fragment_program")) {
348 print_program_limits(GL_FRAGMENT_PROGRAM_ARB);
349 }
350 if (strstr(extensions, "GL_ARB_vertex_shader")) {
351 print_shader_limits(GL_VERTEX_SHADER_ARB);
352 }
353 if (strstr(extensions, "GL_ARB_fragment_shader")) {
354 print_shader_limits(GL_FRAGMENT_SHADER_ARB);
355 }
Brian Paul2f7ef5f2002-09-06 03:35:43 +0000356}
357
358
359static void
360print_screen_info(Display *dpy, int scrnum, Bool allowDirect, GLboolean limits)
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000361{
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000362 Window win;
Brian Paul8460cc92000-02-02 20:57:51 +0000363 int attribSingle[] = {
364 GLX_RGBA,
365 GLX_RED_SIZE, 1,
366 GLX_GREEN_SIZE, 1,
367 GLX_BLUE_SIZE, 1,
368 None };
369 int attribDouble[] = {
370 GLX_RGBA,
371 GLX_RED_SIZE, 1,
372 GLX_GREEN_SIZE, 1,
373 GLX_BLUE_SIZE, 1,
374 GLX_DOUBLEBUFFER,
375 None };
376
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000377 XSetWindowAttributes attr;
378 unsigned long mask;
379 Window root;
380 GLXContext ctx;
381 XVisualInfo *visinfo;
382 int width = 100, height = 100;
383
Brian Paul76bc4402000-01-27 16:43:56 +0000384 root = RootWindow(dpy, scrnum);
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000385
Brian Paul8460cc92000-02-02 20:57:51 +0000386 visinfo = glXChooseVisual(dpy, scrnum, attribSingle);
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000387 if (!visinfo) {
Brian Paul8460cc92000-02-02 20:57:51 +0000388 visinfo = glXChooseVisual(dpy, scrnum, attribDouble);
389 if (!visinfo) {
Brian Paul9cff5582000-05-07 18:07:23 +0000390 fprintf(stderr, "Error: couldn't find RGB GLX visual\n");
Brian Paul8460cc92000-02-02 20:57:51 +0000391 return;
392 }
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000393 }
394
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000395 attr.background_pixel = 0;
396 attr.border_pixel = 0;
Brian Paul9cff5582000-05-07 18:07:23 +0000397 attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone);
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000398 attr.event_mask = StructureNotifyMask | ExposureMask;
399 mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
Brian Paul76bc4402000-01-27 16:43:56 +0000400 win = XCreateWindow(dpy, root, 0, 0, width, height,
401 0, visinfo->depth, InputOutput,
402 visinfo->visual, mask, &attr);
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000403
Brian Paul08b3ff12001-04-24 20:57:36 +0000404 ctx = glXCreateContext( dpy, visinfo, NULL, allowDirect );
Brian Paul34fb5db2000-04-22 20:31:23 +0000405 if (!ctx) {
Brian Paul9cff5582000-05-07 18:07:23 +0000406 fprintf(stderr, "Error: glXCreateContext failed\n");
Brian Paul361bccb2006-01-16 16:17:18 +0000407 XFree(visinfo);
Brian Paul34fb5db2000-04-22 20:31:23 +0000408 XDestroyWindow(dpy, win);
409 return;
410 }
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000411
Brian Paul9cff5582000-05-07 18:07:23 +0000412 if (glXMakeCurrent(dpy, win, ctx)) {
Brian Paul76bc4402000-01-27 16:43:56 +0000413 const char *serverVendor = glXQueryServerString(dpy, scrnum, GLX_VENDOR);
414 const char *serverVersion = glXQueryServerString(dpy, scrnum, GLX_VERSION);
415 const char *serverExtensions = glXQueryServerString(dpy, scrnum, GLX_EXTENSIONS);
Brian Paul34fb5db2000-04-22 20:31:23 +0000416 const char *clientVendor = glXGetClientString(dpy, GLX_VENDOR);
Brian Paul76bc4402000-01-27 16:43:56 +0000417 const char *clientVersion = glXGetClientString(dpy, GLX_VERSION);
418 const char *clientExtensions = glXGetClientString(dpy, GLX_EXTENSIONS);
419 const char *glxExtensions = glXQueryExtensionsString(dpy, scrnum);
420 const char *glVendor = (const char *) glGetString(GL_VENDOR);
421 const char *glRenderer = (const char *) glGetString(GL_RENDERER);
422 const char *glVersion = (const char *) glGetString(GL_VERSION);
423 const char *glExtensions = (const char *) glGetString(GL_EXTENSIONS);
Ian Romanickc00fbd52004-02-23 17:37:36 +0000424 int glxVersionMajor;
425 int glxVersionMinor;
Brian Paul373aea12001-04-02 22:45:07 +0000426 char *displayName = NULL;
427 char *colon = NULL, *period = NULL;
Ian Romanickc00fbd52004-02-23 17:37:36 +0000428
429 if (! glXQueryVersion( dpy, & glxVersionMajor, & glxVersionMinor )) {
430 fprintf(stderr, "Error: glXQueryVersion failed\n");
431 exit(1);
432 }
433
Brian Paul373aea12001-04-02 22:45:07 +0000434 /* Strip the screen number from the display name, if present. */
Brian Paulf02a5f62002-07-12 15:54:01 +0000435 if (!(displayName = (char *) malloc(strlen(DisplayString(dpy)) + 1))) {
Brian Paul373aea12001-04-02 22:45:07 +0000436 fprintf(stderr, "Error: malloc() failed\n");
437 exit(1);
438 }
439 strcpy(displayName, DisplayString(dpy));
440 colon = strrchr(displayName, ':');
441 if (colon) {
442 period = strchr(colon, '.');
443 if (period)
444 *period = '\0';
445 }
446 printf("display: %s screen: %d\n", displayName, scrnum);
447 free(displayName);
Brian Paule691ee22000-05-08 14:53:57 +0000448 printf("direct rendering: %s\n", glXIsDirect(dpy, ctx) ? "Yes" : "No");
Brian Paul76bc4402000-01-27 16:43:56 +0000449 printf("server glx vendor string: %s\n", serverVendor);
450 printf("server glx version string: %s\n", serverVersion);
451 printf("server glx extensions:\n");
452 print_extension_list(serverExtensions);
Brian Paul34fb5db2000-04-22 20:31:23 +0000453 printf("client glx vendor string: %s\n", clientVendor);
454 printf("client glx version string: %s\n", clientVersion);
Brian Paul76bc4402000-01-27 16:43:56 +0000455 printf("client glx extensions:\n");
456 print_extension_list(clientExtensions);
Ian Romanickc00fbd52004-02-23 17:37:36 +0000457 printf("GLX version: %u.%u\n", glxVersionMajor, glxVersionMinor);
Brian Paul76bc4402000-01-27 16:43:56 +0000458 printf("GLX extensions:\n");
459 print_extension_list(glxExtensions);
460 printf("OpenGL vendor string: %s\n", glVendor);
461 printf("OpenGL renderer string: %s\n", glRenderer);
462 printf("OpenGL version string: %s\n", glVersion);
463 printf("OpenGL extensions:\n");
464 print_extension_list(glExtensions);
Brian Paul2f7ef5f2002-09-06 03:35:43 +0000465 if (limits)
Brian Paulad7805d2006-05-13 00:18:12 +0000466 print_limits(glExtensions);
Brian Paul76bc4402000-01-27 16:43:56 +0000467 }
Brian Paul9cff5582000-05-07 18:07:23 +0000468 else {
469 fprintf(stderr, "Error: glXMakeCurrent failed\n");
470 }
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000471
472 glXDestroyContext(dpy, ctx);
Brian Paul361bccb2006-01-16 16:17:18 +0000473 XFree(visinfo);
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000474 XDestroyWindow(dpy, win);
Brian Paul76bc4402000-01-27 16:43:56 +0000475}
476
477
478static const char *
479visual_class_name(int cls)
480{
481 switch (cls) {
482 case StaticColor:
483 return "StaticColor";
484 case PseudoColor:
485 return "PseudoColor";
486 case StaticGray:
487 return "StaticGray";
488 case GrayScale:
489 return "GrayScale";
490 case TrueColor:
491 return "TrueColor";
492 case DirectColor:
493 return "DirectColor";
494 default:
495 return "";
496 }
497}
498
499
500static const char *
501visual_class_abbrev(int cls)
502{
503 switch (cls) {
504 case StaticColor:
505 return "sc";
506 case PseudoColor:
507 return "pc";
508 case StaticGray:
509 return "sg";
510 case GrayScale:
511 return "gs";
512 case TrueColor:
513 return "tc";
514 case DirectColor:
515 return "dc";
516 default:
517 return "";
518 }
519}
520
521
522static void
523get_visual_attribs(Display *dpy, XVisualInfo *vInfo,
524 struct visual_attribs *attribs)
525{
Brian Paul25673f02000-03-31 18:17:51 +0000526 const char *ext = glXQueryExtensionsString(dpy, vInfo->screen);
527
Brian Paula9c53fa2000-04-03 15:45:34 +0000528 memset(attribs, 0, sizeof(struct visual_attribs));
529
Brian Paul76bc4402000-01-27 16:43:56 +0000530 attribs->id = vInfo->visualid;
531#if defined(__cplusplus) || defined(c_plusplus)
532 attribs->klass = vInfo->c_class;
533#else
534 attribs->klass = vInfo->class;
535#endif
536 attribs->depth = vInfo->depth;
537 attribs->redMask = vInfo->red_mask;
538 attribs->greenMask = vInfo->green_mask;
539 attribs->blueMask = vInfo->blue_mask;
540 attribs->colormapSize = vInfo->colormap_size;
541 attribs->bitsPerRGB = vInfo->bits_per_rgb;
542
Brian Paula9c53fa2000-04-03 15:45:34 +0000543 if (glXGetConfig(dpy, vInfo, GLX_USE_GL, &attribs->supportsGL) != 0)
544 return;
Brian Paul76bc4402000-01-27 16:43:56 +0000545 glXGetConfig(dpy, vInfo, GLX_BUFFER_SIZE, &attribs->bufferSize);
546 glXGetConfig(dpy, vInfo, GLX_LEVEL, &attribs->level);
547 glXGetConfig(dpy, vInfo, GLX_RGBA, &attribs->rgba);
548 glXGetConfig(dpy, vInfo, GLX_DOUBLEBUFFER, &attribs->doubleBuffer);
549 glXGetConfig(dpy, vInfo, GLX_STEREO, &attribs->stereo);
550 glXGetConfig(dpy, vInfo, GLX_AUX_BUFFERS, &attribs->auxBuffers);
551 glXGetConfig(dpy, vInfo, GLX_RED_SIZE, &attribs->redSize);
552 glXGetConfig(dpy, vInfo, GLX_GREEN_SIZE, &attribs->greenSize);
553 glXGetConfig(dpy, vInfo, GLX_BLUE_SIZE, &attribs->blueSize);
554 glXGetConfig(dpy, vInfo, GLX_ALPHA_SIZE, &attribs->alphaSize);
555 glXGetConfig(dpy, vInfo, GLX_DEPTH_SIZE, &attribs->depthSize);
556 glXGetConfig(dpy, vInfo, GLX_STENCIL_SIZE, &attribs->stencilSize);
557 glXGetConfig(dpy, vInfo, GLX_ACCUM_RED_SIZE, &attribs->accumRedSize);
558 glXGetConfig(dpy, vInfo, GLX_ACCUM_GREEN_SIZE, &attribs->accumGreenSize);
559 glXGetConfig(dpy, vInfo, GLX_ACCUM_BLUE_SIZE, &attribs->accumBlueSize);
560 glXGetConfig(dpy, vInfo, GLX_ACCUM_ALPHA_SIZE, &attribs->accumAlphaSize);
561
Brian Paul45c56982002-10-14 13:57:23 +0000562 /* get transparent pixel stuff */
563 glXGetConfig(dpy, vInfo,GLX_TRANSPARENT_TYPE, &attribs->transparentType);
564 if (attribs->transparentType == GLX_TRANSPARENT_RGB) {
565 glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_RED_VALUE, &attribs->transparentRedValue);
566 glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_GREEN_VALUE, &attribs->transparentGreenValue);
567 glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_BLUE_VALUE, &attribs->transparentBlueValue);
568 glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_ALPHA_VALUE, &attribs->transparentAlphaValue);
569 }
570 else if (attribs->transparentType == GLX_TRANSPARENT_INDEX) {
571 glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_INDEX_VALUE, &attribs->transparentIndexValue);
572 }
Brian Paule06c7f32000-01-27 16:53:55 +0000573
Brian Pauld2e39bb2002-11-04 16:24:18 +0000574 /* multisample attribs */
575#ifdef GLX_ARB_multisample
Brian Paulad7805d2006-05-13 00:18:12 +0000576 if (ext && strstr(ext, "GLX_ARB_multisample") == 0) {
Brian Pauld2e39bb2002-11-04 16:24:18 +0000577 glXGetConfig(dpy, vInfo, GLX_SAMPLE_BUFFERS_ARB, &attribs->numMultisample);
578 glXGetConfig(dpy, vInfo, GLX_SAMPLES_ARB, &attribs->numSamples);
579 }
580#endif
581 else {
582 attribs->numSamples = 0;
583 attribs->numMultisample = 0;
584 }
Brian Paul25673f02000-03-31 18:17:51 +0000585
586#if defined(GLX_EXT_visual_rating)
587 if (ext && strstr(ext, "GLX_EXT_visual_rating")) {
588 glXGetConfig(dpy, vInfo, GLX_VISUAL_CAVEAT_EXT, &attribs->visualCaveat);
589 }
590 else {
591 attribs->visualCaveat = GLX_NONE_EXT;
592 }
593#else
594 attribs->visualCaveat = 0;
595#endif
Brian Paul76bc4402000-01-27 16:43:56 +0000596}
597
598
599static void
600print_visual_attribs_verbose(const struct visual_attribs *attribs)
601{
602 printf("Visual ID: %x depth=%d class=%s\n",
603 attribs->id, attribs->depth, visual_class_name(attribs->klass));
604 printf(" bufferSize=%d level=%d renderType=%s doubleBuffer=%d stereo=%d\n",
605 attribs->bufferSize, attribs->level, attribs->rgba ? "rgba" : "ci",
606 attribs->doubleBuffer, attribs->stereo);
607 printf(" rgba: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n",
608 attribs->redSize, attribs->greenSize,
609 attribs->blueSize, attribs->alphaSize);
610 printf(" auxBuffers=%d depthSize=%d stencilSize=%d\n",
611 attribs->auxBuffers, attribs->depthSize, attribs->stencilSize);
612 printf(" accum: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n",
613 attribs->accumRedSize, attribs->accumGreenSize,
614 attribs->accumBlueSize, attribs->accumAlphaSize);
615 printf(" multiSample=%d multiSampleBuffers=%d\n",
616 attribs->numSamples, attribs->numMultisample);
Brian Paul25673f02000-03-31 18:17:51 +0000617#ifdef GLX_EXT_visual_rating
618 if (attribs->visualCaveat == GLX_NONE_EXT || attribs->visualCaveat == 0)
Brian Paula9c53fa2000-04-03 15:45:34 +0000619 printf(" visualCaveat=None\n");
Brian Paul25673f02000-03-31 18:17:51 +0000620 else if (attribs->visualCaveat == GLX_SLOW_VISUAL_EXT)
Brian Paula9c53fa2000-04-03 15:45:34 +0000621 printf(" visualCaveat=Slow\n");
Brian Paul25673f02000-03-31 18:17:51 +0000622 else if (attribs->visualCaveat == GLX_NON_CONFORMANT_VISUAL_EXT)
Brian Paula9c53fa2000-04-03 15:45:34 +0000623 printf(" visualCaveat=Nonconformant\n");
Brian Paul25673f02000-03-31 18:17:51 +0000624#endif
Brian Paul45c56982002-10-14 13:57:23 +0000625 if (attribs->transparentType == GLX_NONE) {
626 printf(" Opaque.\n");
627 }
628 else if (attribs->transparentType == GLX_TRANSPARENT_RGB) {
629 printf(" Transparent RGB: Red=%d Green=%d Blue=%d Alpha=%d\n",attribs->transparentRedValue,attribs->transparentGreenValue,attribs->transparentBlueValue,attribs->transparentAlphaValue);
630 }
631 else if (attribs->transparentType == GLX_TRANSPARENT_INDEX) {
632 printf(" Transparent index=%d\n",attribs->transparentIndexValue);
633 }
Brian Paul76bc4402000-01-27 16:43:56 +0000634}
635
636
637static void
638print_visual_attribs_short_header(void)
639{
Brian Paula9c53fa2000-04-03 15:45:34 +0000640 printf(" visual x bf lv rg d st colorbuffer ax dp st accumbuffer ms cav\n");
641 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 Paul25673f02000-03-31 18:17:51 +0000642 printf("----------------------------------------------------------------------\n");
Brian Paul76bc4402000-01-27 16:43:56 +0000643}
644
645
646static void
647print_visual_attribs_short(const struct visual_attribs *attribs)
648{
Brian Paula3e44f42002-03-08 19:44:28 +0000649 char *caveat = NULL;
Brian Paul25673f02000-03-31 18:17:51 +0000650#ifdef GLX_EXT_visual_rating
651 if (attribs->visualCaveat == GLX_NONE_EXT || attribs->visualCaveat == 0)
652 caveat = "None";
653 else if (attribs->visualCaveat == GLX_SLOW_VISUAL_EXT)
654 caveat = "Slow";
655 else if (attribs->visualCaveat == GLX_NON_CONFORMANT_VISUAL_EXT)
656 caveat = "Ncon";
Brian Paul28bc6cb2002-09-06 03:47:34 +0000657 else
658 caveat = "None";
Brian Paul25673f02000-03-31 18:17:51 +0000659#else
660 caveat = "None";
661#endif
662
Brian Paul76bc4402000-01-27 16:43:56 +0000663 printf("0x%2x %2d %2s %2d %2d %2d %1s %2s %2s %2d %2d %2d %2d %2d %2d %2d",
664 attribs->id,
665 attribs->depth,
666 visual_class_abbrev(attribs->klass),
Brian Paul45c56982002-10-14 13:57:23 +0000667 attribs->transparentType != GLX_NONE,
Brian Paul76bc4402000-01-27 16:43:56 +0000668 attribs->bufferSize,
669 attribs->level,
670 attribs->rgba ? "r" : "c",
671 attribs->doubleBuffer ? "y" : ".",
672 attribs->stereo ? "y" : ".",
673 attribs->redSize, attribs->greenSize,
674 attribs->blueSize, attribs->alphaSize,
675 attribs->auxBuffers,
676 attribs->depthSize,
677 attribs->stencilSize
678 );
679
Brian Paul25673f02000-03-31 18:17:51 +0000680 printf(" %2d %2d %2d %2d %2d %1d %s\n",
Brian Paul76bc4402000-01-27 16:43:56 +0000681 attribs->accumRedSize, attribs->accumGreenSize,
682 attribs->accumBlueSize, attribs->accumAlphaSize,
Brian Paul25673f02000-03-31 18:17:51 +0000683 attribs->numSamples, attribs->numMultisample,
684 caveat
Brian Paul76bc4402000-01-27 16:43:56 +0000685 );
686}
687
688
689static void
690print_visual_attribs_long_header(void)
691{
692 printf("Vis Vis Visual Trans buff lev render DB ste r g b a aux dep ste accum buffers MS MS\n");
693 printf(" ID Depth Type parent size el type reo sz sz sz sz buf th ncl r g b a num bufs\n");
694 printf("----------------------------------------------------------------------------------------------------\n");
695}
696
697
698static void
699print_visual_attribs_long(const struct visual_attribs *attribs)
700{
701 printf("0x%2x %2d %-11s %2d %2d %2d %4s %3d %3d %3d %3d %3d %3d",
702 attribs->id,
703 attribs->depth,
704 visual_class_name(attribs->klass),
Brian Paul45c56982002-10-14 13:57:23 +0000705 attribs->transparentType != GLX_NONE,
Brian Paul76bc4402000-01-27 16:43:56 +0000706 attribs->bufferSize,
707 attribs->level,
708 attribs->rgba ? "rgba" : "ci ",
709 attribs->doubleBuffer,
710 attribs->stereo,
711 attribs->redSize, attribs->greenSize,
712 attribs->blueSize, attribs->alphaSize
713 );
714
715 printf(" %3d %4d %2d %3d %3d %3d %3d %2d %2d\n",
716 attribs->auxBuffers,
717 attribs->depthSize,
718 attribs->stencilSize,
719 attribs->accumRedSize, attribs->accumGreenSize,
720 attribs->accumBlueSize, attribs->accumAlphaSize,
721 attribs->numSamples, attribs->numMultisample
722 );
723}
724
725
726static void
727print_visual_info(Display *dpy, int scrnum, InfoMode mode)
728{
Brian Paulf02a5f62002-07-12 15:54:01 +0000729 XVisualInfo theTemplate;
Brian Paul76bc4402000-01-27 16:43:56 +0000730 XVisualInfo *visuals;
731 int numVisuals;
732 long mask;
733 int i;
734
735 /* get list of all visuals on this screen */
Brian Paulf02a5f62002-07-12 15:54:01 +0000736 theTemplate.screen = scrnum;
Brian Paul76bc4402000-01-27 16:43:56 +0000737 mask = VisualScreenMask;
Brian Paulf02a5f62002-07-12 15:54:01 +0000738 visuals = XGetVisualInfo(dpy, mask, &theTemplate, &numVisuals);
Brian Paul76bc4402000-01-27 16:43:56 +0000739
740 if (mode == Verbose) {
741 for (i = 0; i < numVisuals; i++) {
742 struct visual_attribs attribs;
743 get_visual_attribs(dpy, &visuals[i], &attribs);
744 print_visual_attribs_verbose(&attribs);
745 }
746 }
747 else if (mode == Normal) {
748 print_visual_attribs_short_header();
749 for (i = 0; i < numVisuals; i++) {
750 struct visual_attribs attribs;
751 get_visual_attribs(dpy, &visuals[i], &attribs);
752 print_visual_attribs_short(&attribs);
753 }
754 }
755 else if (mode == Wide) {
756 print_visual_attribs_long_header();
757 for (i = 0; i < numVisuals; i++) {
758 struct visual_attribs attribs;
759 get_visual_attribs(dpy, &visuals[i], &attribs);
760 print_visual_attribs_long(&attribs);
761 }
762 }
763
764 XFree(visuals);
765}
766
767
Brian Paul39557c32001-03-23 21:41:44 +0000768/*
769 * Stand-alone Mesa doesn't really implement the GLX protocol so it
770 * doesn't really know the GLX attributes associated with an X visual.
771 * The first time a visual is presented to Mesa's pseudo-GLX it
772 * attaches ancilliary buffers to it (like depth and stencil).
773 * But that usually only works if glXChooseVisual is used.
774 * This function calls glXChooseVisual() to sort of "prime the pump"
775 * for Mesa's GLX so that the visuals that get reported actually
776 * reflect what applications will see.
777 * This has no effect when using true GLX.
778 */
779static void
780mesa_hack(Display *dpy, int scrnum)
781{
782 static int attribs[] = {
783 GLX_RGBA,
784 GLX_RED_SIZE, 1,
785 GLX_GREEN_SIZE, 1,
786 GLX_BLUE_SIZE, 1,
787 GLX_DEPTH_SIZE, 1,
788 GLX_STENCIL_SIZE, 1,
789 GLX_ACCUM_RED_SIZE, 1,
790 GLX_ACCUM_GREEN_SIZE, 1,
791 GLX_ACCUM_BLUE_SIZE, 1,
792 GLX_ACCUM_ALPHA_SIZE, 1,
793 GLX_DOUBLEBUFFER,
794 None
795 };
796 XVisualInfo *visinfo;
797
798 visinfo = glXChooseVisual(dpy, scrnum, attribs);
799 if (visinfo)
800 XFree(visinfo);
801}
802
803
804/*
805 * Examine all visuals to find the so-called best one.
806 * We prefer deepest RGBA buffer with depth, stencil and accum
807 * that has no caveats.
808 */
809static int
810find_best_visual(Display *dpy, int scrnum)
811{
Brian Paulf02a5f62002-07-12 15:54:01 +0000812 XVisualInfo theTemplate;
Brian Paul39557c32001-03-23 21:41:44 +0000813 XVisualInfo *visuals;
814 int numVisuals;
815 long mask;
816 int i;
817 struct visual_attribs bestVis;
818
819 /* get list of all visuals on this screen */
Brian Paulf02a5f62002-07-12 15:54:01 +0000820 theTemplate.screen = scrnum;
Brian Paul39557c32001-03-23 21:41:44 +0000821 mask = VisualScreenMask;
Brian Paulf02a5f62002-07-12 15:54:01 +0000822 visuals = XGetVisualInfo(dpy, mask, &theTemplate, &numVisuals);
Brian Paul39557c32001-03-23 21:41:44 +0000823
824 /* init bestVis with first visual info */
825 get_visual_attribs(dpy, &visuals[0], &bestVis);
826
827 /* try to find a "better" visual */
828 for (i = 1; i < numVisuals; i++) {
829 struct visual_attribs vis;
830
831 get_visual_attribs(dpy, &visuals[i], &vis);
832
833 /* always skip visuals with caveats */
834 if (vis.visualCaveat != GLX_NONE_EXT)
835 continue;
836
837 /* see if this vis is better than bestVis */
838 if ((!bestVis.supportsGL && vis.supportsGL) ||
839 (bestVis.visualCaveat != GLX_NONE_EXT) ||
840 (!bestVis.rgba && vis.rgba) ||
841 (!bestVis.doubleBuffer && vis.doubleBuffer) ||
842 (bestVis.redSize < vis.redSize) ||
843 (bestVis.greenSize < vis.greenSize) ||
844 (bestVis.blueSize < vis.blueSize) ||
845 (bestVis.alphaSize < vis.alphaSize) ||
846 (bestVis.depthSize < vis.depthSize) ||
847 (bestVis.stencilSize < vis.stencilSize) ||
848 (bestVis.accumRedSize < vis.accumRedSize)) {
849 /* found a better visual */
850 bestVis = vis;
851 }
852 }
853
854 XFree(visuals);
855
856 return bestVis.id;
857}
858
859
Brian Paul08b3ff12001-04-24 20:57:36 +0000860static void
861usage(void)
862{
863 printf("Usage: glxinfo [-v] [-t] [-h] [-i] [-b] [-display <dname>]\n");
864 printf("\t-v: Print visuals info in verbose form.\n");
865 printf("\t-t: Print verbose table.\n");
866 printf("\t-display <dname>: Print GLX visuals on specified server.\n");
867 printf("\t-h: This information.\n");
868 printf("\t-i: Force an indirect rendering context.\n");
869 printf("\t-b: Find the 'best' visual and print it's number.\n");
Brian Paul0b77a1c2003-04-09 21:50:08 +0000870 printf("\t-l: Print interesting OpenGL limits.\n");
Brian Paul08b3ff12001-04-24 20:57:36 +0000871}
872
873
Brian Paul76bc4402000-01-27 16:43:56 +0000874int
875main(int argc, char *argv[])
876{
Alan Hourihanee18599a2001-03-19 13:58:45 +0000877 char *displayName = NULL;
Brian Paul76bc4402000-01-27 16:43:56 +0000878 Display *dpy;
879 int numScreens, scrnum;
880 InfoMode mode = Normal;
Brian Paul39557c32001-03-23 21:41:44 +0000881 GLboolean findBest = GL_FALSE;
Brian Paul2f7ef5f2002-09-06 03:35:43 +0000882 GLboolean limits = GL_FALSE;
Brian Paul08b3ff12001-04-24 20:57:36 +0000883 Bool allowDirect = True;
Brian Paul76bc4402000-01-27 16:43:56 +0000884 int i;
885
886 for (i = 1; i < argc; i++) {
887 if (strcmp(argv[i], "-display") == 0 && i + 1 < argc) {
888 displayName = argv[i + 1];
889 i++;
890 }
891 else if (strcmp(argv[i], "-t") == 0) {
892 mode = Wide;
893 }
894 else if (strcmp(argv[i], "-v") == 0) {
895 mode = Verbose;
896 }
Brian Paul39557c32001-03-23 21:41:44 +0000897 else if (strcmp(argv[i], "-b") == 0) {
898 findBest = GL_TRUE;
899 }
Brian Paul08b3ff12001-04-24 20:57:36 +0000900 else if (strcmp(argv[i], "-i") == 0) {
901 allowDirect = False;
902 }
Brian Paul2f7ef5f2002-09-06 03:35:43 +0000903 else if (strcmp(argv[i], "-l") == 0) {
904 limits = GL_TRUE;
905 }
Brian Paul08b3ff12001-04-24 20:57:36 +0000906 else if (strcmp(argv[i], "-h") == 0) {
907 usage();
908 return 0;
909 }
910 else {
911 printf("Unknown option `%s'\n", argv[i]);
912 usage();
913 return 0;
914 }
Brian Paul76bc4402000-01-27 16:43:56 +0000915 }
916
917 dpy = XOpenDisplay(displayName);
918 if (!dpy) {
919 fprintf(stderr, "Error: unable to open display %s\n", displayName);
920 return -1;
921 }
922
Brian Paul39557c32001-03-23 21:41:44 +0000923 if (findBest) {
924 int b;
925 mesa_hack(dpy, 0);
926 b = find_best_visual(dpy, 0);
927 printf("%d\n", b);
928 }
929 else {
930 numScreens = ScreenCount(dpy);
Brian Paul373aea12001-04-02 22:45:07 +0000931 print_display_info(dpy);
Brian Paul39557c32001-03-23 21:41:44 +0000932 for (scrnum = 0; scrnum < numScreens; scrnum++) {
933 mesa_hack(dpy, scrnum);
Brian Paul2f7ef5f2002-09-06 03:35:43 +0000934 print_screen_info(dpy, scrnum, allowDirect, limits);
Brian Paul39557c32001-03-23 21:41:44 +0000935 printf("\n");
936 print_visual_info(dpy, scrnum, mode);
937 if (scrnum + 1 < numScreens)
938 printf("\n\n");
939 }
Brian Paul76bc4402000-01-27 16:43:56 +0000940 }
941
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000942 XCloseDisplay(dpy);
943
944 return 0;
945}