blob: 6cf127afa2ffe599ed2390f6a25ba2ad583f2cda [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;
Kristian Høgsberga0748572007-10-18 15:19:08 -0400398 GLXContext ctx = NULL;
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000399 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);
Kristian Høgsberga0748572007-10-18 15:19:08 -0400405 if (!visinfo)
Brian Paul8460cc92000-02-02 20:57:51 +0000406 visinfo = glXChooseVisual(dpy, scrnum, attribDouble);
Kristian Høgsberga0748572007-10-18 15:19:08 -0400407
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 Paul8460cc92000-02-02 20:57:51 +0000438 }
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000439 }
Kristian Høgsberga0748572007-10-18 15:19:08 -0400440#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);
450 XDestroyWindow(dpy, win);
451 return;
452 }
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000453
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000454 attr.background_pixel = 0;
455 attr.border_pixel = 0;
Brian Paul9cff5582000-05-07 18:07:23 +0000456 attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone);
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000457 attr.event_mask = StructureNotifyMask | ExposureMask;
458 mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
Brian Paul76bc4402000-01-27 16:43:56 +0000459 win = XCreateWindow(dpy, root, 0, 0, width, height,
460 0, visinfo->depth, InputOutput,
461 visinfo->visual, mask, &attr);
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000462
Brian Paul9cff5582000-05-07 18:07:23 +0000463 if (glXMakeCurrent(dpy, win, ctx)) {
Brian Paul76bc4402000-01-27 16:43:56 +0000464 const char *serverVendor = glXQueryServerString(dpy, scrnum, GLX_VENDOR);
465 const char *serverVersion = glXQueryServerString(dpy, scrnum, GLX_VERSION);
466 const char *serverExtensions = glXQueryServerString(dpy, scrnum, GLX_EXTENSIONS);
Brian Paul34fb5db2000-04-22 20:31:23 +0000467 const char *clientVendor = glXGetClientString(dpy, GLX_VENDOR);
Brian Paul76bc4402000-01-27 16:43:56 +0000468 const char *clientVersion = glXGetClientString(dpy, GLX_VERSION);
469 const char *clientExtensions = glXGetClientString(dpy, GLX_EXTENSIONS);
470 const char *glxExtensions = glXQueryExtensionsString(dpy, scrnum);
471 const char *glVendor = (const char *) glGetString(GL_VENDOR);
472 const char *glRenderer = (const char *) glGetString(GL_RENDERER);
473 const char *glVersion = (const char *) glGetString(GL_VERSION);
474 const char *glExtensions = (const char *) glGetString(GL_EXTENSIONS);
Ian Romanickc00fbd52004-02-23 17:37:36 +0000475 int glxVersionMajor;
476 int glxVersionMinor;
Brian Paul373aea12001-04-02 22:45:07 +0000477 char *displayName = NULL;
478 char *colon = NULL, *period = NULL;
Ian Romanickc00fbd52004-02-23 17:37:36 +0000479
480 if (! glXQueryVersion( dpy, & glxVersionMajor, & glxVersionMinor )) {
481 fprintf(stderr, "Error: glXQueryVersion failed\n");
482 exit(1);
483 }
484
Brian Paul373aea12001-04-02 22:45:07 +0000485 /* Strip the screen number from the display name, if present. */
Brian Paulf02a5f62002-07-12 15:54:01 +0000486 if (!(displayName = (char *) malloc(strlen(DisplayString(dpy)) + 1))) {
Brian Paul373aea12001-04-02 22:45:07 +0000487 fprintf(stderr, "Error: malloc() failed\n");
488 exit(1);
489 }
490 strcpy(displayName, DisplayString(dpy));
491 colon = strrchr(displayName, ':');
492 if (colon) {
493 period = strchr(colon, '.');
494 if (period)
495 *period = '\0';
496 }
497 printf("display: %s screen: %d\n", displayName, scrnum);
498 free(displayName);
Michel Dänzerb46e3592006-12-06 14:54:43 +0100499 printf("direct rendering: ");
500 if (glXIsDirect(dpy, ctx)) {
501 printf("Yes\n");
502 } else {
503 if (!allowDirect) {
504 printf("No (-i specified)\n");
505 } else if (getenv("LIBGL_ALWAYS_INDIRECT")) {
506 printf("No (LIBGL_ALWAYS_INDIRECT set)\n");
507 } else {
508 printf("No (If you want to find out why, try setting "
509 "LIBGL_DEBUG=verbose)\n");
510 }
511 }
Brian Paul76bc4402000-01-27 16:43:56 +0000512 printf("server glx vendor string: %s\n", serverVendor);
513 printf("server glx version string: %s\n", serverVersion);
514 printf("server glx extensions:\n");
515 print_extension_list(serverExtensions);
Brian Paul34fb5db2000-04-22 20:31:23 +0000516 printf("client glx vendor string: %s\n", clientVendor);
517 printf("client glx version string: %s\n", clientVersion);
Brian Paul76bc4402000-01-27 16:43:56 +0000518 printf("client glx extensions:\n");
519 print_extension_list(clientExtensions);
Ian Romanickc00fbd52004-02-23 17:37:36 +0000520 printf("GLX version: %u.%u\n", glxVersionMajor, glxVersionMinor);
Brian Paul76bc4402000-01-27 16:43:56 +0000521 printf("GLX extensions:\n");
522 print_extension_list(glxExtensions);
523 printf("OpenGL vendor string: %s\n", glVendor);
524 printf("OpenGL renderer string: %s\n", glRenderer);
525 printf("OpenGL version string: %s\n", glVersion);
Brian Paul51bfb6a2008-07-24 14:27:11 -0600526#ifdef GL_VERSION_2_0
527 if (glVersion[0] >= '2' && glVersion[1] == '.') {
528 char *v = (char *) glGetString(GL_SHADING_LANGUAGE_VERSION);
529 printf("OpenGL shading language version string: %s\n", v);
530 }
531#endif
532
Brian Paul76bc4402000-01-27 16:43:56 +0000533 printf("OpenGL extensions:\n");
534 print_extension_list(glExtensions);
Brian Paul2f7ef5f2002-09-06 03:35:43 +0000535 if (limits)
Brian Paulad7805d2006-05-13 00:18:12 +0000536 print_limits(glExtensions);
Brian Paul76bc4402000-01-27 16:43:56 +0000537 }
Brian Paul9cff5582000-05-07 18:07:23 +0000538 else {
539 fprintf(stderr, "Error: glXMakeCurrent failed\n");
540 }
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000541
542 glXDestroyContext(dpy, ctx);
Brian Paul361bccb2006-01-16 16:17:18 +0000543 XFree(visinfo);
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000544 XDestroyWindow(dpy, win);
Brian Paul76bc4402000-01-27 16:43:56 +0000545}
546
547
548static const char *
549visual_class_name(int cls)
550{
551 switch (cls) {
552 case StaticColor:
553 return "StaticColor";
554 case PseudoColor:
555 return "PseudoColor";
556 case StaticGray:
557 return "StaticGray";
558 case GrayScale:
559 return "GrayScale";
560 case TrueColor:
561 return "TrueColor";
562 case DirectColor:
563 return "DirectColor";
564 default:
565 return "";
566 }
567}
568
569
570static const char *
571visual_class_abbrev(int cls)
572{
573 switch (cls) {
574 case StaticColor:
575 return "sc";
576 case PseudoColor:
577 return "pc";
578 case StaticGray:
579 return "sg";
580 case GrayScale:
581 return "gs";
582 case TrueColor:
583 return "tc";
584 case DirectColor:
585 return "dc";
586 default:
587 return "";
588 }
589}
590
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400591static const char *
592visual_render_type_name(int type)
593{
594 switch (type) {
595 case GLX_RGBA_BIT:
596 return "rgba";
597 case GLX_COLOR_INDEX_BIT:
598 return "ci";
599 case GLX_RGBA_BIT | GLX_COLOR_INDEX_BIT:
600 return "rgba|ci";
601 default:
602 return "";
603 }
604}
Brian Paul76bc4402000-01-27 16:43:56 +0000605
Kristian Høgsbergf7d1d552007-10-15 20:12:01 -0400606static GLboolean
Brian Paul76bc4402000-01-27 16:43:56 +0000607get_visual_attribs(Display *dpy, XVisualInfo *vInfo,
608 struct visual_attribs *attribs)
609{
Brian Paul25673f02000-03-31 18:17:51 +0000610 const char *ext = glXQueryExtensionsString(dpy, vInfo->screen);
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400611 int rgba;
Brian Paul25673f02000-03-31 18:17:51 +0000612
Brian Paula9c53fa2000-04-03 15:45:34 +0000613 memset(attribs, 0, sizeof(struct visual_attribs));
614
Brian Paul76bc4402000-01-27 16:43:56 +0000615 attribs->id = vInfo->visualid;
616#if defined(__cplusplus) || defined(c_plusplus)
617 attribs->klass = vInfo->c_class;
618#else
619 attribs->klass = vInfo->class;
620#endif
621 attribs->depth = vInfo->depth;
622 attribs->redMask = vInfo->red_mask;
623 attribs->greenMask = vInfo->green_mask;
624 attribs->blueMask = vInfo->blue_mask;
625 attribs->colormapSize = vInfo->colormap_size;
626 attribs->bitsPerRGB = vInfo->bits_per_rgb;
627
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400628 if (glXGetConfig(dpy, vInfo, GLX_USE_GL, &attribs->supportsGL) != 0 ||
629 !attribs->supportsGL)
Kristian Høgsbergf7d1d552007-10-15 20:12:01 -0400630 return GL_FALSE;
Brian Paul76bc4402000-01-27 16:43:56 +0000631 glXGetConfig(dpy, vInfo, GLX_BUFFER_SIZE, &attribs->bufferSize);
632 glXGetConfig(dpy, vInfo, GLX_LEVEL, &attribs->level);
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400633 glXGetConfig(dpy, vInfo, GLX_RGBA, &rgba);
634 if (rgba)
635 attribs->render_type = GLX_RGBA_BIT;
636 else
637 attribs->render_type = GLX_COLOR_INDEX_BIT;
638
Brian Paul76bc4402000-01-27 16:43:56 +0000639 glXGetConfig(dpy, vInfo, GLX_DOUBLEBUFFER, &attribs->doubleBuffer);
640 glXGetConfig(dpy, vInfo, GLX_STEREO, &attribs->stereo);
641 glXGetConfig(dpy, vInfo, GLX_AUX_BUFFERS, &attribs->auxBuffers);
642 glXGetConfig(dpy, vInfo, GLX_RED_SIZE, &attribs->redSize);
643 glXGetConfig(dpy, vInfo, GLX_GREEN_SIZE, &attribs->greenSize);
644 glXGetConfig(dpy, vInfo, GLX_BLUE_SIZE, &attribs->blueSize);
645 glXGetConfig(dpy, vInfo, GLX_ALPHA_SIZE, &attribs->alphaSize);
646 glXGetConfig(dpy, vInfo, GLX_DEPTH_SIZE, &attribs->depthSize);
647 glXGetConfig(dpy, vInfo, GLX_STENCIL_SIZE, &attribs->stencilSize);
648 glXGetConfig(dpy, vInfo, GLX_ACCUM_RED_SIZE, &attribs->accumRedSize);
649 glXGetConfig(dpy, vInfo, GLX_ACCUM_GREEN_SIZE, &attribs->accumGreenSize);
650 glXGetConfig(dpy, vInfo, GLX_ACCUM_BLUE_SIZE, &attribs->accumBlueSize);
651 glXGetConfig(dpy, vInfo, GLX_ACCUM_ALPHA_SIZE, &attribs->accumAlphaSize);
652
Brian Paul45c56982002-10-14 13:57:23 +0000653 /* get transparent pixel stuff */
654 glXGetConfig(dpy, vInfo,GLX_TRANSPARENT_TYPE, &attribs->transparentType);
655 if (attribs->transparentType == GLX_TRANSPARENT_RGB) {
656 glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_RED_VALUE, &attribs->transparentRedValue);
657 glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_GREEN_VALUE, &attribs->transparentGreenValue);
658 glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_BLUE_VALUE, &attribs->transparentBlueValue);
659 glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_ALPHA_VALUE, &attribs->transparentAlphaValue);
660 }
661 else if (attribs->transparentType == GLX_TRANSPARENT_INDEX) {
662 glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_INDEX_VALUE, &attribs->transparentIndexValue);
663 }
Brian Paule06c7f32000-01-27 16:53:55 +0000664
Brian Pauld2e39bb2002-11-04 16:24:18 +0000665 /* multisample attribs */
666#ifdef GLX_ARB_multisample
Adam Jacksone1ae5b82008-01-22 14:57:20 -0500667 if (ext && strstr(ext, "GLX_ARB_multisample")) {
Brian Pauld2e39bb2002-11-04 16:24:18 +0000668 glXGetConfig(dpy, vInfo, GLX_SAMPLE_BUFFERS_ARB, &attribs->numMultisample);
669 glXGetConfig(dpy, vInfo, GLX_SAMPLES_ARB, &attribs->numSamples);
670 }
671#endif
672 else {
673 attribs->numSamples = 0;
674 attribs->numMultisample = 0;
675 }
Brian Paul25673f02000-03-31 18:17:51 +0000676
677#if defined(GLX_EXT_visual_rating)
678 if (ext && strstr(ext, "GLX_EXT_visual_rating")) {
679 glXGetConfig(dpy, vInfo, GLX_VISUAL_CAVEAT_EXT, &attribs->visualCaveat);
680 }
681 else {
682 attribs->visualCaveat = GLX_NONE_EXT;
683 }
684#else
685 attribs->visualCaveat = 0;
686#endif
Kristian Høgsbergf7d1d552007-10-15 20:12:01 -0400687
688 return GL_TRUE;
Brian Paul76bc4402000-01-27 16:43:56 +0000689}
690
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400691#ifdef GLX_VERSION_1_3
692
693static int
694glx_token_to_visual_class(int visual_type)
695{
696 switch (visual_type) {
697 case GLX_TRUE_COLOR:
698 return TrueColor;
699 case GLX_DIRECT_COLOR:
700 return DirectColor;
701 case GLX_PSEUDO_COLOR:
702 return PseudoColor;
703 case GLX_STATIC_COLOR:
704 return StaticColor;
705 case GLX_GRAY_SCALE:
706 return GrayScale;
707 case GLX_STATIC_GRAY:
708 return StaticGray;
709 case GLX_NONE:
710 default:
711 return None;
712 }
713}
714
715static GLboolean
716get_fbconfig_attribs(Display *dpy, GLXFBConfig fbconfig,
717 struct visual_attribs *attribs)
718{
719 int visual_type;
720
721 memset(attribs, 0, sizeof(struct visual_attribs));
722
723 glXGetFBConfigAttrib(dpy, fbconfig, GLX_FBCONFIG_ID, &attribs->id);
724
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400725#if 0
726 attribs->depth = vInfo->depth;
727 attribs->redMask = vInfo->red_mask;
728 attribs->greenMask = vInfo->green_mask;
729 attribs->blueMask = vInfo->blue_mask;
730 attribs->colormapSize = vInfo->colormap_size;
731 attribs->bitsPerRGB = vInfo->bits_per_rgb;
732#endif
733
734 glXGetFBConfigAttrib(dpy, fbconfig, GLX_X_VISUAL_TYPE, &visual_type);
735 attribs->klass = glx_token_to_visual_class(visual_type);
736
737 glXGetFBConfigAttrib(dpy, fbconfig, GLX_BUFFER_SIZE, &attribs->bufferSize);
738 glXGetFBConfigAttrib(dpy, fbconfig, GLX_LEVEL, &attribs->level);
739 glXGetFBConfigAttrib(dpy, fbconfig, GLX_RENDER_TYPE, &attribs->render_type);
740 glXGetFBConfigAttrib(dpy, fbconfig, GLX_DOUBLEBUFFER, &attribs->doubleBuffer);
741 glXGetFBConfigAttrib(dpy, fbconfig, GLX_STEREO, &attribs->stereo);
742 glXGetFBConfigAttrib(dpy, fbconfig, GLX_AUX_BUFFERS, &attribs->auxBuffers);
743
744 glXGetFBConfigAttrib(dpy, fbconfig, GLX_RED_SIZE, &attribs->redSize);
745 glXGetFBConfigAttrib(dpy, fbconfig, GLX_GREEN_SIZE, &attribs->greenSize);
746 glXGetFBConfigAttrib(dpy, fbconfig, GLX_BLUE_SIZE, &attribs->blueSize);
747 glXGetFBConfigAttrib(dpy, fbconfig, GLX_ALPHA_SIZE, &attribs->alphaSize);
748 glXGetFBConfigAttrib(dpy, fbconfig, GLX_DEPTH_SIZE, &attribs->depthSize);
749 glXGetFBConfigAttrib(dpy, fbconfig, GLX_STENCIL_SIZE, &attribs->stencilSize);
750
751 glXGetFBConfigAttrib(dpy, fbconfig, GLX_ACCUM_RED_SIZE, &attribs->accumRedSize);
752 glXGetFBConfigAttrib(dpy, fbconfig, GLX_ACCUM_GREEN_SIZE, &attribs->accumGreenSize);
753 glXGetFBConfigAttrib(dpy, fbconfig, GLX_ACCUM_BLUE_SIZE, &attribs->accumBlueSize);
754 glXGetFBConfigAttrib(dpy, fbconfig, GLX_ACCUM_ALPHA_SIZE, &attribs->accumAlphaSize);
755
756 /* get transparent pixel stuff */
757 glXGetFBConfigAttrib(dpy, fbconfig,GLX_TRANSPARENT_TYPE, &attribs->transparentType);
758 if (attribs->transparentType == GLX_TRANSPARENT_RGB) {
759 glXGetFBConfigAttrib(dpy, fbconfig, GLX_TRANSPARENT_RED_VALUE, &attribs->transparentRedValue);
760 glXGetFBConfigAttrib(dpy, fbconfig, GLX_TRANSPARENT_GREEN_VALUE, &attribs->transparentGreenValue);
761 glXGetFBConfigAttrib(dpy, fbconfig, GLX_TRANSPARENT_BLUE_VALUE, &attribs->transparentBlueValue);
762 glXGetFBConfigAttrib(dpy, fbconfig, GLX_TRANSPARENT_ALPHA_VALUE, &attribs->transparentAlphaValue);
763 }
764 else if (attribs->transparentType == GLX_TRANSPARENT_INDEX) {
765 glXGetFBConfigAttrib(dpy, fbconfig, GLX_TRANSPARENT_INDEX_VALUE, &attribs->transparentIndexValue);
766 }
767
768 glXGetFBConfigAttrib(dpy, fbconfig, GLX_SAMPLE_BUFFERS, &attribs->numMultisample);
769 glXGetFBConfigAttrib(dpy, fbconfig, GLX_SAMPLES, &attribs->numSamples);
770 glXGetFBConfigAttrib(dpy, fbconfig, GLX_CONFIG_CAVEAT, &attribs->visualCaveat);
771
772 return GL_TRUE;
773}
774
775#endif
776
777
Brian Paul76bc4402000-01-27 16:43:56 +0000778
779static void
780print_visual_attribs_verbose(const struct visual_attribs *attribs)
781{
782 printf("Visual ID: %x depth=%d class=%s\n",
783 attribs->id, attribs->depth, visual_class_name(attribs->klass));
784 printf(" bufferSize=%d level=%d renderType=%s doubleBuffer=%d stereo=%d\n",
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400785 attribs->bufferSize, attribs->level,
786 visual_render_type_name(attribs->render_type),
Brian Paul76bc4402000-01-27 16:43:56 +0000787 attribs->doubleBuffer, attribs->stereo);
788 printf(" rgba: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n",
789 attribs->redSize, attribs->greenSize,
790 attribs->blueSize, attribs->alphaSize);
791 printf(" auxBuffers=%d depthSize=%d stencilSize=%d\n",
792 attribs->auxBuffers, attribs->depthSize, attribs->stencilSize);
793 printf(" accum: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n",
794 attribs->accumRedSize, attribs->accumGreenSize,
795 attribs->accumBlueSize, attribs->accumAlphaSize);
796 printf(" multiSample=%d multiSampleBuffers=%d\n",
797 attribs->numSamples, attribs->numMultisample);
Brian Paul25673f02000-03-31 18:17:51 +0000798#ifdef GLX_EXT_visual_rating
799 if (attribs->visualCaveat == GLX_NONE_EXT || attribs->visualCaveat == 0)
Brian Paula9c53fa2000-04-03 15:45:34 +0000800 printf(" visualCaveat=None\n");
Brian Paul25673f02000-03-31 18:17:51 +0000801 else if (attribs->visualCaveat == GLX_SLOW_VISUAL_EXT)
Brian Paula9c53fa2000-04-03 15:45:34 +0000802 printf(" visualCaveat=Slow\n");
Brian Paul25673f02000-03-31 18:17:51 +0000803 else if (attribs->visualCaveat == GLX_NON_CONFORMANT_VISUAL_EXT)
Brian Paula9c53fa2000-04-03 15:45:34 +0000804 printf(" visualCaveat=Nonconformant\n");
Brian Paul25673f02000-03-31 18:17:51 +0000805#endif
Brian Paul45c56982002-10-14 13:57:23 +0000806 if (attribs->transparentType == GLX_NONE) {
807 printf(" Opaque.\n");
808 }
809 else if (attribs->transparentType == GLX_TRANSPARENT_RGB) {
810 printf(" Transparent RGB: Red=%d Green=%d Blue=%d Alpha=%d\n",attribs->transparentRedValue,attribs->transparentGreenValue,attribs->transparentBlueValue,attribs->transparentAlphaValue);
811 }
812 else if (attribs->transparentType == GLX_TRANSPARENT_INDEX) {
813 printf(" Transparent index=%d\n",attribs->transparentIndexValue);
814 }
Brian Paul76bc4402000-01-27 16:43:56 +0000815}
816
817
818static void
819print_visual_attribs_short_header(void)
820{
Brian Paula9c53fa2000-04-03 15:45:34 +0000821 printf(" visual x bf lv rg d st colorbuffer ax dp st accumbuffer ms cav\n");
822 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 +0000823 printf("----------------------------------------------------------------------\n");
Brian Paul76bc4402000-01-27 16:43:56 +0000824}
825
826
827static void
828print_visual_attribs_short(const struct visual_attribs *attribs)
829{
Brian Paula3e44f42002-03-08 19:44:28 +0000830 char *caveat = NULL;
Brian Paul25673f02000-03-31 18:17:51 +0000831#ifdef GLX_EXT_visual_rating
832 if (attribs->visualCaveat == GLX_NONE_EXT || attribs->visualCaveat == 0)
833 caveat = "None";
834 else if (attribs->visualCaveat == GLX_SLOW_VISUAL_EXT)
835 caveat = "Slow";
836 else if (attribs->visualCaveat == GLX_NON_CONFORMANT_VISUAL_EXT)
837 caveat = "Ncon";
Brian Paul28bc6cb2002-09-06 03:47:34 +0000838 else
839 caveat = "None";
Brian Paul25673f02000-03-31 18:17:51 +0000840#else
841 caveat = "None";
842#endif
843
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400844 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 +0000845 attribs->id,
846 attribs->depth,
847 visual_class_abbrev(attribs->klass),
Brian Paul45c56982002-10-14 13:57:23 +0000848 attribs->transparentType != GLX_NONE,
Brian Paul76bc4402000-01-27 16:43:56 +0000849 attribs->bufferSize,
850 attribs->level,
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400851 (attribs->render_type & GLX_RGBA_BIT) ? 'r' : ' ',
852 (attribs->render_type & GLX_COLOR_INDEX_BIT) ? 'c' : ' ',
853 attribs->doubleBuffer ? 'y' : '.',
854 attribs->stereo ? 'y' : '.',
Brian Paul76bc4402000-01-27 16:43:56 +0000855 attribs->redSize, attribs->greenSize,
856 attribs->blueSize, attribs->alphaSize,
857 attribs->auxBuffers,
858 attribs->depthSize,
859 attribs->stencilSize
860 );
861
Brian Paul25673f02000-03-31 18:17:51 +0000862 printf(" %2d %2d %2d %2d %2d %1d %s\n",
Brian Paul76bc4402000-01-27 16:43:56 +0000863 attribs->accumRedSize, attribs->accumGreenSize,
864 attribs->accumBlueSize, attribs->accumAlphaSize,
Brian Paul25673f02000-03-31 18:17:51 +0000865 attribs->numSamples, attribs->numMultisample,
866 caveat
Brian Paul76bc4402000-01-27 16:43:56 +0000867 );
868}
869
870
871static void
872print_visual_attribs_long_header(void)
873{
874 printf("Vis Vis Visual Trans buff lev render DB ste r g b a aux dep ste accum buffers MS MS\n");
875 printf(" ID Depth Type parent size el type reo sz sz sz sz buf th ncl r g b a num bufs\n");
876 printf("----------------------------------------------------------------------------------------------------\n");
877}
878
879
880static void
881print_visual_attribs_long(const struct visual_attribs *attribs)
882{
883 printf("0x%2x %2d %-11s %2d %2d %2d %4s %3d %3d %3d %3d %3d %3d",
884 attribs->id,
885 attribs->depth,
886 visual_class_name(attribs->klass),
Brian Paul45c56982002-10-14 13:57:23 +0000887 attribs->transparentType != GLX_NONE,
Brian Paul76bc4402000-01-27 16:43:56 +0000888 attribs->bufferSize,
889 attribs->level,
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400890 visual_render_type_name(attribs->render_type),
Brian Paul76bc4402000-01-27 16:43:56 +0000891 attribs->doubleBuffer,
892 attribs->stereo,
893 attribs->redSize, attribs->greenSize,
894 attribs->blueSize, attribs->alphaSize
895 );
896
897 printf(" %3d %4d %2d %3d %3d %3d %3d %2d %2d\n",
898 attribs->auxBuffers,
899 attribs->depthSize,
900 attribs->stencilSize,
901 attribs->accumRedSize, attribs->accumGreenSize,
902 attribs->accumBlueSize, attribs->accumAlphaSize,
903 attribs->numSamples, attribs->numMultisample
904 );
905}
906
907
908static void
909print_visual_info(Display *dpy, int scrnum, InfoMode mode)
910{
Brian Paulf02a5f62002-07-12 15:54:01 +0000911 XVisualInfo theTemplate;
Brian Paul76bc4402000-01-27 16:43:56 +0000912 XVisualInfo *visuals;
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400913 int numVisuals, numGlxVisuals;
Brian Paul76bc4402000-01-27 16:43:56 +0000914 long mask;
915 int i;
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400916 struct visual_attribs attribs;
Brian Paul76bc4402000-01-27 16:43:56 +0000917
918 /* get list of all visuals on this screen */
Brian Paulf02a5f62002-07-12 15:54:01 +0000919 theTemplate.screen = scrnum;
Brian Paul76bc4402000-01-27 16:43:56 +0000920 mask = VisualScreenMask;
Brian Paulf02a5f62002-07-12 15:54:01 +0000921 visuals = XGetVisualInfo(dpy, mask, &theTemplate, &numVisuals);
Brian Paul76bc4402000-01-27 16:43:56 +0000922
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400923 numGlxVisuals = 0;
924 for (i = 0; i < numVisuals; i++) {
925 if (get_visual_attribs(dpy, &visuals[i], &attribs))
926 numGlxVisuals++;
Brian Paul76bc4402000-01-27 16:43:56 +0000927 }
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400928
929 if (numGlxVisuals == 0)
930 return;
931
932 printf("%d GLX Visuals\n", numGlxVisuals);
933
934 if (mode == Normal)
Brian Paul76bc4402000-01-27 16:43:56 +0000935 print_visual_attribs_short_header();
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400936 else if (mode == Wide)
Brian Paul76bc4402000-01-27 16:43:56 +0000937 print_visual_attribs_long_header();
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400938
939 for (i = 0; i < numVisuals; i++) {
940 if (!get_visual_attribs(dpy, &visuals[i], &attribs))
941 continue;
942
943 if (mode == Verbose)
944 print_visual_attribs_verbose(&attribs);
945 else if (mode == Normal)
946 print_visual_attribs_short(&attribs);
947 else if (mode == Wide)
Brian Paul76bc4402000-01-27 16:43:56 +0000948 print_visual_attribs_long(&attribs);
Brian Paul76bc4402000-01-27 16:43:56 +0000949 }
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400950 printf("\n");
Brian Paul76bc4402000-01-27 16:43:56 +0000951
952 XFree(visuals);
953}
954
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400955#ifdef GLX_VERSION_1_3
956
957static void
958print_fbconfig_info(Display *dpy, int scrnum, InfoMode mode)
959{
960 int numFBConfigs;
961 struct visual_attribs attribs;
962 GLXFBConfig *fbconfigs;
963 int i;
964
965 /* get list of all fbconfigs on this screen */
966 fbconfigs = glXGetFBConfigs(dpy, scrnum, &numFBConfigs);
967
968 if (numFBConfigs == 0)
969 return;
970
Kristian Høgsberga5b4bb32007-10-17 14:43:35 -0400971 printf("%d GLXFBConfigs:\n", numFBConfigs);
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400972 if (mode == Normal)
973 print_visual_attribs_short_header();
974 else if (mode == Wide)
975 print_visual_attribs_long_header();
976
977 for (i = 0; i < numFBConfigs; i++) {
978 get_fbconfig_attribs(dpy, fbconfigs[i], &attribs);
979
980 if (mode == Verbose)
981 print_visual_attribs_verbose(&attribs);
982 else if (mode == Normal)
983 print_visual_attribs_short(&attribs);
984 else if (mode == Wide)
985 print_visual_attribs_long(&attribs);
986 }
987 printf("\n");
988
989 XFree(fbconfigs);
990}
991
992#endif
Brian Paul76bc4402000-01-27 16:43:56 +0000993
Brian Paul39557c32001-03-23 21:41:44 +0000994/*
995 * Stand-alone Mesa doesn't really implement the GLX protocol so it
996 * doesn't really know the GLX attributes associated with an X visual.
997 * The first time a visual is presented to Mesa's pseudo-GLX it
998 * attaches ancilliary buffers to it (like depth and stencil).
999 * But that usually only works if glXChooseVisual is used.
1000 * This function calls glXChooseVisual() to sort of "prime the pump"
1001 * for Mesa's GLX so that the visuals that get reported actually
1002 * reflect what applications will see.
1003 * This has no effect when using true GLX.
1004 */
1005static void
1006mesa_hack(Display *dpy, int scrnum)
1007{
1008 static int attribs[] = {
1009 GLX_RGBA,
1010 GLX_RED_SIZE, 1,
1011 GLX_GREEN_SIZE, 1,
1012 GLX_BLUE_SIZE, 1,
1013 GLX_DEPTH_SIZE, 1,
1014 GLX_STENCIL_SIZE, 1,
1015 GLX_ACCUM_RED_SIZE, 1,
1016 GLX_ACCUM_GREEN_SIZE, 1,
1017 GLX_ACCUM_BLUE_SIZE, 1,
1018 GLX_ACCUM_ALPHA_SIZE, 1,
1019 GLX_DOUBLEBUFFER,
1020 None
1021 };
1022 XVisualInfo *visinfo;
1023
1024 visinfo = glXChooseVisual(dpy, scrnum, attribs);
1025 if (visinfo)
1026 XFree(visinfo);
1027}
1028
1029
1030/*
1031 * Examine all visuals to find the so-called best one.
1032 * We prefer deepest RGBA buffer with depth, stencil and accum
1033 * that has no caveats.
1034 */
1035static int
1036find_best_visual(Display *dpy, int scrnum)
1037{
Brian Paulf02a5f62002-07-12 15:54:01 +00001038 XVisualInfo theTemplate;
Brian Paul39557c32001-03-23 21:41:44 +00001039 XVisualInfo *visuals;
1040 int numVisuals;
1041 long mask;
1042 int i;
1043 struct visual_attribs bestVis;
1044
1045 /* get list of all visuals on this screen */
Brian Paulf02a5f62002-07-12 15:54:01 +00001046 theTemplate.screen = scrnum;
Brian Paul39557c32001-03-23 21:41:44 +00001047 mask = VisualScreenMask;
Brian Paulf02a5f62002-07-12 15:54:01 +00001048 visuals = XGetVisualInfo(dpy, mask, &theTemplate, &numVisuals);
Brian Paul39557c32001-03-23 21:41:44 +00001049
1050 /* init bestVis with first visual info */
1051 get_visual_attribs(dpy, &visuals[0], &bestVis);
1052
1053 /* try to find a "better" visual */
1054 for (i = 1; i < numVisuals; i++) {
1055 struct visual_attribs vis;
1056
1057 get_visual_attribs(dpy, &visuals[i], &vis);
1058
1059 /* always skip visuals with caveats */
1060 if (vis.visualCaveat != GLX_NONE_EXT)
1061 continue;
1062
1063 /* see if this vis is better than bestVis */
1064 if ((!bestVis.supportsGL && vis.supportsGL) ||
1065 (bestVis.visualCaveat != GLX_NONE_EXT) ||
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -04001066 (!(bestVis.render_type & GLX_RGBA_BIT) && (vis.render_type & GLX_RGBA_BIT)) ||
Brian Paul39557c32001-03-23 21:41:44 +00001067 (!bestVis.doubleBuffer && vis.doubleBuffer) ||
1068 (bestVis.redSize < vis.redSize) ||
1069 (bestVis.greenSize < vis.greenSize) ||
1070 (bestVis.blueSize < vis.blueSize) ||
1071 (bestVis.alphaSize < vis.alphaSize) ||
1072 (bestVis.depthSize < vis.depthSize) ||
1073 (bestVis.stencilSize < vis.stencilSize) ||
1074 (bestVis.accumRedSize < vis.accumRedSize)) {
1075 /* found a better visual */
1076 bestVis = vis;
1077 }
1078 }
1079
1080 XFree(visuals);
1081
1082 return bestVis.id;
1083}
1084
1085
Brian Paul08b3ff12001-04-24 20:57:36 +00001086static void
1087usage(void)
1088{
1089 printf("Usage: glxinfo [-v] [-t] [-h] [-i] [-b] [-display <dname>]\n");
1090 printf("\t-v: Print visuals info in verbose form.\n");
1091 printf("\t-t: Print verbose table.\n");
1092 printf("\t-display <dname>: Print GLX visuals on specified server.\n");
1093 printf("\t-h: This information.\n");
1094 printf("\t-i: Force an indirect rendering context.\n");
1095 printf("\t-b: Find the 'best' visual and print it's number.\n");
Brian Paul0b77a1c2003-04-09 21:50:08 +00001096 printf("\t-l: Print interesting OpenGL limits.\n");
Brian Paul08b3ff12001-04-24 20:57:36 +00001097}
1098
1099
Brian Paul76bc4402000-01-27 16:43:56 +00001100int
1101main(int argc, char *argv[])
1102{
Alan Hourihanee18599a2001-03-19 13:58:45 +00001103 char *displayName = NULL;
Brian Paul76bc4402000-01-27 16:43:56 +00001104 Display *dpy;
1105 int numScreens, scrnum;
1106 InfoMode mode = Normal;
Brian Paul39557c32001-03-23 21:41:44 +00001107 GLboolean findBest = GL_FALSE;
Brian Paul2f7ef5f2002-09-06 03:35:43 +00001108 GLboolean limits = GL_FALSE;
Brian Paul08b3ff12001-04-24 20:57:36 +00001109 Bool allowDirect = True;
Brian Paul76bc4402000-01-27 16:43:56 +00001110 int i;
1111
1112 for (i = 1; i < argc; i++) {
1113 if (strcmp(argv[i], "-display") == 0 && i + 1 < argc) {
1114 displayName = argv[i + 1];
1115 i++;
1116 }
1117 else if (strcmp(argv[i], "-t") == 0) {
1118 mode = Wide;
1119 }
1120 else if (strcmp(argv[i], "-v") == 0) {
1121 mode = Verbose;
1122 }
Brian Paul39557c32001-03-23 21:41:44 +00001123 else if (strcmp(argv[i], "-b") == 0) {
1124 findBest = GL_TRUE;
1125 }
Brian Paul08b3ff12001-04-24 20:57:36 +00001126 else if (strcmp(argv[i], "-i") == 0) {
1127 allowDirect = False;
1128 }
Brian Paul2f7ef5f2002-09-06 03:35:43 +00001129 else if (strcmp(argv[i], "-l") == 0) {
1130 limits = GL_TRUE;
1131 }
Brian Paul08b3ff12001-04-24 20:57:36 +00001132 else if (strcmp(argv[i], "-h") == 0) {
1133 usage();
1134 return 0;
1135 }
1136 else {
1137 printf("Unknown option `%s'\n", argv[i]);
1138 usage();
1139 return 0;
1140 }
Brian Paul76bc4402000-01-27 16:43:56 +00001141 }
1142
1143 dpy = XOpenDisplay(displayName);
1144 if (!dpy) {
Brian73eee242006-12-13 08:30:26 -07001145 fprintf(stderr, "Error: unable to open display %s\n", XDisplayName(displayName));
Brian Paul76bc4402000-01-27 16:43:56 +00001146 return -1;
1147 }
1148
Brian Paul39557c32001-03-23 21:41:44 +00001149 if (findBest) {
1150 int b;
1151 mesa_hack(dpy, 0);
1152 b = find_best_visual(dpy, 0);
1153 printf("%d\n", b);
1154 }
1155 else {
1156 numScreens = ScreenCount(dpy);
Brian Paul373aea12001-04-02 22:45:07 +00001157 print_display_info(dpy);
Brian Paul39557c32001-03-23 21:41:44 +00001158 for (scrnum = 0; scrnum < numScreens; scrnum++) {
1159 mesa_hack(dpy, scrnum);
Brian Paul2f7ef5f2002-09-06 03:35:43 +00001160 print_screen_info(dpy, scrnum, allowDirect, limits);
Brian Paul39557c32001-03-23 21:41:44 +00001161 printf("\n");
1162 print_visual_info(dpy, scrnum, mode);
Kristian Høgsberg87966ba2007-10-17 10:14:55 -04001163#ifdef GLX_VERSION_1_3
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -04001164 print_fbconfig_info(dpy, scrnum, mode);
Kristian Høgsberg87966ba2007-10-17 10:14:55 -04001165#endif
Brian Paul39557c32001-03-23 21:41:44 +00001166 if (scrnum + 1 < numScreens)
1167 printf("\n\n");
1168 }
Brian Paul76bc4402000-01-27 16:43:56 +00001169 }
1170
Brian Pauld2bfe1e1999-09-16 16:40:46 +00001171 XCloseDisplay(dpy);
1172
1173 return 0;
1174}