blob: 23df82f6f903051a89f523db0e531d71893a6499 [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 Paulca7cd3a2009-12-04 08:09:55 -0700404 /*
405 * Find a basic GLX visual. We'll then create a rendering context and
406 * query various info strings.
407 */
Brian Paul8460cc92000-02-02 20:57:51 +0000408 visinfo = glXChooseVisual(dpy, scrnum, attribSingle);
Kristian Høgsberga0748572007-10-18 15:19:08 -0400409 if (!visinfo)
Brian Paul8460cc92000-02-02 20:57:51 +0000410 visinfo = glXChooseVisual(dpy, scrnum, attribDouble);
Kristian Høgsberga0748572007-10-18 15:19:08 -0400411
412 if (visinfo)
413 ctx = glXCreateContext( dpy, visinfo, NULL, allowDirect );
414
415#ifdef GLX_VERSION_1_3
Brian Paulca7cd3a2009-12-04 08:09:55 -0700416 /* Try glXChooseFBConfig() if glXChooseVisual didn't work.
417 * XXX when would that happen?
418 */
419 if (!visinfo) {
Kristian Høgsberga0748572007-10-18 15:19:08 -0400420 int fbAttribSingle[] = {
421 GLX_RENDER_TYPE, GLX_RGBA_BIT,
422 GLX_RED_SIZE, 1,
423 GLX_GREEN_SIZE, 1,
424 GLX_BLUE_SIZE, 1,
Brian Paulca7cd3a2009-12-04 08:09:55 -0700425 GLX_DOUBLEBUFFER, GL_FALSE,
Kristian Høgsberga0748572007-10-18 15:19:08 -0400426 None };
427 int fbAttribDouble[] = {
428 GLX_RENDER_TYPE, GLX_RGBA_BIT,
429 GLX_RED_SIZE, 1,
430 GLX_GREEN_SIZE, 1,
431 GLX_BLUE_SIZE, 1,
Brian Paulca7cd3a2009-12-04 08:09:55 -0700432 GLX_DOUBLEBUFFER, GL_TRUE,
Kristian Høgsberga0748572007-10-18 15:19:08 -0400433 None };
434 GLXFBConfig *configs = NULL;
435 int nConfigs;
436
Brian Paulca7cd3a2009-12-04 08:09:55 -0700437 configs = glXChooseFBConfig(dpy, scrnum, fbAttribSingle, &nConfigs);
438 if (!configs)
Kristian Høgsberga0748572007-10-18 15:19:08 -0400439 configs = glXChooseFBConfig(dpy, scrnum, fbAttribDouble, &nConfigs);
440
441 if (configs) {
442 visinfo = glXGetVisualFromFBConfig(dpy, configs[0]);
443 ctx = glXCreateNewContext(dpy, configs[0], GLX_RGBA_TYPE, NULL, allowDirect);
444 XFree(configs);
Brian Paul8460cc92000-02-02 20:57:51 +0000445 }
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000446 }
Kristian Høgsberga0748572007-10-18 15:19:08 -0400447#endif
448
449 if (!visinfo) {
450 fprintf(stderr, "Error: couldn't find RGB GLX visual or fbconfig\n");
451 return;
452 }
453
454 if (!ctx) {
455 fprintf(stderr, "Error: glXCreateContext failed\n");
456 XFree(visinfo);
Kristian Høgsberga0748572007-10-18 15:19:08 -0400457 return;
458 }
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000459
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000460 attr.background_pixel = 0;
461 attr.border_pixel = 0;
Brian Paul9cff5582000-05-07 18:07:23 +0000462 attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone);
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000463 attr.event_mask = StructureNotifyMask | ExposureMask;
464 mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
Brian Paul76bc4402000-01-27 16:43:56 +0000465 win = XCreateWindow(dpy, root, 0, 0, width, height,
466 0, visinfo->depth, InputOutput,
467 visinfo->visual, mask, &attr);
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000468
Brian Paul9cff5582000-05-07 18:07:23 +0000469 if (glXMakeCurrent(dpy, win, ctx)) {
Brian Paul76bc4402000-01-27 16:43:56 +0000470 const char *serverVendor = glXQueryServerString(dpy, scrnum, GLX_VENDOR);
471 const char *serverVersion = glXQueryServerString(dpy, scrnum, GLX_VERSION);
472 const char *serverExtensions = glXQueryServerString(dpy, scrnum, GLX_EXTENSIONS);
Brian Paul34fb5db2000-04-22 20:31:23 +0000473 const char *clientVendor = glXGetClientString(dpy, GLX_VENDOR);
Brian Paul76bc4402000-01-27 16:43:56 +0000474 const char *clientVersion = glXGetClientString(dpy, GLX_VERSION);
475 const char *clientExtensions = glXGetClientString(dpy, GLX_EXTENSIONS);
476 const char *glxExtensions = glXQueryExtensionsString(dpy, scrnum);
477 const char *glVendor = (const char *) glGetString(GL_VENDOR);
478 const char *glRenderer = (const char *) glGetString(GL_RENDERER);
479 const char *glVersion = (const char *) glGetString(GL_VERSION);
480 const char *glExtensions = (const char *) glGetString(GL_EXTENSIONS);
Ian Romanickc00fbd52004-02-23 17:37:36 +0000481 int glxVersionMajor;
482 int glxVersionMinor;
Brian Paul373aea12001-04-02 22:45:07 +0000483 char *displayName = NULL;
484 char *colon = NULL, *period = NULL;
Ian Romanickc00fbd52004-02-23 17:37:36 +0000485
486 if (! glXQueryVersion( dpy, & glxVersionMajor, & glxVersionMinor )) {
487 fprintf(stderr, "Error: glXQueryVersion failed\n");
488 exit(1);
489 }
490
Brian Paul373aea12001-04-02 22:45:07 +0000491 /* Strip the screen number from the display name, if present. */
Brian Paulf02a5f62002-07-12 15:54:01 +0000492 if (!(displayName = (char *) malloc(strlen(DisplayString(dpy)) + 1))) {
Brian Paul373aea12001-04-02 22:45:07 +0000493 fprintf(stderr, "Error: malloc() failed\n");
494 exit(1);
495 }
496 strcpy(displayName, DisplayString(dpy));
497 colon = strrchr(displayName, ':');
498 if (colon) {
499 period = strchr(colon, '.');
500 if (period)
501 *period = '\0';
502 }
503 printf("display: %s screen: %d\n", displayName, scrnum);
504 free(displayName);
Michel Dänzerb46e3592006-12-06 14:54:43 +0100505 printf("direct rendering: ");
506 if (glXIsDirect(dpy, ctx)) {
507 printf("Yes\n");
508 } else {
509 if (!allowDirect) {
510 printf("No (-i specified)\n");
511 } else if (getenv("LIBGL_ALWAYS_INDIRECT")) {
512 printf("No (LIBGL_ALWAYS_INDIRECT set)\n");
513 } else {
514 printf("No (If you want to find out why, try setting "
515 "LIBGL_DEBUG=verbose)\n");
516 }
517 }
Brian Paul76bc4402000-01-27 16:43:56 +0000518 printf("server glx vendor string: %s\n", serverVendor);
519 printf("server glx version string: %s\n", serverVersion);
520 printf("server glx extensions:\n");
521 print_extension_list(serverExtensions);
Brian Paul34fb5db2000-04-22 20:31:23 +0000522 printf("client glx vendor string: %s\n", clientVendor);
523 printf("client glx version string: %s\n", clientVersion);
Brian Paul76bc4402000-01-27 16:43:56 +0000524 printf("client glx extensions:\n");
525 print_extension_list(clientExtensions);
Ian Romanickc00fbd52004-02-23 17:37:36 +0000526 printf("GLX version: %u.%u\n", glxVersionMajor, glxVersionMinor);
Brian Paul76bc4402000-01-27 16:43:56 +0000527 printf("GLX extensions:\n");
528 print_extension_list(glxExtensions);
529 printf("OpenGL vendor string: %s\n", glVendor);
530 printf("OpenGL renderer string: %s\n", glRenderer);
531 printf("OpenGL version string: %s\n", glVersion);
Brian Paul51bfb6a2008-07-24 14:27:11 -0600532#ifdef GL_VERSION_2_0
533 if (glVersion[0] >= '2' && glVersion[1] == '.') {
534 char *v = (char *) glGetString(GL_SHADING_LANGUAGE_VERSION);
535 printf("OpenGL shading language version string: %s\n", v);
536 }
537#endif
538
Brian Paul76bc4402000-01-27 16:43:56 +0000539 printf("OpenGL extensions:\n");
540 print_extension_list(glExtensions);
Brian Paul2f7ef5f2002-09-06 03:35:43 +0000541 if (limits)
Brian Paulad7805d2006-05-13 00:18:12 +0000542 print_limits(glExtensions);
Brian Paul76bc4402000-01-27 16:43:56 +0000543 }
Brian Paul9cff5582000-05-07 18:07:23 +0000544 else {
545 fprintf(stderr, "Error: glXMakeCurrent failed\n");
546 }
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000547
548 glXDestroyContext(dpy, ctx);
Brian Paul361bccb2006-01-16 16:17:18 +0000549 XFree(visinfo);
Brian Pauld2bfe1e1999-09-16 16:40:46 +0000550 XDestroyWindow(dpy, win);
Brian Paul76bc4402000-01-27 16:43:56 +0000551}
552
553
554static const char *
555visual_class_name(int cls)
556{
557 switch (cls) {
558 case StaticColor:
559 return "StaticColor";
560 case PseudoColor:
561 return "PseudoColor";
562 case StaticGray:
563 return "StaticGray";
564 case GrayScale:
565 return "GrayScale";
566 case TrueColor:
567 return "TrueColor";
568 case DirectColor:
569 return "DirectColor";
570 default:
571 return "";
572 }
573}
574
575
576static const char *
577visual_class_abbrev(int cls)
578{
579 switch (cls) {
580 case StaticColor:
581 return "sc";
582 case PseudoColor:
583 return "pc";
584 case StaticGray:
585 return "sg";
586 case GrayScale:
587 return "gs";
588 case TrueColor:
589 return "tc";
590 case DirectColor:
591 return "dc";
592 default:
593 return "";
594 }
595}
596
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400597static const char *
598visual_render_type_name(int type)
599{
600 switch (type) {
601 case GLX_RGBA_BIT:
602 return "rgba";
603 case GLX_COLOR_INDEX_BIT:
604 return "ci";
605 case GLX_RGBA_BIT | GLX_COLOR_INDEX_BIT:
606 return "rgba|ci";
607 default:
608 return "";
609 }
610}
Brian Paul76bc4402000-01-27 16:43:56 +0000611
Kristian Høgsbergf7d1d552007-10-15 20:12:01 -0400612static GLboolean
Brian Paul76bc4402000-01-27 16:43:56 +0000613get_visual_attribs(Display *dpy, XVisualInfo *vInfo,
614 struct visual_attribs *attribs)
615{
Brian Paul25673f02000-03-31 18:17:51 +0000616 const char *ext = glXQueryExtensionsString(dpy, vInfo->screen);
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400617 int rgba;
Brian Paul25673f02000-03-31 18:17:51 +0000618
Brian Paula9c53fa2000-04-03 15:45:34 +0000619 memset(attribs, 0, sizeof(struct visual_attribs));
620
Brian Paul76bc4402000-01-27 16:43:56 +0000621 attribs->id = vInfo->visualid;
622#if defined(__cplusplus) || defined(c_plusplus)
623 attribs->klass = vInfo->c_class;
624#else
625 attribs->klass = vInfo->class;
626#endif
627 attribs->depth = vInfo->depth;
628 attribs->redMask = vInfo->red_mask;
629 attribs->greenMask = vInfo->green_mask;
630 attribs->blueMask = vInfo->blue_mask;
631 attribs->colormapSize = vInfo->colormap_size;
632 attribs->bitsPerRGB = vInfo->bits_per_rgb;
633
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400634 if (glXGetConfig(dpy, vInfo, GLX_USE_GL, &attribs->supportsGL) != 0 ||
635 !attribs->supportsGL)
Kristian Høgsbergf7d1d552007-10-15 20:12:01 -0400636 return GL_FALSE;
Brian Paul76bc4402000-01-27 16:43:56 +0000637 glXGetConfig(dpy, vInfo, GLX_BUFFER_SIZE, &attribs->bufferSize);
638 glXGetConfig(dpy, vInfo, GLX_LEVEL, &attribs->level);
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400639 glXGetConfig(dpy, vInfo, GLX_RGBA, &rgba);
640 if (rgba)
641 attribs->render_type = GLX_RGBA_BIT;
642 else
643 attribs->render_type = GLX_COLOR_INDEX_BIT;
644
Brian Paul76bc4402000-01-27 16:43:56 +0000645 glXGetConfig(dpy, vInfo, GLX_DOUBLEBUFFER, &attribs->doubleBuffer);
646 glXGetConfig(dpy, vInfo, GLX_STEREO, &attribs->stereo);
647 glXGetConfig(dpy, vInfo, GLX_AUX_BUFFERS, &attribs->auxBuffers);
648 glXGetConfig(dpy, vInfo, GLX_RED_SIZE, &attribs->redSize);
649 glXGetConfig(dpy, vInfo, GLX_GREEN_SIZE, &attribs->greenSize);
650 glXGetConfig(dpy, vInfo, GLX_BLUE_SIZE, &attribs->blueSize);
651 glXGetConfig(dpy, vInfo, GLX_ALPHA_SIZE, &attribs->alphaSize);
652 glXGetConfig(dpy, vInfo, GLX_DEPTH_SIZE, &attribs->depthSize);
653 glXGetConfig(dpy, vInfo, GLX_STENCIL_SIZE, &attribs->stencilSize);
654 glXGetConfig(dpy, vInfo, GLX_ACCUM_RED_SIZE, &attribs->accumRedSize);
655 glXGetConfig(dpy, vInfo, GLX_ACCUM_GREEN_SIZE, &attribs->accumGreenSize);
656 glXGetConfig(dpy, vInfo, GLX_ACCUM_BLUE_SIZE, &attribs->accumBlueSize);
657 glXGetConfig(dpy, vInfo, GLX_ACCUM_ALPHA_SIZE, &attribs->accumAlphaSize);
658
Brian Paul45c56982002-10-14 13:57:23 +0000659 /* get transparent pixel stuff */
660 glXGetConfig(dpy, vInfo,GLX_TRANSPARENT_TYPE, &attribs->transparentType);
661 if (attribs->transparentType == GLX_TRANSPARENT_RGB) {
662 glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_RED_VALUE, &attribs->transparentRedValue);
663 glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_GREEN_VALUE, &attribs->transparentGreenValue);
664 glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_BLUE_VALUE, &attribs->transparentBlueValue);
665 glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_ALPHA_VALUE, &attribs->transparentAlphaValue);
666 }
667 else if (attribs->transparentType == GLX_TRANSPARENT_INDEX) {
668 glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_INDEX_VALUE, &attribs->transparentIndexValue);
669 }
Brian Paule06c7f32000-01-27 16:53:55 +0000670
Brian Pauld2e39bb2002-11-04 16:24:18 +0000671 /* multisample attribs */
672#ifdef GLX_ARB_multisample
Adam Jacksone1ae5b82008-01-22 14:57:20 -0500673 if (ext && strstr(ext, "GLX_ARB_multisample")) {
Brian Pauld2e39bb2002-11-04 16:24:18 +0000674 glXGetConfig(dpy, vInfo, GLX_SAMPLE_BUFFERS_ARB, &attribs->numMultisample);
675 glXGetConfig(dpy, vInfo, GLX_SAMPLES_ARB, &attribs->numSamples);
676 }
677#endif
678 else {
679 attribs->numSamples = 0;
680 attribs->numMultisample = 0;
681 }
Brian Paul25673f02000-03-31 18:17:51 +0000682
683#if defined(GLX_EXT_visual_rating)
684 if (ext && strstr(ext, "GLX_EXT_visual_rating")) {
685 glXGetConfig(dpy, vInfo, GLX_VISUAL_CAVEAT_EXT, &attribs->visualCaveat);
686 }
687 else {
688 attribs->visualCaveat = GLX_NONE_EXT;
689 }
690#else
691 attribs->visualCaveat = 0;
692#endif
Kristian Høgsbergf7d1d552007-10-15 20:12:01 -0400693
694 return GL_TRUE;
Brian Paul76bc4402000-01-27 16:43:56 +0000695}
696
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400697#ifdef GLX_VERSION_1_3
698
699static int
700glx_token_to_visual_class(int visual_type)
701{
702 switch (visual_type) {
703 case GLX_TRUE_COLOR:
704 return TrueColor;
705 case GLX_DIRECT_COLOR:
706 return DirectColor;
707 case GLX_PSEUDO_COLOR:
708 return PseudoColor;
709 case GLX_STATIC_COLOR:
710 return StaticColor;
711 case GLX_GRAY_SCALE:
712 return GrayScale;
713 case GLX_STATIC_GRAY:
714 return StaticGray;
715 case GLX_NONE:
716 default:
717 return None;
718 }
719}
720
721static GLboolean
722get_fbconfig_attribs(Display *dpy, GLXFBConfig fbconfig,
723 struct visual_attribs *attribs)
724{
725 int visual_type;
726
727 memset(attribs, 0, sizeof(struct visual_attribs));
728
729 glXGetFBConfigAttrib(dpy, fbconfig, GLX_FBCONFIG_ID, &attribs->id);
730
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400731#if 0
732 attribs->depth = vInfo->depth;
733 attribs->redMask = vInfo->red_mask;
734 attribs->greenMask = vInfo->green_mask;
735 attribs->blueMask = vInfo->blue_mask;
736 attribs->colormapSize = vInfo->colormap_size;
737 attribs->bitsPerRGB = vInfo->bits_per_rgb;
738#endif
739
740 glXGetFBConfigAttrib(dpy, fbconfig, GLX_X_VISUAL_TYPE, &visual_type);
741 attribs->klass = glx_token_to_visual_class(visual_type);
742
743 glXGetFBConfigAttrib(dpy, fbconfig, GLX_BUFFER_SIZE, &attribs->bufferSize);
744 glXGetFBConfigAttrib(dpy, fbconfig, GLX_LEVEL, &attribs->level);
745 glXGetFBConfigAttrib(dpy, fbconfig, GLX_RENDER_TYPE, &attribs->render_type);
746 glXGetFBConfigAttrib(dpy, fbconfig, GLX_DOUBLEBUFFER, &attribs->doubleBuffer);
747 glXGetFBConfigAttrib(dpy, fbconfig, GLX_STEREO, &attribs->stereo);
748 glXGetFBConfigAttrib(dpy, fbconfig, GLX_AUX_BUFFERS, &attribs->auxBuffers);
749
750 glXGetFBConfigAttrib(dpy, fbconfig, GLX_RED_SIZE, &attribs->redSize);
751 glXGetFBConfigAttrib(dpy, fbconfig, GLX_GREEN_SIZE, &attribs->greenSize);
752 glXGetFBConfigAttrib(dpy, fbconfig, GLX_BLUE_SIZE, &attribs->blueSize);
753 glXGetFBConfigAttrib(dpy, fbconfig, GLX_ALPHA_SIZE, &attribs->alphaSize);
754 glXGetFBConfigAttrib(dpy, fbconfig, GLX_DEPTH_SIZE, &attribs->depthSize);
755 glXGetFBConfigAttrib(dpy, fbconfig, GLX_STENCIL_SIZE, &attribs->stencilSize);
756
757 glXGetFBConfigAttrib(dpy, fbconfig, GLX_ACCUM_RED_SIZE, &attribs->accumRedSize);
758 glXGetFBConfigAttrib(dpy, fbconfig, GLX_ACCUM_GREEN_SIZE, &attribs->accumGreenSize);
759 glXGetFBConfigAttrib(dpy, fbconfig, GLX_ACCUM_BLUE_SIZE, &attribs->accumBlueSize);
760 glXGetFBConfigAttrib(dpy, fbconfig, GLX_ACCUM_ALPHA_SIZE, &attribs->accumAlphaSize);
761
762 /* get transparent pixel stuff */
763 glXGetFBConfigAttrib(dpy, fbconfig,GLX_TRANSPARENT_TYPE, &attribs->transparentType);
764 if (attribs->transparentType == GLX_TRANSPARENT_RGB) {
765 glXGetFBConfigAttrib(dpy, fbconfig, GLX_TRANSPARENT_RED_VALUE, &attribs->transparentRedValue);
766 glXGetFBConfigAttrib(dpy, fbconfig, GLX_TRANSPARENT_GREEN_VALUE, &attribs->transparentGreenValue);
767 glXGetFBConfigAttrib(dpy, fbconfig, GLX_TRANSPARENT_BLUE_VALUE, &attribs->transparentBlueValue);
768 glXGetFBConfigAttrib(dpy, fbconfig, GLX_TRANSPARENT_ALPHA_VALUE, &attribs->transparentAlphaValue);
769 }
770 else if (attribs->transparentType == GLX_TRANSPARENT_INDEX) {
771 glXGetFBConfigAttrib(dpy, fbconfig, GLX_TRANSPARENT_INDEX_VALUE, &attribs->transparentIndexValue);
772 }
773
774 glXGetFBConfigAttrib(dpy, fbconfig, GLX_SAMPLE_BUFFERS, &attribs->numMultisample);
775 glXGetFBConfigAttrib(dpy, fbconfig, GLX_SAMPLES, &attribs->numSamples);
776 glXGetFBConfigAttrib(dpy, fbconfig, GLX_CONFIG_CAVEAT, &attribs->visualCaveat);
777
778 return GL_TRUE;
779}
780
781#endif
782
783
Brian Paul76bc4402000-01-27 16:43:56 +0000784
785static void
786print_visual_attribs_verbose(const struct visual_attribs *attribs)
787{
788 printf("Visual ID: %x depth=%d class=%s\n",
789 attribs->id, attribs->depth, visual_class_name(attribs->klass));
790 printf(" bufferSize=%d level=%d renderType=%s doubleBuffer=%d stereo=%d\n",
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400791 attribs->bufferSize, attribs->level,
792 visual_render_type_name(attribs->render_type),
Brian Paul76bc4402000-01-27 16:43:56 +0000793 attribs->doubleBuffer, attribs->stereo);
794 printf(" rgba: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n",
795 attribs->redSize, attribs->greenSize,
796 attribs->blueSize, attribs->alphaSize);
797 printf(" auxBuffers=%d depthSize=%d stencilSize=%d\n",
798 attribs->auxBuffers, attribs->depthSize, attribs->stencilSize);
799 printf(" accum: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n",
800 attribs->accumRedSize, attribs->accumGreenSize,
801 attribs->accumBlueSize, attribs->accumAlphaSize);
802 printf(" multiSample=%d multiSampleBuffers=%d\n",
803 attribs->numSamples, attribs->numMultisample);
Brian Paul25673f02000-03-31 18:17:51 +0000804#ifdef GLX_EXT_visual_rating
805 if (attribs->visualCaveat == GLX_NONE_EXT || attribs->visualCaveat == 0)
Brian Paula9c53fa2000-04-03 15:45:34 +0000806 printf(" visualCaveat=None\n");
Brian Paul25673f02000-03-31 18:17:51 +0000807 else if (attribs->visualCaveat == GLX_SLOW_VISUAL_EXT)
Brian Paula9c53fa2000-04-03 15:45:34 +0000808 printf(" visualCaveat=Slow\n");
Brian Paul25673f02000-03-31 18:17:51 +0000809 else if (attribs->visualCaveat == GLX_NON_CONFORMANT_VISUAL_EXT)
Brian Paula9c53fa2000-04-03 15:45:34 +0000810 printf(" visualCaveat=Nonconformant\n");
Brian Paul25673f02000-03-31 18:17:51 +0000811#endif
Brian Paul45c56982002-10-14 13:57:23 +0000812 if (attribs->transparentType == GLX_NONE) {
813 printf(" Opaque.\n");
814 }
815 else if (attribs->transparentType == GLX_TRANSPARENT_RGB) {
816 printf(" Transparent RGB: Red=%d Green=%d Blue=%d Alpha=%d\n",attribs->transparentRedValue,attribs->transparentGreenValue,attribs->transparentBlueValue,attribs->transparentAlphaValue);
817 }
818 else if (attribs->transparentType == GLX_TRANSPARENT_INDEX) {
819 printf(" Transparent index=%d\n",attribs->transparentIndexValue);
820 }
Brian Paul76bc4402000-01-27 16:43:56 +0000821}
822
823
824static void
825print_visual_attribs_short_header(void)
826{
Brian Paula9c53fa2000-04-03 15:45:34 +0000827 printf(" visual x bf lv rg d st colorbuffer ax dp st accumbuffer ms cav\n");
828 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 +0000829 printf("----------------------------------------------------------------------\n");
Brian Paul76bc4402000-01-27 16:43:56 +0000830}
831
832
833static void
834print_visual_attribs_short(const struct visual_attribs *attribs)
835{
Brian Paula3e44f42002-03-08 19:44:28 +0000836 char *caveat = NULL;
Brian Paul25673f02000-03-31 18:17:51 +0000837#ifdef GLX_EXT_visual_rating
838 if (attribs->visualCaveat == GLX_NONE_EXT || attribs->visualCaveat == 0)
839 caveat = "None";
840 else if (attribs->visualCaveat == GLX_SLOW_VISUAL_EXT)
841 caveat = "Slow";
842 else if (attribs->visualCaveat == GLX_NON_CONFORMANT_VISUAL_EXT)
843 caveat = "Ncon";
Brian Paul28bc6cb2002-09-06 03:47:34 +0000844 else
845 caveat = "None";
Brian Paul25673f02000-03-31 18:17:51 +0000846#else
847 caveat = "None";
848#endif
849
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400850 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 +0000851 attribs->id,
852 attribs->depth,
853 visual_class_abbrev(attribs->klass),
Brian Paul45c56982002-10-14 13:57:23 +0000854 attribs->transparentType != GLX_NONE,
Brian Paul76bc4402000-01-27 16:43:56 +0000855 attribs->bufferSize,
856 attribs->level,
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400857 (attribs->render_type & GLX_RGBA_BIT) ? 'r' : ' ',
858 (attribs->render_type & GLX_COLOR_INDEX_BIT) ? 'c' : ' ',
859 attribs->doubleBuffer ? 'y' : '.',
860 attribs->stereo ? 'y' : '.',
Brian Paul76bc4402000-01-27 16:43:56 +0000861 attribs->redSize, attribs->greenSize,
862 attribs->blueSize, attribs->alphaSize,
863 attribs->auxBuffers,
864 attribs->depthSize,
865 attribs->stencilSize
866 );
867
Brian Paul25673f02000-03-31 18:17:51 +0000868 printf(" %2d %2d %2d %2d %2d %1d %s\n",
Brian Paul76bc4402000-01-27 16:43:56 +0000869 attribs->accumRedSize, attribs->accumGreenSize,
870 attribs->accumBlueSize, attribs->accumAlphaSize,
Brian Paul25673f02000-03-31 18:17:51 +0000871 attribs->numSamples, attribs->numMultisample,
872 caveat
Brian Paul76bc4402000-01-27 16:43:56 +0000873 );
874}
875
876
877static void
878print_visual_attribs_long_header(void)
879{
880 printf("Vis Vis Visual Trans buff lev render DB ste r g b a aux dep ste accum buffers MS MS\n");
881 printf(" ID Depth Type parent size el type reo sz sz sz sz buf th ncl r g b a num bufs\n");
882 printf("----------------------------------------------------------------------------------------------------\n");
883}
884
885
886static void
887print_visual_attribs_long(const struct visual_attribs *attribs)
888{
889 printf("0x%2x %2d %-11s %2d %2d %2d %4s %3d %3d %3d %3d %3d %3d",
890 attribs->id,
891 attribs->depth,
892 visual_class_name(attribs->klass),
Brian Paul45c56982002-10-14 13:57:23 +0000893 attribs->transparentType != GLX_NONE,
Brian Paul76bc4402000-01-27 16:43:56 +0000894 attribs->bufferSize,
895 attribs->level,
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400896 visual_render_type_name(attribs->render_type),
Brian Paul76bc4402000-01-27 16:43:56 +0000897 attribs->doubleBuffer,
898 attribs->stereo,
899 attribs->redSize, attribs->greenSize,
900 attribs->blueSize, attribs->alphaSize
901 );
902
903 printf(" %3d %4d %2d %3d %3d %3d %3d %2d %2d\n",
904 attribs->auxBuffers,
905 attribs->depthSize,
906 attribs->stencilSize,
907 attribs->accumRedSize, attribs->accumGreenSize,
908 attribs->accumBlueSize, attribs->accumAlphaSize,
909 attribs->numSamples, attribs->numMultisample
910 );
911}
912
913
914static void
915print_visual_info(Display *dpy, int scrnum, InfoMode mode)
916{
Brian Paulf02a5f62002-07-12 15:54:01 +0000917 XVisualInfo theTemplate;
Brian Paul76bc4402000-01-27 16:43:56 +0000918 XVisualInfo *visuals;
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400919 int numVisuals, numGlxVisuals;
Brian Paul76bc4402000-01-27 16:43:56 +0000920 long mask;
921 int i;
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400922 struct visual_attribs attribs;
Brian Paul76bc4402000-01-27 16:43:56 +0000923
924 /* get list of all visuals on this screen */
Brian Paulf02a5f62002-07-12 15:54:01 +0000925 theTemplate.screen = scrnum;
Brian Paul76bc4402000-01-27 16:43:56 +0000926 mask = VisualScreenMask;
Brian Paulf02a5f62002-07-12 15:54:01 +0000927 visuals = XGetVisualInfo(dpy, mask, &theTemplate, &numVisuals);
Brian Paul76bc4402000-01-27 16:43:56 +0000928
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400929 numGlxVisuals = 0;
930 for (i = 0; i < numVisuals; i++) {
931 if (get_visual_attribs(dpy, &visuals[i], &attribs))
932 numGlxVisuals++;
Brian Paul76bc4402000-01-27 16:43:56 +0000933 }
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400934
935 if (numGlxVisuals == 0)
936 return;
937
938 printf("%d GLX Visuals\n", numGlxVisuals);
939
940 if (mode == Normal)
Brian Paul76bc4402000-01-27 16:43:56 +0000941 print_visual_attribs_short_header();
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400942 else if (mode == Wide)
Brian Paul76bc4402000-01-27 16:43:56 +0000943 print_visual_attribs_long_header();
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400944
945 for (i = 0; i < numVisuals; i++) {
946 if (!get_visual_attribs(dpy, &visuals[i], &attribs))
947 continue;
948
949 if (mode == Verbose)
950 print_visual_attribs_verbose(&attribs);
951 else if (mode == Normal)
952 print_visual_attribs_short(&attribs);
953 else if (mode == Wide)
Brian Paul76bc4402000-01-27 16:43:56 +0000954 print_visual_attribs_long(&attribs);
Brian Paul76bc4402000-01-27 16:43:56 +0000955 }
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400956 printf("\n");
Brian Paul76bc4402000-01-27 16:43:56 +0000957
958 XFree(visuals);
959}
960
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400961#ifdef GLX_VERSION_1_3
962
963static void
964print_fbconfig_info(Display *dpy, int scrnum, InfoMode mode)
965{
966 int numFBConfigs;
967 struct visual_attribs attribs;
968 GLXFBConfig *fbconfigs;
969 int i;
970
971 /* get list of all fbconfigs on this screen */
972 fbconfigs = glXGetFBConfigs(dpy, scrnum, &numFBConfigs);
973
Vinson Lee7324c222009-11-20 13:01:22 -0800974 if (numFBConfigs == 0) {
975 XFree(fbconfigs);
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400976 return;
Vinson Lee7324c222009-11-20 13:01:22 -0800977 }
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400978
Kristian Høgsberga5b4bb32007-10-17 14:43:35 -0400979 printf("%d GLXFBConfigs:\n", numFBConfigs);
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -0400980 if (mode == Normal)
981 print_visual_attribs_short_header();
982 else if (mode == Wide)
983 print_visual_attribs_long_header();
984
985 for (i = 0; i < numFBConfigs; i++) {
986 get_fbconfig_attribs(dpy, fbconfigs[i], &attribs);
987
988 if (mode == Verbose)
989 print_visual_attribs_verbose(&attribs);
990 else if (mode == Normal)
991 print_visual_attribs_short(&attribs);
992 else if (mode == Wide)
993 print_visual_attribs_long(&attribs);
994 }
995 printf("\n");
996
997 XFree(fbconfigs);
998}
999
1000#endif
Brian Paul76bc4402000-01-27 16:43:56 +00001001
Brian Paul39557c32001-03-23 21:41:44 +00001002/*
1003 * Stand-alone Mesa doesn't really implement the GLX protocol so it
1004 * doesn't really know the GLX attributes associated with an X visual.
1005 * The first time a visual is presented to Mesa's pseudo-GLX it
1006 * attaches ancilliary buffers to it (like depth and stencil).
1007 * But that usually only works if glXChooseVisual is used.
1008 * This function calls glXChooseVisual() to sort of "prime the pump"
1009 * for Mesa's GLX so that the visuals that get reported actually
1010 * reflect what applications will see.
1011 * This has no effect when using true GLX.
1012 */
1013static void
1014mesa_hack(Display *dpy, int scrnum)
1015{
1016 static int attribs[] = {
1017 GLX_RGBA,
1018 GLX_RED_SIZE, 1,
1019 GLX_GREEN_SIZE, 1,
1020 GLX_BLUE_SIZE, 1,
1021 GLX_DEPTH_SIZE, 1,
1022 GLX_STENCIL_SIZE, 1,
1023 GLX_ACCUM_RED_SIZE, 1,
1024 GLX_ACCUM_GREEN_SIZE, 1,
1025 GLX_ACCUM_BLUE_SIZE, 1,
1026 GLX_ACCUM_ALPHA_SIZE, 1,
1027 GLX_DOUBLEBUFFER,
1028 None
1029 };
1030 XVisualInfo *visinfo;
1031
1032 visinfo = glXChooseVisual(dpy, scrnum, attribs);
1033 if (visinfo)
1034 XFree(visinfo);
1035}
1036
1037
1038/*
1039 * Examine all visuals to find the so-called best one.
1040 * We prefer deepest RGBA buffer with depth, stencil and accum
1041 * that has no caveats.
1042 */
1043static int
1044find_best_visual(Display *dpy, int scrnum)
1045{
Brian Paulf02a5f62002-07-12 15:54:01 +00001046 XVisualInfo theTemplate;
Brian Paul39557c32001-03-23 21:41:44 +00001047 XVisualInfo *visuals;
1048 int numVisuals;
1049 long mask;
1050 int i;
1051 struct visual_attribs bestVis;
1052
1053 /* get list of all visuals on this screen */
Brian Paulf02a5f62002-07-12 15:54:01 +00001054 theTemplate.screen = scrnum;
Brian Paul39557c32001-03-23 21:41:44 +00001055 mask = VisualScreenMask;
Brian Paulf02a5f62002-07-12 15:54:01 +00001056 visuals = XGetVisualInfo(dpy, mask, &theTemplate, &numVisuals);
Brian Paul39557c32001-03-23 21:41:44 +00001057
1058 /* init bestVis with first visual info */
1059 get_visual_attribs(dpy, &visuals[0], &bestVis);
1060
1061 /* try to find a "better" visual */
1062 for (i = 1; i < numVisuals; i++) {
1063 struct visual_attribs vis;
1064
1065 get_visual_attribs(dpy, &visuals[i], &vis);
1066
1067 /* always skip visuals with caveats */
1068 if (vis.visualCaveat != GLX_NONE_EXT)
1069 continue;
1070
1071 /* see if this vis is better than bestVis */
1072 if ((!bestVis.supportsGL && vis.supportsGL) ||
1073 (bestVis.visualCaveat != GLX_NONE_EXT) ||
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -04001074 (!(bestVis.render_type & GLX_RGBA_BIT) && (vis.render_type & GLX_RGBA_BIT)) ||
Brian Paul39557c32001-03-23 21:41:44 +00001075 (!bestVis.doubleBuffer && vis.doubleBuffer) ||
1076 (bestVis.redSize < vis.redSize) ||
1077 (bestVis.greenSize < vis.greenSize) ||
1078 (bestVis.blueSize < vis.blueSize) ||
1079 (bestVis.alphaSize < vis.alphaSize) ||
1080 (bestVis.depthSize < vis.depthSize) ||
1081 (bestVis.stencilSize < vis.stencilSize) ||
1082 (bestVis.accumRedSize < vis.accumRedSize)) {
1083 /* found a better visual */
1084 bestVis = vis;
1085 }
1086 }
1087
1088 XFree(visuals);
1089
1090 return bestVis.id;
1091}
1092
1093
Brian Paul08b3ff12001-04-24 20:57:36 +00001094static void
1095usage(void)
1096{
1097 printf("Usage: glxinfo [-v] [-t] [-h] [-i] [-b] [-display <dname>]\n");
1098 printf("\t-v: Print visuals info in verbose form.\n");
1099 printf("\t-t: Print verbose table.\n");
1100 printf("\t-display <dname>: Print GLX visuals on specified server.\n");
1101 printf("\t-h: This information.\n");
1102 printf("\t-i: Force an indirect rendering context.\n");
1103 printf("\t-b: Find the 'best' visual and print it's number.\n");
Brian Paul0b77a1c2003-04-09 21:50:08 +00001104 printf("\t-l: Print interesting OpenGL limits.\n");
Brian Paul08b3ff12001-04-24 20:57:36 +00001105}
1106
1107
Brian Paul76bc4402000-01-27 16:43:56 +00001108int
1109main(int argc, char *argv[])
1110{
Alan Hourihanee18599a2001-03-19 13:58:45 +00001111 char *displayName = NULL;
Brian Paul76bc4402000-01-27 16:43:56 +00001112 Display *dpy;
1113 int numScreens, scrnum;
1114 InfoMode mode = Normal;
Brian Paul39557c32001-03-23 21:41:44 +00001115 GLboolean findBest = GL_FALSE;
Brian Paul2f7ef5f2002-09-06 03:35:43 +00001116 GLboolean limits = GL_FALSE;
Brian Paul08b3ff12001-04-24 20:57:36 +00001117 Bool allowDirect = True;
Brian Paul76bc4402000-01-27 16:43:56 +00001118 int i;
1119
1120 for (i = 1; i < argc; i++) {
1121 if (strcmp(argv[i], "-display") == 0 && i + 1 < argc) {
1122 displayName = argv[i + 1];
1123 i++;
1124 }
1125 else if (strcmp(argv[i], "-t") == 0) {
1126 mode = Wide;
1127 }
1128 else if (strcmp(argv[i], "-v") == 0) {
1129 mode = Verbose;
1130 }
Brian Paul39557c32001-03-23 21:41:44 +00001131 else if (strcmp(argv[i], "-b") == 0) {
1132 findBest = GL_TRUE;
1133 }
Brian Paul08b3ff12001-04-24 20:57:36 +00001134 else if (strcmp(argv[i], "-i") == 0) {
1135 allowDirect = False;
1136 }
Brian Paul2f7ef5f2002-09-06 03:35:43 +00001137 else if (strcmp(argv[i], "-l") == 0) {
1138 limits = GL_TRUE;
1139 }
Brian Paul08b3ff12001-04-24 20:57:36 +00001140 else if (strcmp(argv[i], "-h") == 0) {
1141 usage();
1142 return 0;
1143 }
1144 else {
1145 printf("Unknown option `%s'\n", argv[i]);
1146 usage();
1147 return 0;
1148 }
Brian Paul76bc4402000-01-27 16:43:56 +00001149 }
1150
1151 dpy = XOpenDisplay(displayName);
1152 if (!dpy) {
Brian73eee242006-12-13 08:30:26 -07001153 fprintf(stderr, "Error: unable to open display %s\n", XDisplayName(displayName));
Brian Paul76bc4402000-01-27 16:43:56 +00001154 return -1;
1155 }
1156
Brian Paul39557c32001-03-23 21:41:44 +00001157 if (findBest) {
1158 int b;
1159 mesa_hack(dpy, 0);
1160 b = find_best_visual(dpy, 0);
1161 printf("%d\n", b);
1162 }
1163 else {
1164 numScreens = ScreenCount(dpy);
Brian Paul373aea12001-04-02 22:45:07 +00001165 print_display_info(dpy);
Brian Paul39557c32001-03-23 21:41:44 +00001166 for (scrnum = 0; scrnum < numScreens; scrnum++) {
1167 mesa_hack(dpy, scrnum);
Brian Paul2f7ef5f2002-09-06 03:35:43 +00001168 print_screen_info(dpy, scrnum, allowDirect, limits);
Brian Paul39557c32001-03-23 21:41:44 +00001169 printf("\n");
1170 print_visual_info(dpy, scrnum, mode);
Kristian Høgsberg87966ba2007-10-17 10:14:55 -04001171#ifdef GLX_VERSION_1_3
Kristian Høgsberg791ad0e2007-10-16 16:01:34 -04001172 print_fbconfig_info(dpy, scrnum, mode);
Kristian Høgsberg87966ba2007-10-17 10:14:55 -04001173#endif
Brian Paul39557c32001-03-23 21:41:44 +00001174 if (scrnum + 1 < numScreens)
1175 printf("\n\n");
1176 }
Brian Paul76bc4402000-01-27 16:43:56 +00001177 }
1178
Brian Pauld2bfe1e1999-09-16 16:40:46 +00001179 XCloseDisplay(dpy);
1180
1181 return 0;
1182}