blob: dfad1d391952a2793d020227d60f1e84fde00582 [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 Paul2ca741a2006-05-15 15:35:38 +000036#define GLX_GLXEXT_PROTOTYPES
37
Brian Paul76bc4402000-01-27 16:43:56 +000038#include <X11/Xlib.h>
39#include <X11/Xutil.h>
Brian Pauld2bfe1e1999-09-16 16:40:46 +000040#include <GL/gl.h>
Brian Paul76bc4402000-01-27 16:43:56 +000041#include <GL/glx.h>
Brian Pauld2bfe1e1999-09-16 16:40:46 +000042#include <stdio.h>
Brian Paul76bc4402000-01-27 16:43:56 +000043#include <string.h>
Brian Paul373aea12001-04-02 22:45:07 +000044#include <stdlib.h>
Brian Pauld2bfe1e1999-09-16 16:40:46 +000045
46
Brian Paul39557c32001-03-23 21:41:44 +000047#ifndef GLX_NONE_EXT
48#define GLX_NONE_EXT 0x8000
49#endif
50
Brian Paul45c56982002-10-14 13:57:23 +000051#ifndef GLX_TRANSPARENT_RGB
52#define GLX_TRANSPARENT_RGB 0x8008
53#endif
Brian Paul39557c32001-03-23 21:41:44 +000054
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -040055#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 Paul2ca741a2006-05-15 15:35:38 +000062
Brian Paul76bc4402000-01-27 16:43:56 +000063typedef enum
Brian Pauld2bfe1e1999-09-16 16:40:46 +000064{
Brian Paul76bc4402000-01-27 16:43:56 +000065 Normal,
66 Wide,
67 Verbose
68} InfoMode;
Brian Pauld2bfe1e1999-09-16 16:40:46 +000069
Brian Pauld2bfe1e1999-09-16 16:40:46 +000070
Brian Paul76bc4402000-01-27 16:43:56 +000071struct 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 Pauld2bfe1e1999-09-16 16:40:46 +000080
Brian Paul76bc4402000-01-27 16:43:56 +000081 /* GL visual attribs */
82 int supportsGL;
Brian Paul45c56982002-10-14 13:57:23 +000083 int transparentType;
84 int transparentRedValue;
85 int transparentGreenValue;
86 int transparentBlueValue;
87 int transparentAlphaValue;
88 int transparentIndexValue;
Brian Paul76bc4402000-01-27 16:43:56 +000089 int bufferSize;
90 int level;
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -040091 int render_type;
Brian Paul76bc4402000-01-27 16:43:56 +000092 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 Paul25673f02000-03-31 18:17:51 +0000100 int visualCaveat;
Brian Paul76bc4402000-01-27 16:43:56 +0000101};
102
103
104/*
105 * Print a list of extensions, with word-wrapping.
106 */
107static void
108print_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 Paul7ac43502000-02-23 22:50:35 +0000144 if (ext[j] == 0)
145 break;
Brian Paul76bc4402000-01-27 16:43:56 +0000146 printf(", ");
147 width += 2;
148 }
149 }
150 j++;
151 }
152 printf("\n");
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000153}
154
155
Brian Paul76bc4402000-01-27 16:43:56 +0000156static void
Brian Paul373aea12001-04-02 22:45:07 +0000157print_display_info(Display *dpy)
158{
159 printf("name of display: %s\n", DisplayString(dpy));
160}
161
162
Brian Paulad7805d2006-05-13 00:18:12 +0000163/**
164 * Print interesting limits for vertex/fragment programs.
165 */
Brian Paul373aea12001-04-02 22:45:07 +0000166static void
Brian Paulad7805d2006-05-13 00:18:12 +0000167print_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 Paul2ca741a2006-05-15 15:35:38 +0000216#endif /* GL_ARB_vertex_program / GL_ARB_fragment_program */
Brian Paulad7805d2006-05-13 00:18:12 +0000217}
218
219
220/**
221 * Print interesting limits for vertex/fragment shaders.
222 */
223static void
224print_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 */
281static void
282print_limits(const char *extensions)
Brian Paul2f7ef5f2002-09-06 03:35:43 +0000283{
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 Paul2f7ef5f2002-09-06 03:35:43 +0000294 { 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 Paul2f7ef5f2002-09-06 03:35:43 +0000306 { 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 Paulad7805d2006-05-13 00:18:12 +0000311#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 Paul2f7ef5f2002-09-06 03:35:43 +0000332 { 0, (GLenum) 0, NULL }
333 };
334 GLint i, max[2];
Brian Paulad7805d2006-05-13 00:18:12 +0000335
Brian Paul2f7ef5f2002-09-06 03:35:43 +0000336 printf("OpenGL limits:\n");
337 for (i = 0; limits[i].count; i++) {
338 glGetIntegerv(limits[i].token, max);
Brian Paulad7805d2006-05-13 00:18:12 +0000339 if (glGetError() == GL_NO_ERROR) {
Brian Paul2f7ef5f2002-09-06 03:35:43 +0000340 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 Paulad7805d2006-05-13 00:18:12 +0000346
Brian Paulf2afdca2004-08-10 15:32:25 +0000347 /* 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 Paul2ca741a2006-05-15 15:35:38 +0000354#if defined(GL_ARB_vertex_program)
Brian Paulad7805d2006-05-13 00:18:12 +0000355 if (strstr(extensions, "GL_ARB_vertex_program")) {
356 print_program_limits(GL_VERTEX_PROGRAM_ARB);
357 }
Brian Paul2ca741a2006-05-15 15:35:38 +0000358#endif
359#if defined(GL_ARB_fragment_program)
Brian Paulad7805d2006-05-13 00:18:12 +0000360 if (strstr(extensions, "GL_ARB_fragment_program")) {
361 print_program_limits(GL_FRAGMENT_PROGRAM_ARB);
362 }
Brian Paul2ca741a2006-05-15 15:35:38 +0000363#endif
364#if defined(GL_ARB_vertex_shader)
Brian Paulad7805d2006-05-13 00:18:12 +0000365 if (strstr(extensions, "GL_ARB_vertex_shader")) {
366 print_shader_limits(GL_VERTEX_SHADER_ARB);
367 }
Brian Paul2ca741a2006-05-15 15:35:38 +0000368#endif
369#if defined(GL_ARB_fragment_shader)
Brian Paulad7805d2006-05-13 00:18:12 +0000370 if (strstr(extensions, "GL_ARB_fragment_shader")) {
371 print_shader_limits(GL_FRAGMENT_SHADER_ARB);
372 }
Brian Paul2ca741a2006-05-15 15:35:38 +0000373#endif
Brian Paul2f7ef5f2002-09-06 03:35:43 +0000374}
375
376
377static void
378print_screen_info(Display *dpy, int scrnum, Bool allowDirect, GLboolean limits)
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000379{
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000380 Window win;
Brian Paul8460cc92000-02-02 20:57:51 +0000381 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 Pauld2bfe1e1999-09-16 16:40:46 +0000395 XSetWindowAttributes attr;
396 unsigned long mask;
397 Window root;
398 GLXContext ctx;
399 XVisualInfo *visinfo;
400 int width = 100, height = 100;
401
Brian Paul76bc4402000-01-27 16:43:56 +0000402 root = RootWindow(dpy, scrnum);
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000403
Brian Paul8460cc92000-02-02 20:57:51 +0000404 visinfo = glXChooseVisual(dpy, scrnum, attribSingle);
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000405 if (!visinfo) {
Brian Paul8460cc92000-02-02 20:57:51 +0000406 visinfo = glXChooseVisual(dpy, scrnum, attribDouble);
407 if (!visinfo) {
Brian Paul9cff5582000-05-07 18:07:23 +0000408 fprintf(stderr, "Error: couldn't find RGB GLX visual\n");
Brian Paul8460cc92000-02-02 20:57:51 +0000409 return;
410 }
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000411 }
412
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000413 attr.background_pixel = 0;
414 attr.border_pixel = 0;
Brian Paul9cff5582000-05-07 18:07:23 +0000415 attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone);
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000416 attr.event_mask = StructureNotifyMask | ExposureMask;
417 mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
Brian Paul76bc4402000-01-27 16:43:56 +0000418 win = XCreateWindow(dpy, root, 0, 0, width, height,
419 0, visinfo->depth, InputOutput,
420 visinfo->visual, mask, &attr);
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000421
Brian Paul08b3ff12001-04-24 20:57:36 +0000422 ctx = glXCreateContext( dpy, visinfo, NULL, allowDirect );
Brian Paul34fb5db2000-04-22 20:31:23 +0000423 if (!ctx) {
Brian Paul9cff5582000-05-07 18:07:23 +0000424 fprintf(stderr, "Error: glXCreateContext failed\n");
Brian Paul361bccb2006-01-16 16:17:18 +0000425 XFree(visinfo);
Brian Paul34fb5db2000-04-22 20:31:23 +0000426 XDestroyWindow(dpy, win);
427 return;
428 }
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000429
Brian Paul9cff5582000-05-07 18:07:23 +0000430 if (glXMakeCurrent(dpy, win, ctx)) {
Brian Paul76bc4402000-01-27 16:43:56 +0000431 const char *serverVendor = glXQueryServerString(dpy, scrnum, GLX_VENDOR);
432 const char *serverVersion = glXQueryServerString(dpy, scrnum, GLX_VERSION);
433 const char *serverExtensions = glXQueryServerString(dpy, scrnum, GLX_EXTENSIONS);
Brian Paul34fb5db2000-04-22 20:31:23 +0000434 const char *clientVendor = glXGetClientString(dpy, GLX_VENDOR);
Brian Paul76bc4402000-01-27 16:43:56 +0000435 const char *clientVersion = glXGetClientString(dpy, GLX_VERSION);
436 const char *clientExtensions = glXGetClientString(dpy, GLX_EXTENSIONS);
437 const char *glxExtensions = glXQueryExtensionsString(dpy, scrnum);
438 const char *glVendor = (const char *) glGetString(GL_VENDOR);
439 const char *glRenderer = (const char *) glGetString(GL_RENDERER);
440 const char *glVersion = (const char *) glGetString(GL_VERSION);
441 const char *glExtensions = (const char *) glGetString(GL_EXTENSIONS);
Ian Romanickc00fbd52004-02-23 17:37:36 +0000442 int glxVersionMajor;
443 int glxVersionMinor;
Brian Paul373aea12001-04-02 22:45:07 +0000444 char *displayName = NULL;
445 char *colon = NULL, *period = NULL;
Ian Romanickc00fbd52004-02-23 17:37:36 +0000446
447 if (! glXQueryVersion( dpy, & glxVersionMajor, & glxVersionMinor )) {
448 fprintf(stderr, "Error: glXQueryVersion failed\n");
449 exit(1);
450 }
451
Brian Paul373aea12001-04-02 22:45:07 +0000452 /* Strip the screen number from the display name, if present. */
Brian Paulf02a5f62002-07-12 15:54:01 +0000453 if (!(displayName = (char *) malloc(strlen(DisplayString(dpy)) + 1))) {
Brian Paul373aea12001-04-02 22:45:07 +0000454 fprintf(stderr, "Error: malloc() failed\n");
455 exit(1);
456 }
457 strcpy(displayName, DisplayString(dpy));
458 colon = strrchr(displayName, ':');
459 if (colon) {
460 period = strchr(colon, '.');
461 if (period)
462 *period = '\0';
463 }
464 printf("display: %s screen: %d\n", displayName, scrnum);
465 free(displayName);
Michel Dänzerb46e3592006-12-06 14:54:43 +0100466 printf("direct rendering: ");
467 if (glXIsDirect(dpy, ctx)) {
468 printf("Yes\n");
469 } else {
470 if (!allowDirect) {
471 printf("No (-i specified)\n");
472 } else if (getenv("LIBGL_ALWAYS_INDIRECT")) {
473 printf("No (LIBGL_ALWAYS_INDIRECT set)\n");
474 } else {
475 printf("No (If you want to find out why, try setting "
476 "LIBGL_DEBUG=verbose)\n");
477 }
478 }
Brian Paul76bc4402000-01-27 16:43:56 +0000479 printf("server glx vendor string: %s\n", serverVendor);
480 printf("server glx version string: %s\n", serverVersion);
481 printf("server glx extensions:\n");
482 print_extension_list(serverExtensions);
Brian Paul34fb5db2000-04-22 20:31:23 +0000483 printf("client glx vendor string: %s\n", clientVendor);
484 printf("client glx version string: %s\n", clientVersion);
Brian Paul76bc4402000-01-27 16:43:56 +0000485 printf("client glx extensions:\n");
486 print_extension_list(clientExtensions);
Ian Romanickc00fbd52004-02-23 17:37:36 +0000487 printf("GLX version: %u.%u\n", glxVersionMajor, glxVersionMinor);
Brian Paul76bc4402000-01-27 16:43:56 +0000488 printf("GLX extensions:\n");
489 print_extension_list(glxExtensions);
490 printf("OpenGL vendor string: %s\n", glVendor);
491 printf("OpenGL renderer string: %s\n", glRenderer);
492 printf("OpenGL version string: %s\n", glVersion);
493 printf("OpenGL extensions:\n");
494 print_extension_list(glExtensions);
Brian Paul2f7ef5f2002-09-06 03:35:43 +0000495 if (limits)
Brian Paulad7805d2006-05-13 00:18:12 +0000496 print_limits(glExtensions);
Brian Paul76bc4402000-01-27 16:43:56 +0000497 }
Brian Paul9cff5582000-05-07 18:07:23 +0000498 else {
499 fprintf(stderr, "Error: glXMakeCurrent failed\n");
500 }
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000501
502 glXDestroyContext(dpy, ctx);
Brian Paul361bccb2006-01-16 16:17:18 +0000503 XFree(visinfo);
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000504 XDestroyWindow(dpy, win);
Brian Paul76bc4402000-01-27 16:43:56 +0000505}
506
507
508static const char *
509visual_class_name(int cls)
510{
511 switch (cls) {
512 case StaticColor:
513 return "StaticColor";
514 case PseudoColor:
515 return "PseudoColor";
516 case StaticGray:
517 return "StaticGray";
518 case GrayScale:
519 return "GrayScale";
520 case TrueColor:
521 return "TrueColor";
522 case DirectColor:
523 return "DirectColor";
524 default:
525 return "";
526 }
527}
528
529
530static const char *
531visual_class_abbrev(int cls)
532{
533 switch (cls) {
534 case StaticColor:
535 return "sc";
536 case PseudoColor:
537 return "pc";
538 case StaticGray:
539 return "sg";
540 case GrayScale:
541 return "gs";
542 case TrueColor:
543 return "tc";
544 case DirectColor:
545 return "dc";
546 default:
547 return "";
548 }
549}
550
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400551static const char *
552visual_render_type_name(int type)
553{
554 switch (type) {
555 case GLX_RGBA_BIT:
556 return "rgba";
557 case GLX_COLOR_INDEX_BIT:
558 return "ci";
559 case GLX_RGBA_BIT | GLX_COLOR_INDEX_BIT:
560 return "rgba|ci";
561 default:
562 return "";
563 }
564}
Brian Paul76bc4402000-01-27 16:43:56 +0000565
Kristian Høgsbergf7d1d552007-10-15 20:12:01 -0400566static GLboolean
Brian Paul76bc4402000-01-27 16:43:56 +0000567get_visual_attribs(Display *dpy, XVisualInfo *vInfo,
568 struct visual_attribs *attribs)
569{
Brian Paul25673f02000-03-31 18:17:51 +0000570 const char *ext = glXQueryExtensionsString(dpy, vInfo->screen);
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400571 int rgba;
Brian Paul25673f02000-03-31 18:17:51 +0000572
Brian Paula9c53fa2000-04-03 15:45:34 +0000573 memset(attribs, 0, sizeof(struct visual_attribs));
574
Brian Paul76bc4402000-01-27 16:43:56 +0000575 attribs->id = vInfo->visualid;
576#if defined(__cplusplus) || defined(c_plusplus)
577 attribs->klass = vInfo->c_class;
578#else
579 attribs->klass = vInfo->class;
580#endif
581 attribs->depth = vInfo->depth;
582 attribs->redMask = vInfo->red_mask;
583 attribs->greenMask = vInfo->green_mask;
584 attribs->blueMask = vInfo->blue_mask;
585 attribs->colormapSize = vInfo->colormap_size;
586 attribs->bitsPerRGB = vInfo->bits_per_rgb;
587
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400588 if (glXGetConfig(dpy, vInfo, GLX_USE_GL, &attribs->supportsGL) != 0 ||
589 !attribs->supportsGL)
Kristian Høgsbergf7d1d552007-10-15 20:12:01 -0400590 return GL_FALSE;
Brian Paul76bc4402000-01-27 16:43:56 +0000591 glXGetConfig(dpy, vInfo, GLX_BUFFER_SIZE, &attribs->bufferSize);
592 glXGetConfig(dpy, vInfo, GLX_LEVEL, &attribs->level);
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400593 glXGetConfig(dpy, vInfo, GLX_RGBA, &rgba);
594 if (rgba)
595 attribs->render_type = GLX_RGBA_BIT;
596 else
597 attribs->render_type = GLX_COLOR_INDEX_BIT;
598
Brian Paul76bc4402000-01-27 16:43:56 +0000599 glXGetConfig(dpy, vInfo, GLX_DOUBLEBUFFER, &attribs->doubleBuffer);
600 glXGetConfig(dpy, vInfo, GLX_STEREO, &attribs->stereo);
601 glXGetConfig(dpy, vInfo, GLX_AUX_BUFFERS, &attribs->auxBuffers);
602 glXGetConfig(dpy, vInfo, GLX_RED_SIZE, &attribs->redSize);
603 glXGetConfig(dpy, vInfo, GLX_GREEN_SIZE, &attribs->greenSize);
604 glXGetConfig(dpy, vInfo, GLX_BLUE_SIZE, &attribs->blueSize);
605 glXGetConfig(dpy, vInfo, GLX_ALPHA_SIZE, &attribs->alphaSize);
606 glXGetConfig(dpy, vInfo, GLX_DEPTH_SIZE, &attribs->depthSize);
607 glXGetConfig(dpy, vInfo, GLX_STENCIL_SIZE, &attribs->stencilSize);
608 glXGetConfig(dpy, vInfo, GLX_ACCUM_RED_SIZE, &attribs->accumRedSize);
609 glXGetConfig(dpy, vInfo, GLX_ACCUM_GREEN_SIZE, &attribs->accumGreenSize);
610 glXGetConfig(dpy, vInfo, GLX_ACCUM_BLUE_SIZE, &attribs->accumBlueSize);
611 glXGetConfig(dpy, vInfo, GLX_ACCUM_ALPHA_SIZE, &attribs->accumAlphaSize);
612
Brian Paul45c56982002-10-14 13:57:23 +0000613 /* get transparent pixel stuff */
614 glXGetConfig(dpy, vInfo,GLX_TRANSPARENT_TYPE, &attribs->transparentType);
615 if (attribs->transparentType == GLX_TRANSPARENT_RGB) {
616 glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_RED_VALUE, &attribs->transparentRedValue);
617 glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_GREEN_VALUE, &attribs->transparentGreenValue);
618 glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_BLUE_VALUE, &attribs->transparentBlueValue);
619 glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_ALPHA_VALUE, &attribs->transparentAlphaValue);
620 }
621 else if (attribs->transparentType == GLX_TRANSPARENT_INDEX) {
622 glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_INDEX_VALUE, &attribs->transparentIndexValue);
623 }
Brian Paule06c7f32000-01-27 16:53:55 +0000624
Brian Pauld2e39bb2002-11-04 16:24:18 +0000625 /* multisample attribs */
626#ifdef GLX_ARB_multisample
Brian Paulad7805d2006-05-13 00:18:12 +0000627 if (ext && strstr(ext, "GLX_ARB_multisample") == 0) {
Brian Pauld2e39bb2002-11-04 16:24:18 +0000628 glXGetConfig(dpy, vInfo, GLX_SAMPLE_BUFFERS_ARB, &attribs->numMultisample);
629 glXGetConfig(dpy, vInfo, GLX_SAMPLES_ARB, &attribs->numSamples);
630 }
631#endif
632 else {
633 attribs->numSamples = 0;
634 attribs->numMultisample = 0;
635 }
Brian Paul25673f02000-03-31 18:17:51 +0000636
637#if defined(GLX_EXT_visual_rating)
638 if (ext && strstr(ext, "GLX_EXT_visual_rating")) {
639 glXGetConfig(dpy, vInfo, GLX_VISUAL_CAVEAT_EXT, &attribs->visualCaveat);
640 }
641 else {
642 attribs->visualCaveat = GLX_NONE_EXT;
643 }
644#else
645 attribs->visualCaveat = 0;
646#endif
Kristian Høgsbergf7d1d552007-10-15 20:12:01 -0400647
648 return GL_TRUE;
Brian Paul76bc4402000-01-27 16:43:56 +0000649}
650
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400651#ifdef GLX_VERSION_1_3
652
653static int
654glx_token_to_visual_class(int visual_type)
655{
656 switch (visual_type) {
657 case GLX_TRUE_COLOR:
658 return TrueColor;
659 case GLX_DIRECT_COLOR:
660 return DirectColor;
661 case GLX_PSEUDO_COLOR:
662 return PseudoColor;
663 case GLX_STATIC_COLOR:
664 return StaticColor;
665 case GLX_GRAY_SCALE:
666 return GrayScale;
667 case GLX_STATIC_GRAY:
668 return StaticGray;
669 case GLX_NONE:
670 default:
671 return None;
672 }
673}
674
675static GLboolean
676get_fbconfig_attribs(Display *dpy, GLXFBConfig fbconfig,
677 struct visual_attribs *attribs)
678{
679 int visual_type;
680
681 memset(attribs, 0, sizeof(struct visual_attribs));
682
683 glXGetFBConfigAttrib(dpy, fbconfig, GLX_FBCONFIG_ID, &attribs->id);
684
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400685#if 0
686 attribs->depth = vInfo->depth;
687 attribs->redMask = vInfo->red_mask;
688 attribs->greenMask = vInfo->green_mask;
689 attribs->blueMask = vInfo->blue_mask;
690 attribs->colormapSize = vInfo->colormap_size;
691 attribs->bitsPerRGB = vInfo->bits_per_rgb;
692#endif
693
694 glXGetFBConfigAttrib(dpy, fbconfig, GLX_X_VISUAL_TYPE, &visual_type);
695 attribs->klass = glx_token_to_visual_class(visual_type);
696
697 glXGetFBConfigAttrib(dpy, fbconfig, GLX_BUFFER_SIZE, &attribs->bufferSize);
698 glXGetFBConfigAttrib(dpy, fbconfig, GLX_LEVEL, &attribs->level);
699 glXGetFBConfigAttrib(dpy, fbconfig, GLX_RENDER_TYPE, &attribs->render_type);
700 glXGetFBConfigAttrib(dpy, fbconfig, GLX_DOUBLEBUFFER, &attribs->doubleBuffer);
701 glXGetFBConfigAttrib(dpy, fbconfig, GLX_STEREO, &attribs->stereo);
702 glXGetFBConfigAttrib(dpy, fbconfig, GLX_AUX_BUFFERS, &attribs->auxBuffers);
703
704 glXGetFBConfigAttrib(dpy, fbconfig, GLX_RED_SIZE, &attribs->redSize);
705 glXGetFBConfigAttrib(dpy, fbconfig, GLX_GREEN_SIZE, &attribs->greenSize);
706 glXGetFBConfigAttrib(dpy, fbconfig, GLX_BLUE_SIZE, &attribs->blueSize);
707 glXGetFBConfigAttrib(dpy, fbconfig, GLX_ALPHA_SIZE, &attribs->alphaSize);
708 glXGetFBConfigAttrib(dpy, fbconfig, GLX_DEPTH_SIZE, &attribs->depthSize);
709 glXGetFBConfigAttrib(dpy, fbconfig, GLX_STENCIL_SIZE, &attribs->stencilSize);
710
711 glXGetFBConfigAttrib(dpy, fbconfig, GLX_ACCUM_RED_SIZE, &attribs->accumRedSize);
712 glXGetFBConfigAttrib(dpy, fbconfig, GLX_ACCUM_GREEN_SIZE, &attribs->accumGreenSize);
713 glXGetFBConfigAttrib(dpy, fbconfig, GLX_ACCUM_BLUE_SIZE, &attribs->accumBlueSize);
714 glXGetFBConfigAttrib(dpy, fbconfig, GLX_ACCUM_ALPHA_SIZE, &attribs->accumAlphaSize);
715
716 /* get transparent pixel stuff */
717 glXGetFBConfigAttrib(dpy, fbconfig,GLX_TRANSPARENT_TYPE, &attribs->transparentType);
718 if (attribs->transparentType == GLX_TRANSPARENT_RGB) {
719 glXGetFBConfigAttrib(dpy, fbconfig, GLX_TRANSPARENT_RED_VALUE, &attribs->transparentRedValue);
720 glXGetFBConfigAttrib(dpy, fbconfig, GLX_TRANSPARENT_GREEN_VALUE, &attribs->transparentGreenValue);
721 glXGetFBConfigAttrib(dpy, fbconfig, GLX_TRANSPARENT_BLUE_VALUE, &attribs->transparentBlueValue);
722 glXGetFBConfigAttrib(dpy, fbconfig, GLX_TRANSPARENT_ALPHA_VALUE, &attribs->transparentAlphaValue);
723 }
724 else if (attribs->transparentType == GLX_TRANSPARENT_INDEX) {
725 glXGetFBConfigAttrib(dpy, fbconfig, GLX_TRANSPARENT_INDEX_VALUE, &attribs->transparentIndexValue);
726 }
727
728 glXGetFBConfigAttrib(dpy, fbconfig, GLX_SAMPLE_BUFFERS, &attribs->numMultisample);
729 glXGetFBConfigAttrib(dpy, fbconfig, GLX_SAMPLES, &attribs->numSamples);
730 glXGetFBConfigAttrib(dpy, fbconfig, GLX_CONFIG_CAVEAT, &attribs->visualCaveat);
731
732 return GL_TRUE;
733}
734
735#endif
736
737
Brian Paul76bc4402000-01-27 16:43:56 +0000738
739static void
740print_visual_attribs_verbose(const struct visual_attribs *attribs)
741{
742 printf("Visual ID: %x depth=%d class=%s\n",
743 attribs->id, attribs->depth, visual_class_name(attribs->klass));
744 printf(" bufferSize=%d level=%d renderType=%s doubleBuffer=%d stereo=%d\n",
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400745 attribs->bufferSize, attribs->level,
746 visual_render_type_name(attribs->render_type),
Brian Paul76bc4402000-01-27 16:43:56 +0000747 attribs->doubleBuffer, attribs->stereo);
748 printf(" rgba: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n",
749 attribs->redSize, attribs->greenSize,
750 attribs->blueSize, attribs->alphaSize);
751 printf(" auxBuffers=%d depthSize=%d stencilSize=%d\n",
752 attribs->auxBuffers, attribs->depthSize, attribs->stencilSize);
753 printf(" accum: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n",
754 attribs->accumRedSize, attribs->accumGreenSize,
755 attribs->accumBlueSize, attribs->accumAlphaSize);
756 printf(" multiSample=%d multiSampleBuffers=%d\n",
757 attribs->numSamples, attribs->numMultisample);
Brian Paul25673f02000-03-31 18:17:51 +0000758#ifdef GLX_EXT_visual_rating
759 if (attribs->visualCaveat == GLX_NONE_EXT || attribs->visualCaveat == 0)
Brian Paula9c53fa2000-04-03 15:45:34 +0000760 printf(" visualCaveat=None\n");
Brian Paul25673f02000-03-31 18:17:51 +0000761 else if (attribs->visualCaveat == GLX_SLOW_VISUAL_EXT)
Brian Paula9c53fa2000-04-03 15:45:34 +0000762 printf(" visualCaveat=Slow\n");
Brian Paul25673f02000-03-31 18:17:51 +0000763 else if (attribs->visualCaveat == GLX_NON_CONFORMANT_VISUAL_EXT)
Brian Paula9c53fa2000-04-03 15:45:34 +0000764 printf(" visualCaveat=Nonconformant\n");
Brian Paul25673f02000-03-31 18:17:51 +0000765#endif
Brian Paul45c56982002-10-14 13:57:23 +0000766 if (attribs->transparentType == GLX_NONE) {
767 printf(" Opaque.\n");
768 }
769 else if (attribs->transparentType == GLX_TRANSPARENT_RGB) {
770 printf(" Transparent RGB: Red=%d Green=%d Blue=%d Alpha=%d\n",attribs->transparentRedValue,attribs->transparentGreenValue,attribs->transparentBlueValue,attribs->transparentAlphaValue);
771 }
772 else if (attribs->transparentType == GLX_TRANSPARENT_INDEX) {
773 printf(" Transparent index=%d\n",attribs->transparentIndexValue);
774 }
Brian Paul76bc4402000-01-27 16:43:56 +0000775}
776
777
778static void
779print_visual_attribs_short_header(void)
780{
Brian Paula9c53fa2000-04-03 15:45:34 +0000781 printf(" visual x bf lv rg d st colorbuffer ax dp st accumbuffer ms cav\n");
782 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 +0000783 printf("----------------------------------------------------------------------\n");
Brian Paul76bc4402000-01-27 16:43:56 +0000784}
785
786
787static void
788print_visual_attribs_short(const struct visual_attribs *attribs)
789{
Brian Paula3e44f42002-03-08 19:44:28 +0000790 char *caveat = NULL;
Brian Paul25673f02000-03-31 18:17:51 +0000791#ifdef GLX_EXT_visual_rating
792 if (attribs->visualCaveat == GLX_NONE_EXT || attribs->visualCaveat == 0)
793 caveat = "None";
794 else if (attribs->visualCaveat == GLX_SLOW_VISUAL_EXT)
795 caveat = "Slow";
796 else if (attribs->visualCaveat == GLX_NON_CONFORMANT_VISUAL_EXT)
797 caveat = "Ncon";
Brian Paul28bc6cb2002-09-06 03:47:34 +0000798 else
799 caveat = "None";
Brian Paul25673f02000-03-31 18:17:51 +0000800#else
801 caveat = "None";
802#endif
803
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400804 printf("0x%02x %2d %2s %2d %2d %2d %c%c %c %c %2d %2d %2d %2d %2d %2d %2d",
Brian Paul76bc4402000-01-27 16:43:56 +0000805 attribs->id,
806 attribs->depth,
807 visual_class_abbrev(attribs->klass),
Brian Paul45c56982002-10-14 13:57:23 +0000808 attribs->transparentType != GLX_NONE,
Brian Paul76bc4402000-01-27 16:43:56 +0000809 attribs->bufferSize,
810 attribs->level,
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400811 (attribs->render_type & GLX_RGBA_BIT) ? 'r' : ' ',
812 (attribs->render_type & GLX_COLOR_INDEX_BIT) ? 'c' : ' ',
813 attribs->doubleBuffer ? 'y' : '.',
814 attribs->stereo ? 'y' : '.',
Brian Paul76bc4402000-01-27 16:43:56 +0000815 attribs->redSize, attribs->greenSize,
816 attribs->blueSize, attribs->alphaSize,
817 attribs->auxBuffers,
818 attribs->depthSize,
819 attribs->stencilSize
820 );
821
Brian Paul25673f02000-03-31 18:17:51 +0000822 printf(" %2d %2d %2d %2d %2d %1d %s\n",
Brian Paul76bc4402000-01-27 16:43:56 +0000823 attribs->accumRedSize, attribs->accumGreenSize,
824 attribs->accumBlueSize, attribs->accumAlphaSize,
Brian Paul25673f02000-03-31 18:17:51 +0000825 attribs->numSamples, attribs->numMultisample,
826 caveat
Brian Paul76bc4402000-01-27 16:43:56 +0000827 );
828}
829
830
831static void
832print_visual_attribs_long_header(void)
833{
834 printf("Vis Vis Visual Trans buff lev render DB ste r g b a aux dep ste accum buffers MS MS\n");
835 printf(" ID Depth Type parent size el type reo sz sz sz sz buf th ncl r g b a num bufs\n");
836 printf("----------------------------------------------------------------------------------------------------\n");
837}
838
839
840static void
841print_visual_attribs_long(const struct visual_attribs *attribs)
842{
843 printf("0x%2x %2d %-11s %2d %2d %2d %4s %3d %3d %3d %3d %3d %3d",
844 attribs->id,
845 attribs->depth,
846 visual_class_name(attribs->klass),
Brian Paul45c56982002-10-14 13:57:23 +0000847 attribs->transparentType != GLX_NONE,
Brian Paul76bc4402000-01-27 16:43:56 +0000848 attribs->bufferSize,
849 attribs->level,
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400850 visual_render_type_name(attribs->render_type),
Brian Paul76bc4402000-01-27 16:43:56 +0000851 attribs->doubleBuffer,
852 attribs->stereo,
853 attribs->redSize, attribs->greenSize,
854 attribs->blueSize, attribs->alphaSize
855 );
856
857 printf(" %3d %4d %2d %3d %3d %3d %3d %2d %2d\n",
858 attribs->auxBuffers,
859 attribs->depthSize,
860 attribs->stencilSize,
861 attribs->accumRedSize, attribs->accumGreenSize,
862 attribs->accumBlueSize, attribs->accumAlphaSize,
863 attribs->numSamples, attribs->numMultisample
864 );
865}
866
867
868static void
869print_visual_info(Display *dpy, int scrnum, InfoMode mode)
870{
Brian Paulf02a5f62002-07-12 15:54:01 +0000871 XVisualInfo theTemplate;
Brian Paul76bc4402000-01-27 16:43:56 +0000872 XVisualInfo *visuals;
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400873 int numVisuals, numGlxVisuals;
Brian Paul76bc4402000-01-27 16:43:56 +0000874 long mask;
875 int i;
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400876 struct visual_attribs attribs;
Brian Paul76bc4402000-01-27 16:43:56 +0000877
878 /* get list of all visuals on this screen */
Brian Paulf02a5f62002-07-12 15:54:01 +0000879 theTemplate.screen = scrnum;
Brian Paul76bc4402000-01-27 16:43:56 +0000880 mask = VisualScreenMask;
Brian Paulf02a5f62002-07-12 15:54:01 +0000881 visuals = XGetVisualInfo(dpy, mask, &theTemplate, &numVisuals);
Brian Paul76bc4402000-01-27 16:43:56 +0000882
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400883 numGlxVisuals = 0;
884 for (i = 0; i < numVisuals; i++) {
885 if (get_visual_attribs(dpy, &visuals[i], &attribs))
886 numGlxVisuals++;
Brian Paul76bc4402000-01-27 16:43:56 +0000887 }
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400888
889 if (numGlxVisuals == 0)
890 return;
891
892 printf("%d GLX Visuals\n", numGlxVisuals);
893
894 if (mode == Normal)
Brian Paul76bc4402000-01-27 16:43:56 +0000895 print_visual_attribs_short_header();
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400896 else if (mode == Wide)
Brian Paul76bc4402000-01-27 16:43:56 +0000897 print_visual_attribs_long_header();
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400898
899 for (i = 0; i < numVisuals; i++) {
900 if (!get_visual_attribs(dpy, &visuals[i], &attribs))
901 continue;
902
903 if (mode == Verbose)
904 print_visual_attribs_verbose(&attribs);
905 else if (mode == Normal)
906 print_visual_attribs_short(&attribs);
907 else if (mode == Wide)
Brian Paul76bc4402000-01-27 16:43:56 +0000908 print_visual_attribs_long(&attribs);
Brian Paul76bc4402000-01-27 16:43:56 +0000909 }
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400910 printf("\n");
Brian Paul76bc4402000-01-27 16:43:56 +0000911
912 XFree(visuals);
913}
914
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400915#ifdef GLX_VERSION_1_3
916
917static void
918print_fbconfig_info(Display *dpy, int scrnum, InfoMode mode)
919{
920 int numFBConfigs;
921 struct visual_attribs attribs;
922 GLXFBConfig *fbconfigs;
923 int i;
924
925 /* get list of all fbconfigs on this screen */
926 fbconfigs = glXGetFBConfigs(dpy, scrnum, &numFBConfigs);
927
928 if (numFBConfigs == 0)
929 return;
930
931 printf("GLXFBConfigs:\n");
932 if (mode == Normal)
933 print_visual_attribs_short_header();
934 else if (mode == Wide)
935 print_visual_attribs_long_header();
936
937 for (i = 0; i < numFBConfigs; i++) {
938 get_fbconfig_attribs(dpy, fbconfigs[i], &attribs);
939
940 if (mode == Verbose)
941 print_visual_attribs_verbose(&attribs);
942 else if (mode == Normal)
943 print_visual_attribs_short(&attribs);
944 else if (mode == Wide)
945 print_visual_attribs_long(&attribs);
946 }
947 printf("\n");
948
949 XFree(fbconfigs);
950}
951
952#endif
Brian Paul76bc4402000-01-27 16:43:56 +0000953
Brian Paul39557c32001-03-23 21:41:44 +0000954/*
955 * Stand-alone Mesa doesn't really implement the GLX protocol so it
956 * doesn't really know the GLX attributes associated with an X visual.
957 * The first time a visual is presented to Mesa's pseudo-GLX it
958 * attaches ancilliary buffers to it (like depth and stencil).
959 * But that usually only works if glXChooseVisual is used.
960 * This function calls glXChooseVisual() to sort of "prime the pump"
961 * for Mesa's GLX so that the visuals that get reported actually
962 * reflect what applications will see.
963 * This has no effect when using true GLX.
964 */
965static void
966mesa_hack(Display *dpy, int scrnum)
967{
968 static int attribs[] = {
969 GLX_RGBA,
970 GLX_RED_SIZE, 1,
971 GLX_GREEN_SIZE, 1,
972 GLX_BLUE_SIZE, 1,
973 GLX_DEPTH_SIZE, 1,
974 GLX_STENCIL_SIZE, 1,
975 GLX_ACCUM_RED_SIZE, 1,
976 GLX_ACCUM_GREEN_SIZE, 1,
977 GLX_ACCUM_BLUE_SIZE, 1,
978 GLX_ACCUM_ALPHA_SIZE, 1,
979 GLX_DOUBLEBUFFER,
980 None
981 };
982 XVisualInfo *visinfo;
983
984 visinfo = glXChooseVisual(dpy, scrnum, attribs);
985 if (visinfo)
986 XFree(visinfo);
987}
988
989
990/*
991 * Examine all visuals to find the so-called best one.
992 * We prefer deepest RGBA buffer with depth, stencil and accum
993 * that has no caveats.
994 */
995static int
996find_best_visual(Display *dpy, int scrnum)
997{
Brian Paulf02a5f62002-07-12 15:54:01 +0000998 XVisualInfo theTemplate;
Brian Paul39557c32001-03-23 21:41:44 +0000999 XVisualInfo *visuals;
1000 int numVisuals;
1001 long mask;
1002 int i;
1003 struct visual_attribs bestVis;
1004
1005 /* get list of all visuals on this screen */
Brian Paulf02a5f62002-07-12 15:54:01 +00001006 theTemplate.screen = scrnum;
Brian Paul39557c32001-03-23 21:41:44 +00001007 mask = VisualScreenMask;
Brian Paulf02a5f62002-07-12 15:54:01 +00001008 visuals = XGetVisualInfo(dpy, mask, &theTemplate, &numVisuals);
Brian Paul39557c32001-03-23 21:41:44 +00001009
1010 /* init bestVis with first visual info */
1011 get_visual_attribs(dpy, &visuals[0], &bestVis);
1012
1013 /* try to find a "better" visual */
1014 for (i = 1; i < numVisuals; i++) {
1015 struct visual_attribs vis;
1016
1017 get_visual_attribs(dpy, &visuals[i], &vis);
1018
1019 /* always skip visuals with caveats */
1020 if (vis.visualCaveat != GLX_NONE_EXT)
1021 continue;
1022
1023 /* see if this vis is better than bestVis */
1024 if ((!bestVis.supportsGL && vis.supportsGL) ||
1025 (bestVis.visualCaveat != GLX_NONE_EXT) ||
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -04001026 (!(bestVis.render_type & GLX_RGBA_BIT) && (vis.render_type & GLX_RGBA_BIT)) ||
Brian Paul39557c32001-03-23 21:41:44 +00001027 (!bestVis.doubleBuffer && vis.doubleBuffer) ||
1028 (bestVis.redSize < vis.redSize) ||
1029 (bestVis.greenSize < vis.greenSize) ||
1030 (bestVis.blueSize < vis.blueSize) ||
1031 (bestVis.alphaSize < vis.alphaSize) ||
1032 (bestVis.depthSize < vis.depthSize) ||
1033 (bestVis.stencilSize < vis.stencilSize) ||
1034 (bestVis.accumRedSize < vis.accumRedSize)) {
1035 /* found a better visual */
1036 bestVis = vis;
1037 }
1038 }
1039
1040 XFree(visuals);
1041
1042 return bestVis.id;
1043}
1044
1045
Brian Paul08b3ff12001-04-24 20:57:36 +00001046static void
1047usage(void)
1048{
1049 printf("Usage: glxinfo [-v] [-t] [-h] [-i] [-b] [-display <dname>]\n");
1050 printf("\t-v: Print visuals info in verbose form.\n");
1051 printf("\t-t: Print verbose table.\n");
1052 printf("\t-display <dname>: Print GLX visuals on specified server.\n");
1053 printf("\t-h: This information.\n");
1054 printf("\t-i: Force an indirect rendering context.\n");
1055 printf("\t-b: Find the 'best' visual and print it's number.\n");
Brian Paul0b77a1c2003-04-09 21:50:08 +00001056 printf("\t-l: Print interesting OpenGL limits.\n");
Brian Paul08b3ff12001-04-24 20:57:36 +00001057}
1058
1059
Brian Paul76bc4402000-01-27 16:43:56 +00001060int
1061main(int argc, char *argv[])
1062{
Alan Hourihanee18599a2001-03-19 13:58:45 +00001063 char *displayName = NULL;
Brian Paul76bc4402000-01-27 16:43:56 +00001064 Display *dpy;
1065 int numScreens, scrnum;
1066 InfoMode mode = Normal;
Brian Paul39557c32001-03-23 21:41:44 +00001067 GLboolean findBest = GL_FALSE;
Brian Paul2f7ef5f2002-09-06 03:35:43 +00001068 GLboolean limits = GL_FALSE;
Brian Paul08b3ff12001-04-24 20:57:36 +00001069 Bool allowDirect = True;
Brian Paul76bc4402000-01-27 16:43:56 +00001070 int i;
1071
1072 for (i = 1; i < argc; i++) {
1073 if (strcmp(argv[i], "-display") == 0 && i + 1 < argc) {
1074 displayName = argv[i + 1];
1075 i++;
1076 }
1077 else if (strcmp(argv[i], "-t") == 0) {
1078 mode = Wide;
1079 }
1080 else if (strcmp(argv[i], "-v") == 0) {
1081 mode = Verbose;
1082 }
Brian Paul39557c32001-03-23 21:41:44 +00001083 else if (strcmp(argv[i], "-b") == 0) {
1084 findBest = GL_TRUE;
1085 }
Brian Paul08b3ff12001-04-24 20:57:36 +00001086 else if (strcmp(argv[i], "-i") == 0) {
1087 allowDirect = False;
1088 }
Brian Paul2f7ef5f2002-09-06 03:35:43 +00001089 else if (strcmp(argv[i], "-l") == 0) {
1090 limits = GL_TRUE;
1091 }
Brian Paul08b3ff12001-04-24 20:57:36 +00001092 else if (strcmp(argv[i], "-h") == 0) {
1093 usage();
1094 return 0;
1095 }
1096 else {
1097 printf("Unknown option `%s'\n", argv[i]);
1098 usage();
1099 return 0;
1100 }
Brian Paul76bc4402000-01-27 16:43:56 +00001101 }
1102
1103 dpy = XOpenDisplay(displayName);
1104 if (!dpy) {
Brian73eee242006-12-13 08:30:26 -07001105 fprintf(stderr, "Error: unable to open display %s\n", XDisplayName(displayName));
Brian Paul76bc4402000-01-27 16:43:56 +00001106 return -1;
1107 }
1108
Brian Paul39557c32001-03-23 21:41:44 +00001109 if (findBest) {
1110 int b;
1111 mesa_hack(dpy, 0);
1112 b = find_best_visual(dpy, 0);
1113 printf("%d\n", b);
1114 }
1115 else {
1116 numScreens = ScreenCount(dpy);
Brian Paul373aea12001-04-02 22:45:07 +00001117 print_display_info(dpy);
Brian Paul39557c32001-03-23 21:41:44 +00001118 for (scrnum = 0; scrnum < numScreens; scrnum++) {
1119 mesa_hack(dpy, scrnum);
Brian Paul2f7ef5f2002-09-06 03:35:43 +00001120 print_screen_info(dpy, scrnum, allowDirect, limits);
Brian Paul39557c32001-03-23 21:41:44 +00001121 printf("\n");
1122 print_visual_info(dpy, scrnum, mode);
Kristian Høgsberg87966ba2007-10-17 10:14:55 -04001123#ifdef GLX_VERSION_1_3
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -04001124 print_fbconfig_info(dpy, scrnum, mode);
Kristian Høgsberg87966ba2007-10-17 10:14:55 -04001125#endif
Brian Paul39557c32001-03-23 21:41:44 +00001126 if (scrnum + 1 < numScreens)
1127 printf("\n\n");
1128 }
Brian Paul76bc4402000-01-27 16:43:56 +00001129 }
1130
Brian Pauld2bfe1e1999-09-16 16:40:46 +00001131 XCloseDisplay(dpy);
1132
1133 return 0;
1134}