wgl: Note down the gallium pixel formats, instead of re-guessing them.
[mesa.git] / progs / wgl / wglinfo.c
1 /*
2 * Copyright (C) 2009 VMware, Inc.
3 * Copyright (C) 1999-2006 Brian Paul
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23
24
25 /*
26 * This program is a work-alike of the GLX glxinfo program.
27 * Command line options:
28 * -t print wide table
29 * -v print verbose information
30 * -b only print ID of "best" visual on screen 0
31 * -l print interesting OpenGL limits (added 5 Sep 2002)
32 */
33
34 #include <windows.h>
35
36 #include <GL/gl.h>
37 #include <GL/glext.h>
38 #include <GL/wglext.h>
39 #include <stdio.h>
40 #include <string.h>
41 #include <stdlib.h>
42
43
44 typedef enum
45 {
46 Normal,
47 Wide,
48 Verbose
49 } InfoMode;
50
51
52 /*
53 * Print a list of extensions, with word-wrapping.
54 */
55 static void
56 print_extension_list(const char *ext)
57 {
58 const char *indentString = " ";
59 const int indent = 4;
60 const int max = 79;
61 int width, i, j;
62
63 if (!ext || !ext[0])
64 return;
65
66 width = indent;
67 printf(indentString);
68 i = j = 0;
69 while (1) {
70 if (ext[j] == ' ' || ext[j] == 0) {
71 /* found end of an extension name */
72 const int len = j - i;
73 if (width + len > max) {
74 /* start a new line */
75 printf("\n");
76 width = indent;
77 printf(indentString);
78 }
79 /* print the extension name between ext[i] and ext[j] */
80 while (i < j) {
81 printf("%c", ext[i]);
82 i++;
83 }
84 /* either we're all done, or we'll continue with next extension */
85 width += len + 1;
86 if (ext[j] == 0) {
87 break;
88 }
89 else {
90 i++;
91 j++;
92 if (ext[j] == 0)
93 break;
94 printf(", ");
95 width += 2;
96 }
97 }
98 j++;
99 }
100 printf("\n");
101 }
102
103
104 /**
105 * Print interesting limits for vertex/fragment programs.
106 */
107 static void
108 print_program_limits(GLenum target)
109 {
110 #if defined(GL_ARB_vertex_program) || defined(GL_ARB_fragment_program)
111 struct token_name {
112 GLenum token;
113 const char *name;
114 };
115 static const struct token_name limits[] = {
116 { GL_MAX_PROGRAM_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_INSTRUCTIONS_ARB" },
117 { GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB" },
118 { GL_MAX_PROGRAM_TEMPORARIES_ARB, "GL_MAX_PROGRAM_TEMPORARIES_ARB" },
119 { GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB, "GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB" },
120 { GL_MAX_PROGRAM_PARAMETERS_ARB, "GL_MAX_PROGRAM_PARAMETERS_ARB" },
121 { GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB, "GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB" },
122 { GL_MAX_PROGRAM_ATTRIBS_ARB, "GL_MAX_PROGRAM_ATTRIBS_ARB" },
123 { GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB, "GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB" },
124 { GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB, "GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB" },
125 { GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB, "GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB" },
126 { GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB, "GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB" },
127 { GL_MAX_PROGRAM_ENV_PARAMETERS_ARB, "GL_MAX_PROGRAM_ENV_PARAMETERS_ARB" },
128 { GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB" },
129 { GL_MAX_PROGRAM_TEX_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_TEX_INSTRUCTIONS_ARB" },
130 { GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB, "GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB" },
131 { GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB" },
132 { GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB" },
133 { GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB, "GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB" },
134 { (GLenum) 0, NULL }
135 };
136 PFNGLGETPROGRAMIVARBPROC GetProgramivARB_func = (PFNGLGETPROGRAMIVARBPROC)
137 wglGetProcAddress("glGetProgramivARB");
138 GLint max[1];
139 int i;
140
141 if (target == GL_VERTEX_PROGRAM_ARB) {
142 printf(" GL_VERTEX_PROGRAM_ARB:\n");
143 }
144 else if (target == GL_FRAGMENT_PROGRAM_ARB) {
145 printf(" GL_FRAGMENT_PROGRAM_ARB:\n");
146 }
147 else {
148 return; /* something's wrong */
149 }
150
151 for (i = 0; limits[i].token; i++) {
152 GetProgramivARB_func(target, limits[i].token, max);
153 if (glGetError() == GL_NO_ERROR) {
154 printf(" %s = %d\n", limits[i].name, max[0]);
155 }
156 }
157 #endif /* GL_ARB_vertex_program / GL_ARB_fragment_program */
158 }
159
160
161 /**
162 * Print interesting limits for vertex/fragment shaders.
163 */
164 static void
165 print_shader_limits(GLenum target)
166 {
167 struct token_name {
168 GLenum token;
169 const char *name;
170 };
171 #if defined(GL_ARB_vertex_shader)
172 static const struct token_name vertex_limits[] = {
173 { GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB, "GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB" },
174 { GL_MAX_VARYING_FLOATS_ARB, "GL_MAX_VARYING_FLOATS_ARB" },
175 { GL_MAX_VERTEX_ATTRIBS_ARB, "GL_MAX_VERTEX_ATTRIBS_ARB" },
176 { GL_MAX_TEXTURE_IMAGE_UNITS_ARB, "GL_MAX_TEXTURE_IMAGE_UNITS_ARB" },
177 { GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB, "GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB" },
178 { GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB, "GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB" },
179 { GL_MAX_TEXTURE_COORDS_ARB, "GL_MAX_TEXTURE_COORDS_ARB" },
180 { (GLenum) 0, NULL }
181 };
182 #endif
183 #if defined(GL_ARB_fragment_shader)
184 static const struct token_name fragment_limits[] = {
185 { GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB, "GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB" },
186 { GL_MAX_TEXTURE_COORDS_ARB, "GL_MAX_TEXTURE_COORDS_ARB" },
187 { GL_MAX_TEXTURE_IMAGE_UNITS_ARB, "GL_MAX_TEXTURE_IMAGE_UNITS_ARB" },
188 { (GLenum) 0, NULL }
189 };
190 #endif
191 GLint max[1];
192 int i;
193
194 #if defined(GL_ARB_vertex_shader)
195 if (target == GL_VERTEX_SHADER_ARB) {
196 printf(" GL_VERTEX_SHADER_ARB:\n");
197 for (i = 0; vertex_limits[i].token; i++) {
198 glGetIntegerv(vertex_limits[i].token, max);
199 if (glGetError() == GL_NO_ERROR) {
200 printf(" %s = %d\n", vertex_limits[i].name, max[0]);
201 }
202 }
203 }
204 #endif
205 #if defined(GL_ARB_fragment_shader)
206 if (target == GL_FRAGMENT_SHADER_ARB) {
207 printf(" GL_FRAGMENT_SHADER_ARB:\n");
208 for (i = 0; fragment_limits[i].token; i++) {
209 glGetIntegerv(fragment_limits[i].token, max);
210 if (glGetError() == GL_NO_ERROR) {
211 printf(" %s = %d\n", fragment_limits[i].name, max[0]);
212 }
213 }
214 }
215 #endif
216 }
217
218
219 /**
220 * Print interesting OpenGL implementation limits.
221 */
222 static void
223 print_limits(const char *extensions)
224 {
225 struct token_name {
226 GLuint count;
227 GLenum token;
228 const char *name;
229 };
230 static const struct token_name limits[] = {
231 { 1, GL_MAX_ATTRIB_STACK_DEPTH, "GL_MAX_ATTRIB_STACK_DEPTH" },
232 { 1, GL_MAX_CLIENT_ATTRIB_STACK_DEPTH, "GL_MAX_CLIENT_ATTRIB_STACK_DEPTH" },
233 { 1, GL_MAX_CLIP_PLANES, "GL_MAX_CLIP_PLANES" },
234 { 1, GL_MAX_COLOR_MATRIX_STACK_DEPTH, "GL_MAX_COLOR_MATRIX_STACK_DEPTH" },
235 { 1, GL_MAX_ELEMENTS_VERTICES, "GL_MAX_ELEMENTS_VERTICES" },
236 { 1, GL_MAX_ELEMENTS_INDICES, "GL_MAX_ELEMENTS_INDICES" },
237 { 1, GL_MAX_EVAL_ORDER, "GL_MAX_EVAL_ORDER" },
238 { 1, GL_MAX_LIGHTS, "GL_MAX_LIGHTS" },
239 { 1, GL_MAX_LIST_NESTING, "GL_MAX_LIST_NESTING" },
240 { 1, GL_MAX_MODELVIEW_STACK_DEPTH, "GL_MAX_MODELVIEW_STACK_DEPTH" },
241 { 1, GL_MAX_NAME_STACK_DEPTH, "GL_MAX_NAME_STACK_DEPTH" },
242 { 1, GL_MAX_PIXEL_MAP_TABLE, "GL_MAX_PIXEL_MAP_TABLE" },
243 { 1, GL_MAX_PROJECTION_STACK_DEPTH, "GL_MAX_PROJECTION_STACK_DEPTH" },
244 { 1, GL_MAX_TEXTURE_STACK_DEPTH, "GL_MAX_TEXTURE_STACK_DEPTH" },
245 { 1, GL_MAX_TEXTURE_SIZE, "GL_MAX_TEXTURE_SIZE" },
246 { 1, GL_MAX_3D_TEXTURE_SIZE, "GL_MAX_3D_TEXTURE_SIZE" },
247 { 2, GL_MAX_VIEWPORT_DIMS, "GL_MAX_VIEWPORT_DIMS" },
248 { 2, GL_ALIASED_LINE_WIDTH_RANGE, "GL_ALIASED_LINE_WIDTH_RANGE" },
249 { 2, GL_SMOOTH_LINE_WIDTH_RANGE, "GL_SMOOTH_LINE_WIDTH_RANGE" },
250 { 2, GL_ALIASED_POINT_SIZE_RANGE, "GL_ALIASED_POINT_SIZE_RANGE" },
251 { 2, GL_SMOOTH_POINT_SIZE_RANGE, "GL_SMOOTH_POINT_SIZE_RANGE" },
252 #if defined(GL_ARB_texture_cube_map)
253 { 1, GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB, "GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB" },
254 #endif
255 #if defined(GLX_NV_texture_rectangle)
256 { 1, GL_MAX_RECTANGLE_TEXTURE_SIZE_NV, "GL_MAX_RECTANGLE_TEXTURE_SIZE_NV" },
257 #endif
258 #if defined(GL_ARB_texture_compression)
259 { 1, GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB, "GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB" },
260 #endif
261 #if defined(GL_ARB_multitexture)
262 { 1, GL_MAX_TEXTURE_UNITS_ARB, "GL_MAX_TEXTURE_UNITS_ARB" },
263 #endif
264 #if defined(GL_EXT_texture_lod_bias)
265 { 1, GL_MAX_TEXTURE_LOD_BIAS_EXT, "GL_MAX_TEXTURE_LOD_BIAS_EXT" },
266 #endif
267 #if defined(GL_EXT_texture_filter_anisotropic)
268 { 1, GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, "GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT" },
269 #endif
270 #if defined(GL_ARB_draw_buffers)
271 { 1, GL_MAX_DRAW_BUFFERS_ARB, "GL_MAX_DRAW_BUFFERS_ARB" },
272 #endif
273 { 0, (GLenum) 0, NULL }
274 };
275 GLint i, max[2];
276
277 printf("OpenGL limits:\n");
278 for (i = 0; limits[i].count; i++) {
279 glGetIntegerv(limits[i].token, max);
280 if (glGetError() == GL_NO_ERROR) {
281 if (limits[i].count == 1)
282 printf(" %s = %d\n", limits[i].name, max[0]);
283 else /* XXX fix if we ever query something with more than 2 values */
284 printf(" %s = %d, %d\n", limits[i].name, max[0], max[1]);
285 }
286 }
287
288 #if defined(GL_EXT_convolution)
289 {
290 PFNGLGETCONVOLUTIONPARAMETERIVEXTPROC glGetConvolutionParameterivEXT_func =
291 (PFNGLGETCONVOLUTIONPARAMETERIVEXTPROC)wglGetProcAddress("glGetConvolutionParameterivEXT");
292 if(glGetConvolutionParameterivEXT_func) {
293 /* these don't fit into the above mechanism, unfortunately */
294 glGetConvolutionParameterivEXT_func(GL_CONVOLUTION_2D, GL_MAX_CONVOLUTION_WIDTH, max);
295 glGetConvolutionParameterivEXT_func(GL_CONVOLUTION_2D, GL_MAX_CONVOLUTION_HEIGHT, max+1);
296 if (glGetError() == GL_NONE) {
297 printf(" GL_MAX_CONVOLUTION_WIDTH/HEIGHT = %d, %d\n", max[0], max[1]);
298 }
299 }
300 }
301 #endif
302
303 #if defined(GL_ARB_vertex_program)
304 if (strstr(extensions, "GL_ARB_vertex_program")) {
305 print_program_limits(GL_VERTEX_PROGRAM_ARB);
306 }
307 #endif
308 #if defined(GL_ARB_fragment_program)
309 if (strstr(extensions, "GL_ARB_fragment_program")) {
310 print_program_limits(GL_FRAGMENT_PROGRAM_ARB);
311 }
312 #endif
313 #if defined(GL_ARB_vertex_shader)
314 if (strstr(extensions, "GL_ARB_vertex_shader")) {
315 print_shader_limits(GL_VERTEX_SHADER_ARB);
316 }
317 #endif
318 #if defined(GL_ARB_fragment_shader)
319 if (strstr(extensions, "GL_ARB_fragment_shader")) {
320 print_shader_limits(GL_FRAGMENT_SHADER_ARB);
321 }
322 #endif
323 }
324
325
326 static LRESULT CALLBACK
327 WndProc(HWND hWnd,
328 UINT uMsg,
329 WPARAM wParam,
330 LPARAM lParam )
331 {
332 switch (uMsg) {
333 case WM_DESTROY:
334 PostQuitMessage(0);
335 break;
336 default:
337 return DefWindowProc(hWnd, uMsg, wParam, lParam);
338 }
339
340 return 0;
341 }
342
343
344 static void
345 print_screen_info(HDC _hdc, GLboolean limits)
346 {
347 WNDCLASS wc;
348 HWND win;
349 HGLRC ctx;
350 int visinfo;
351 int width = 100, height = 100;
352 HDC hdc;
353 PIXELFORMATDESCRIPTOR pfd;
354
355 memset(&wc, 0, sizeof wc);
356 wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1);
357 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
358 wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
359 wc.lpfnWndProc = WndProc;
360 wc.lpszClassName = "wglinfo";
361 wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
362 RegisterClass(&wc);
363
364 win = CreateWindowEx(0,
365 wc.lpszClassName,
366 "wglinfo",
367 WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
368 CW_USEDEFAULT,
369 CW_USEDEFAULT,
370 width,
371 height,
372 NULL,
373 NULL,
374 wc.hInstance,
375 NULL);
376 if (!win) {
377 fprintf(stderr, "Couldn't create window");
378 exit(1);
379 }
380
381 hdc = GetDC(win);
382 if (!hdc) {
383 fprintf(stderr, "Couldn't obtain HDC");
384 return;
385 }
386
387 pfd.cColorBits = 3;
388 pfd.cRedBits = 1;
389 pfd.cGreenBits = 1;
390 pfd.cBlueBits = 1;
391 pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
392 pfd.iLayerType = PFD_MAIN_PLANE;
393 pfd.iPixelType = PFD_TYPE_RGBA;
394 pfd.nSize = sizeof(pfd);
395 pfd.nVersion = 1;
396
397 visinfo = ChoosePixelFormat(hdc, &pfd);
398 if (!visinfo) {
399 pfd.dwFlags |= PFD_DOUBLEBUFFER;
400 visinfo = ChoosePixelFormat(hdc, &pfd);
401 }
402
403 if (!visinfo) {
404 fprintf(stderr, "Error: couldn't find RGB WGL visual\n");
405 return;
406 }
407
408 SetPixelFormat(hdc, visinfo, &pfd);
409 ctx = wglCreateContext(hdc);
410 if (!ctx) {
411 fprintf(stderr, "Error: wglCreateContext failed\n");
412 return;
413 }
414
415 if (wglMakeCurrent(hdc, ctx)) {
416 #if defined(WGL_ARB_extensions_string)
417 PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB_func =
418 (PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB");
419 #endif
420 const char *glVendor = (const char *) glGetString(GL_VENDOR);
421 const char *glRenderer = (const char *) glGetString(GL_RENDERER);
422 const char *glVersion = (const char *) glGetString(GL_VERSION);
423 const char *glExtensions = (const char *) glGetString(GL_EXTENSIONS);
424
425 #if defined(WGL_ARB_extensions_string)
426 if(wglGetExtensionsStringARB_func) {
427 const char *wglExtensions = wglGetExtensionsStringARB_func(hdc);
428 if(wglExtensions) {
429 printf("WGL extensions:\n");
430 print_extension_list(wglExtensions);
431 }
432 }
433 #endif
434 printf("OpenGL vendor string: %s\n", glVendor);
435 printf("OpenGL renderer string: %s\n", glRenderer);
436 printf("OpenGL version string: %s\n", glVersion);
437 #ifdef GL_VERSION_2_0
438 if (glVersion[0] >= '2' && glVersion[1] == '.') {
439 char *v = (char *) glGetString(GL_SHADING_LANGUAGE_VERSION);
440 printf("OpenGL shading language version string: %s\n", v);
441 }
442 #endif
443
444 printf("OpenGL extensions:\n");
445 print_extension_list(glExtensions);
446 if (limits)
447 print_limits(glExtensions);
448 }
449 else {
450 fprintf(stderr, "Error: wglMakeCurrent failed\n");
451 }
452
453 DestroyWindow(win);
454 }
455
456
457 static const char *
458 visual_render_type_name(BYTE iPixelType)
459 {
460 switch (iPixelType) {
461 case PFD_TYPE_RGBA:
462 return "rgba";
463 case PFD_TYPE_COLORINDEX:
464 return "ci";
465 default:
466 return "";
467 }
468 }
469
470 static void
471 print_visual_attribs_verbose(int iPixelFormat, LPPIXELFORMATDESCRIPTOR ppfd)
472 {
473 printf("Visual ID: %x generic=%d native=%d\n",
474 iPixelFormat,
475 ppfd->dwFlags & PFD_GENERIC_FORMAT ? 1 : 0,
476 ppfd->dwFlags & PFD_DRAW_TO_WINDOW ? 1 : 0);
477 printf(" bufferSize=%d level=%d renderType=%s doubleBuffer=%d stereo=%d\n",
478 0 /* ppfd->bufferSize */, 0 /* ppfd->level */,
479 visual_render_type_name(ppfd->dwFlags),
480 ppfd->dwFlags & PFD_DOUBLEBUFFER ? 1 : 0,
481 ppfd->dwFlags & PFD_STEREO ? 1 : 0);
482 printf(" rgba: cRedBits=%d cGreenBits=%d cBlueBits=%d cAlphaBits=%d\n",
483 ppfd->cRedBits, ppfd->cGreenBits,
484 ppfd->cBlueBits, ppfd->cAlphaBits);
485 printf(" cAuxBuffers=%d cDepthBits=%d cStencilBits=%d\n",
486 ppfd->cAuxBuffers, ppfd->cDepthBits, ppfd->cStencilBits);
487 printf(" accum: cRedBits=%d cGreenBits=%d cBlueBits=%d cAlphaBits=%d\n",
488 ppfd->cAccumRedBits, ppfd->cAccumGreenBits,
489 ppfd->cAccumBlueBits, ppfd->cAccumAlphaBits);
490 printf(" multiSample=%d multiSampleBuffers=%d\n",
491 0 /* ppfd->numSamples */, 0 /* ppfd->numMultisample */);
492 }
493
494
495 static void
496 print_visual_attribs_short_header(void)
497 {
498 printf(" visual x bf lv rg d st colorbuffer ax dp st accumbuffer ms cav\n");
499 printf(" id gen nat sp sz l ci b ro r g b a bf th cl r g b a ns b eat\n");
500 printf("-----------------------------------------------------------------------\n");
501 }
502
503
504 static void
505 print_visual_attribs_short(int iPixelFormat, LPPIXELFORMATDESCRIPTOR ppfd)
506 {
507 char *caveat = "None";
508
509 printf("0x%02x %2d %2d %2d %2d %2d %c%c %c %c %2d %2d %2d %2d %2d %2d %2d",
510 iPixelFormat,
511 ppfd->dwFlags & PFD_GENERIC_FORMAT ? 1 : 0,
512 ppfd->dwFlags & PFD_DRAW_TO_WINDOW ? 1 : 0,
513 0,
514 0 /* ppfd->bufferSize */,
515 0 /* ppfd->level */,
516 ppfd->iPixelType == PFD_TYPE_RGBA ? 'r' : ' ',
517 ppfd->iPixelType == PFD_TYPE_COLORINDEX ? 'c' : ' ',
518 ppfd->dwFlags & PFD_DOUBLEBUFFER ? 'y' : '.',
519 ppfd->dwFlags & PFD_STEREO ? 'y' : '.',
520 ppfd->cRedBits, ppfd->cGreenBits,
521 ppfd->cBlueBits, ppfd->cAlphaBits,
522 ppfd->cAuxBuffers,
523 ppfd->cDepthBits,
524 ppfd->cStencilBits
525 );
526
527 printf(" %2d %2d %2d %2d %2d %1d %s\n",
528 ppfd->cAccumRedBits, ppfd->cAccumGreenBits,
529 ppfd->cAccumBlueBits, ppfd->cAccumAlphaBits,
530 0 /* ppfd->numSamples */, 0 /* ppfd->numMultisample */,
531 caveat
532 );
533 }
534
535
536 static void
537 print_visual_attribs_long_header(void)
538 {
539 printf("Vis Vis Visual Trans buff lev render DB ste r g b a aux dep ste accum buffers MS MS\n");
540 printf(" ID Depth Type parent size el type reo sz sz sz sz buf th ncl r g b a num bufs\n");
541 printf("----------------------------------------------------------------------------------------------------\n");
542 }
543
544
545 static void
546 print_visual_attribs_long(int iPixelFormat, LPPIXELFORMATDESCRIPTOR ppfd)
547 {
548 printf("0x%2x %2d %11d %2d %2d %2d %4s %3d %3d %3d %3d %3d %3d",
549 iPixelFormat,
550 ppfd->dwFlags & PFD_GENERIC_FORMAT ? 1 : 0,
551 ppfd->dwFlags & PFD_DRAW_TO_WINDOW ? 1 : 0,
552 0,
553 0 /* ppfd->bufferSize */,
554 0 /* ppfd->level */,
555 visual_render_type_name(ppfd->iPixelType),
556 ppfd->dwFlags & PFD_DOUBLEBUFFER ? 1 : 0,
557 ppfd->dwFlags & PFD_STEREO ? 1 : 0,
558 ppfd->cRedBits, ppfd->cGreenBits,
559 ppfd->cBlueBits, ppfd->cAlphaBits
560 );
561
562 printf(" %3d %4d %2d %3d %3d %3d %3d %2d %2d\n",
563 ppfd->cAuxBuffers,
564 ppfd->cDepthBits,
565 ppfd->cStencilBits,
566 ppfd->cAccumRedBits, ppfd->cAccumGreenBits,
567 ppfd->cAccumBlueBits, ppfd->cAccumAlphaBits,
568 0 /* ppfd->numSamples */, 0 /* ppfd->numMultisample */
569 );
570 }
571
572
573 static void
574 print_visual_info(HDC hdc, InfoMode mode)
575 {
576 PIXELFORMATDESCRIPTOR pfd;
577 int numVisuals, numWglVisuals;
578 int i;
579
580 numVisuals = DescribePixelFormat(hdc, 1, sizeof(PIXELFORMATDESCRIPTOR), NULL);
581 if (numVisuals == 0)
582 return;
583
584 numWglVisuals = 0;
585 for (i = 0; i < numVisuals; i++) {
586 if(!DescribePixelFormat(hdc, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd))
587 continue;
588
589 //if(!(pfd.dwFlags & PFD_SUPPORT_OPENGL))
590 // continue;
591
592 ++numWglVisuals;
593 }
594
595 printf("%d WGL Visuals\n", numWglVisuals);
596
597 if (mode == Normal)
598 print_visual_attribs_short_header();
599 else if (mode == Wide)
600 print_visual_attribs_long_header();
601
602 for (i = 0; i < numVisuals; i++) {
603 if(!DescribePixelFormat(hdc, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd))
604 continue;
605
606 //if(!(pfd.dwFlags & PFD_SUPPORT_OPENGL))
607 // continue;
608
609 if (mode == Verbose)
610 print_visual_attribs_verbose(i, &pfd);
611 else if (mode == Normal)
612 print_visual_attribs_short(i, &pfd);
613 else if (mode == Wide)
614 print_visual_attribs_long(i, &pfd);
615 }
616 printf("\n");
617 }
618
619
620 /*
621 * Examine all visuals to find the so-called best one.
622 * We prefer deepest RGBA buffer with depth, stencil and accum
623 * that has no caveats.
624 */
625 static int
626 find_best_visual(HDC hdc)
627 {
628 #if 0
629 XVisualInfo theTemplate;
630 XVisualInfo *visuals;
631 int numVisuals;
632 long mask;
633 int i;
634 struct visual_attribs bestVis;
635
636 /* get list of all visuals on this screen */
637 theTemplate.screen = scrnum;
638 mask = VisualScreenMask;
639 visuals = XGetVisualInfo(hdc, mask, &theTemplate, &numVisuals);
640
641 /* init bestVis with first visual info */
642 get_visual_attribs(hdc, &visuals[0], &bestVis);
643
644 /* try to find a "better" visual */
645 for (i = 1; i < numVisuals; i++) {
646 struct visual_attribs vis;
647
648 get_visual_attribs(hdc, &visuals[i], &vis);
649
650 /* always skip visuals with caveats */
651 if (vis.visualCaveat != GLX_NONE_EXT)
652 continue;
653
654 /* see if this vis is better than bestVis */
655 if ((!bestVis.supportsGL && vis.supportsGL) ||
656 (bestVis.visualCaveat != GLX_NONE_EXT) ||
657 (bestVis.iPixelType != vis.iPixelType) ||
658 (!bestVis.doubleBuffer && vis.doubleBuffer) ||
659 (bestVis.cRedBits < vis.cRedBits) ||
660 (bestVis.cGreenBits < vis.cGreenBits) ||
661 (bestVis.cBlueBits < vis.cBlueBits) ||
662 (bestVis.cAlphaBits < vis.cAlphaBits) ||
663 (bestVis.cDepthBits < vis.cDepthBits) ||
664 (bestVis.cStencilBits < vis.cStencilBits) ||
665 (bestVis.cAccumRedBits < vis.cAccumRedBits)) {
666 /* found a better visual */
667 bestVis = vis;
668 }
669 }
670
671 return bestVis.id;
672 #else
673 return 0;
674 #endif
675 }
676
677
678 static void
679 usage(void)
680 {
681 printf("Usage: glxinfo [-v] [-t] [-h] [-i] [-b] [-display <dname>]\n");
682 printf("\t-v: Print visuals info in verbose form.\n");
683 printf("\t-t: Print verbose table.\n");
684 printf("\t-h: This information.\n");
685 printf("\t-b: Find the 'best' visual and print it's number.\n");
686 printf("\t-l: Print interesting OpenGL limits.\n");
687 }
688
689
690 int
691 main(int argc, char *argv[])
692 {
693 HDC hdc;
694 InfoMode mode = Normal;
695 GLboolean findBest = GL_FALSE;
696 GLboolean limits = GL_FALSE;
697 int i;
698
699 for (i = 1; i < argc; i++) {
700 if (strcmp(argv[i], "-t") == 0) {
701 mode = Wide;
702 }
703 else if (strcmp(argv[i], "-v") == 0) {
704 mode = Verbose;
705 }
706 else if (strcmp(argv[i], "-b") == 0) {
707 findBest = GL_TRUE;
708 }
709 else if (strcmp(argv[i], "-l") == 0) {
710 limits = GL_TRUE;
711 }
712 else if (strcmp(argv[i], "-h") == 0) {
713 usage();
714 return 0;
715 }
716 else {
717 printf("Unknown option `%s'\n", argv[i]);
718 usage();
719 return 0;
720 }
721 }
722
723 hdc = CreateDC(TEXT("DISPLAY"), NULL, NULL, NULL);
724
725 if (findBest) {
726 int b;
727 b = find_best_visual(hdc);
728 printf("%d\n", b);
729 }
730 else {
731 print_screen_info(hdc, limits);
732 printf("\n");
733 print_visual_info(hdc, mode);
734 }
735
736 return 0;
737 }