mesa: minor fixes in _mesa_GetTransformFeedbackVarying()
[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 HDC hdc;
352 PIXELFORMATDESCRIPTOR pfd;
353
354 memset(&wc, 0, sizeof wc);
355 wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1);
356 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
357 wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
358 wc.lpfnWndProc = WndProc;
359 wc.lpszClassName = "wglinfo";
360 wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
361 RegisterClass(&wc);
362
363 win = CreateWindowEx(0,
364 wc.lpszClassName,
365 "wglinfo",
366 WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
367 CW_USEDEFAULT,
368 CW_USEDEFAULT,
369 CW_USEDEFAULT,
370 CW_USEDEFAULT,
371 NULL,
372 NULL,
373 wc.hInstance,
374 NULL);
375 if (!win) {
376 fprintf(stderr, "Couldn't create window");
377 return;
378 }
379
380 hdc = GetDC(win);
381 if (!hdc) {
382 fprintf(stderr, "Couldn't obtain HDC");
383 return;
384 }
385
386 pfd.cColorBits = 3;
387 pfd.cRedBits = 1;
388 pfd.cGreenBits = 1;
389 pfd.cBlueBits = 1;
390 pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
391 pfd.iLayerType = PFD_MAIN_PLANE;
392 pfd.iPixelType = PFD_TYPE_RGBA;
393 pfd.nSize = sizeof(pfd);
394 pfd.nVersion = 1;
395
396 visinfo = ChoosePixelFormat(hdc, &pfd);
397 if (!visinfo) {
398 pfd.dwFlags |= PFD_DOUBLEBUFFER;
399 visinfo = ChoosePixelFormat(hdc, &pfd);
400 }
401
402 if (!visinfo) {
403 fprintf(stderr, "Error: couldn't find RGB WGL visual\n");
404 return;
405 }
406
407 SetPixelFormat(hdc, visinfo, &pfd);
408 ctx = wglCreateContext(hdc);
409 if (!ctx) {
410 fprintf(stderr, "Error: wglCreateContext failed\n");
411 return;
412 }
413
414 if (wglMakeCurrent(hdc, ctx)) {
415 #if defined(WGL_ARB_extensions_string)
416 PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB_func =
417 (PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB");
418 #endif
419 const char *glVendor = (const char *) glGetString(GL_VENDOR);
420 const char *glRenderer = (const char *) glGetString(GL_RENDERER);
421 const char *glVersion = (const char *) glGetString(GL_VERSION);
422 const char *glExtensions = (const char *) glGetString(GL_EXTENSIONS);
423
424 #if defined(WGL_ARB_extensions_string)
425 if(wglGetExtensionsStringARB_func) {
426 const char *wglExtensions = wglGetExtensionsStringARB_func(hdc);
427 if(wglExtensions) {
428 printf("WGL extensions:\n");
429 print_extension_list(wglExtensions);
430 }
431 }
432 #endif
433 printf("OpenGL vendor string: %s\n", glVendor);
434 printf("OpenGL renderer string: %s\n", glRenderer);
435 printf("OpenGL version string: %s\n", glVersion);
436 #ifdef GL_VERSION_2_0
437 if (glVersion[0] >= '2' && glVersion[1] == '.') {
438 char *v = (char *) glGetString(GL_SHADING_LANGUAGE_VERSION);
439 printf("OpenGL shading language version string: %s\n", v);
440 }
441 #endif
442
443 printf("OpenGL extensions:\n");
444 print_extension_list(glExtensions);
445 if (limits)
446 print_limits(glExtensions);
447 }
448 else {
449 fprintf(stderr, "Error: wglMakeCurrent failed\n");
450 }
451
452 DestroyWindow(win);
453 }
454
455
456 static const char *
457 visual_render_type_name(BYTE iPixelType)
458 {
459 switch (iPixelType) {
460 case PFD_TYPE_RGBA:
461 return "rgba";
462 case PFD_TYPE_COLORINDEX:
463 return "ci";
464 default:
465 return "";
466 }
467 }
468
469 static void
470 print_visual_attribs_verbose(int iPixelFormat, LPPIXELFORMATDESCRIPTOR ppfd)
471 {
472 printf("Visual ID: %x generic=%d native=%d\n",
473 iPixelFormat,
474 ppfd->dwFlags & PFD_GENERIC_FORMAT ? 1 : 0,
475 ppfd->dwFlags & PFD_DRAW_TO_WINDOW ? 1 : 0);
476 printf(" bufferSize=%d level=%d renderType=%s doubleBuffer=%d stereo=%d\n",
477 0 /* ppfd->bufferSize */, 0 /* ppfd->level */,
478 visual_render_type_name(ppfd->iPixelType),
479 ppfd->dwFlags & PFD_DOUBLEBUFFER ? 1 : 0,
480 ppfd->dwFlags & PFD_STEREO ? 1 : 0);
481 printf(" rgba: cRedBits=%d cGreenBits=%d cBlueBits=%d cAlphaBits=%d\n",
482 ppfd->cRedBits, ppfd->cGreenBits,
483 ppfd->cBlueBits, ppfd->cAlphaBits);
484 printf(" cAuxBuffers=%d cDepthBits=%d cStencilBits=%d\n",
485 ppfd->cAuxBuffers, ppfd->cDepthBits, ppfd->cStencilBits);
486 printf(" accum: cRedBits=%d cGreenBits=%d cBlueBits=%d cAlphaBits=%d\n",
487 ppfd->cAccumRedBits, ppfd->cAccumGreenBits,
488 ppfd->cAccumBlueBits, ppfd->cAccumAlphaBits);
489 printf(" multiSample=%d multiSampleBuffers=%d\n",
490 0 /* ppfd->numSamples */, 0 /* ppfd->numMultisample */);
491 }
492
493
494 static void
495 print_visual_attribs_short_header(void)
496 {
497 printf(" visual x bf lv rg d st colorbuffer ax dp st accumbuffer ms cav\n");
498 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");
499 printf("-----------------------------------------------------------------------\n");
500 }
501
502
503 static void
504 print_visual_attribs_short(int iPixelFormat, LPPIXELFORMATDESCRIPTOR ppfd)
505 {
506 char *caveat = "None";
507
508 printf("0x%02x %2d %2d %2d %2d %2d %c%c %c %c %2d %2d %2d %2d %2d %2d %2d",
509 iPixelFormat,
510 ppfd->dwFlags & PFD_GENERIC_FORMAT ? 1 : 0,
511 ppfd->dwFlags & PFD_DRAW_TO_WINDOW ? 1 : 0,
512 0,
513 0 /* ppfd->bufferSize */,
514 0 /* ppfd->level */,
515 ppfd->iPixelType == PFD_TYPE_RGBA ? 'r' : ' ',
516 ppfd->iPixelType == PFD_TYPE_COLORINDEX ? 'c' : ' ',
517 ppfd->dwFlags & PFD_DOUBLEBUFFER ? 'y' : '.',
518 ppfd->dwFlags & PFD_STEREO ? 'y' : '.',
519 ppfd->cRedBits, ppfd->cGreenBits,
520 ppfd->cBlueBits, ppfd->cAlphaBits,
521 ppfd->cAuxBuffers,
522 ppfd->cDepthBits,
523 ppfd->cStencilBits
524 );
525
526 printf(" %2d %2d %2d %2d %2d %1d %s\n",
527 ppfd->cAccumRedBits, ppfd->cAccumGreenBits,
528 ppfd->cAccumBlueBits, ppfd->cAccumAlphaBits,
529 0 /* ppfd->numSamples */, 0 /* ppfd->numMultisample */,
530 caveat
531 );
532 }
533
534
535 static void
536 print_visual_attribs_long_header(void)
537 {
538 printf("Vis Vis Visual Trans buff lev render DB ste r g b a aux dep ste accum buffers MS MS\n");
539 printf(" ID Depth Type parent size el type reo sz sz sz sz buf th ncl r g b a num bufs\n");
540 printf("----------------------------------------------------------------------------------------------------\n");
541 }
542
543
544 static void
545 print_visual_attribs_long(int iPixelFormat, LPPIXELFORMATDESCRIPTOR ppfd)
546 {
547 printf("0x%2x %2d %11d %2d %2d %2d %4s %3d %3d %3d %3d %3d %3d",
548 iPixelFormat,
549 ppfd->dwFlags & PFD_GENERIC_FORMAT ? 1 : 0,
550 ppfd->dwFlags & PFD_DRAW_TO_WINDOW ? 1 : 0,
551 0,
552 0 /* ppfd->bufferSize */,
553 0 /* ppfd->level */,
554 visual_render_type_name(ppfd->iPixelType),
555 ppfd->dwFlags & PFD_DOUBLEBUFFER ? 1 : 0,
556 ppfd->dwFlags & PFD_STEREO ? 1 : 0,
557 ppfd->cRedBits, ppfd->cGreenBits,
558 ppfd->cBlueBits, ppfd->cAlphaBits
559 );
560
561 printf(" %3d %4d %2d %3d %3d %3d %3d %2d %2d\n",
562 ppfd->cAuxBuffers,
563 ppfd->cDepthBits,
564 ppfd->cStencilBits,
565 ppfd->cAccumRedBits, ppfd->cAccumGreenBits,
566 ppfd->cAccumBlueBits, ppfd->cAccumAlphaBits,
567 0 /* ppfd->numSamples */, 0 /* ppfd->numMultisample */
568 );
569 }
570
571
572 static void
573 print_visual_info(HDC hdc, InfoMode mode)
574 {
575 PIXELFORMATDESCRIPTOR pfd;
576 int numVisuals, numWglVisuals;
577 int i;
578
579 numVisuals = DescribePixelFormat(hdc, 1, sizeof(PIXELFORMATDESCRIPTOR), NULL);
580 if (numVisuals == 0)
581 return;
582
583 numWglVisuals = 0;
584 for (i = 0; i < numVisuals; i++) {
585 if(!DescribePixelFormat(hdc, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd))
586 continue;
587
588 //if(!(pfd.dwFlags & PFD_SUPPORT_OPENGL))
589 // continue;
590
591 ++numWglVisuals;
592 }
593
594 printf("%d WGL Visuals\n", numWglVisuals);
595
596 if (mode == Normal)
597 print_visual_attribs_short_header();
598 else if (mode == Wide)
599 print_visual_attribs_long_header();
600
601 for (i = 0; i < numVisuals; i++) {
602 if(!DescribePixelFormat(hdc, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd))
603 continue;
604
605 //if(!(pfd.dwFlags & PFD_SUPPORT_OPENGL))
606 // continue;
607
608 if (mode == Verbose)
609 print_visual_attribs_verbose(i, &pfd);
610 else if (mode == Normal)
611 print_visual_attribs_short(i, &pfd);
612 else if (mode == Wide)
613 print_visual_attribs_long(i, &pfd);
614 }
615 printf("\n");
616 }
617
618
619 /*
620 * Examine all visuals to find the so-called best one.
621 * We prefer deepest RGBA buffer with depth, stencil and accum
622 * that has no caveats.
623 */
624 static int
625 find_best_visual(HDC hdc)
626 {
627 #if 0
628 XVisualInfo theTemplate;
629 XVisualInfo *visuals;
630 int numVisuals;
631 long mask;
632 int i;
633 struct visual_attribs bestVis;
634
635 /* get list of all visuals on this screen */
636 theTemplate.screen = scrnum;
637 mask = VisualScreenMask;
638 visuals = XGetVisualInfo(hdc, mask, &theTemplate, &numVisuals);
639
640 /* init bestVis with first visual info */
641 get_visual_attribs(hdc, &visuals[0], &bestVis);
642
643 /* try to find a "better" visual */
644 for (i = 1; i < numVisuals; i++) {
645 struct visual_attribs vis;
646
647 get_visual_attribs(hdc, &visuals[i], &vis);
648
649 /* always skip visuals with caveats */
650 if (vis.visualCaveat != GLX_NONE_EXT)
651 continue;
652
653 /* see if this vis is better than bestVis */
654 if ((!bestVis.supportsGL && vis.supportsGL) ||
655 (bestVis.visualCaveat != GLX_NONE_EXT) ||
656 (bestVis.iPixelType != vis.iPixelType) ||
657 (!bestVis.doubleBuffer && vis.doubleBuffer) ||
658 (bestVis.cRedBits < vis.cRedBits) ||
659 (bestVis.cGreenBits < vis.cGreenBits) ||
660 (bestVis.cBlueBits < vis.cBlueBits) ||
661 (bestVis.cAlphaBits < vis.cAlphaBits) ||
662 (bestVis.cDepthBits < vis.cDepthBits) ||
663 (bestVis.cStencilBits < vis.cStencilBits) ||
664 (bestVis.cAccumRedBits < vis.cAccumRedBits)) {
665 /* found a better visual */
666 bestVis = vis;
667 }
668 }
669
670 return bestVis.id;
671 #else
672 return 0;
673 #endif
674 }
675
676
677 static void
678 usage(void)
679 {
680 printf("Usage: glxinfo [-v] [-t] [-h] [-i] [-b] [-display <dname>]\n");
681 printf("\t-v: Print visuals info in verbose form.\n");
682 printf("\t-t: Print verbose table.\n");
683 printf("\t-h: This information.\n");
684 printf("\t-b: Find the 'best' visual and print it's number.\n");
685 printf("\t-l: Print interesting OpenGL limits.\n");
686 }
687
688
689 int
690 main(int argc, char *argv[])
691 {
692 HDC hdc;
693 InfoMode mode = Normal;
694 GLboolean findBest = GL_FALSE;
695 GLboolean limits = GL_FALSE;
696 int i;
697
698 for (i = 1; i < argc; i++) {
699 if (strcmp(argv[i], "-t") == 0) {
700 mode = Wide;
701 }
702 else if (strcmp(argv[i], "-v") == 0) {
703 mode = Verbose;
704 }
705 else if (strcmp(argv[i], "-b") == 0) {
706 findBest = GL_TRUE;
707 }
708 else if (strcmp(argv[i], "-l") == 0) {
709 limits = GL_TRUE;
710 }
711 else if (strcmp(argv[i], "-h") == 0) {
712 usage();
713 return 0;
714 }
715 else {
716 printf("Unknown option `%s'\n", argv[i]);
717 usage();
718 return 0;
719 }
720 }
721
722 hdc = CreateDC(TEXT("DISPLAY"), NULL, NULL, NULL);
723
724 if (findBest) {
725 int b;
726 b = find_best_visual(hdc);
727 printf("%d\n", b);
728 }
729 else {
730 print_screen_info(hdc, limits);
731 printf("\n");
732 print_visual_info(hdc, mode);
733 }
734
735 return 0;
736 }