4 ** Copyright (C) Nate Robins, 1997
\r
5 ** Michael Wimmer, 1999
\r
6 ** Milan Ikits, 2002-2008
\r
8 ** visualinfo is a small utility that displays all available visuals,
\r
9 ** aka. pixelformats, in an OpenGL system along with renderer version
\r
10 ** information. It shows a table of all the visuals that support OpenGL
\r
11 ** along with their capabilities. The format of the table is similar to
\r
12 ** that of glxinfo on Unix systems:
\r
14 ** visual ~= pixel format descriptor
\r
15 ** id = visual id (integer from 1 - max visuals)
\r
16 ** tp = type (wn: window, pb: pbuffer, wp: window & pbuffer, bm: bitmap)
\r
17 ** ac = acceleration (ge: generic, fu: full, no: none)
\r
18 ** fm = format (i: integer, f: float, c: color index)
\r
19 ** db = double buffer (y = yes)
\r
20 ** sw = swap method (x: exchange, c: copy, u: undefined)
\r
21 ** st = stereo (y = yes)
\r
22 ** sz = total # bits
\r
23 ** r = # bits of red
\r
24 ** g = # bits of green
\r
25 ** b = # bits of blue
\r
26 ** a = # bits of alpha
\r
27 ** axbf = # aux buffers
\r
28 ** dpth = # bits of depth
\r
29 ** stcl = # bits of stencil
\r
35 #include <GL/glew.h>
\r
37 #include <GL/wglew.h>
\r
38 #elif defined(__APPLE__) && !defined(GLEW_APPLE_GLX)
\r
39 #include <AGL/agl.h>
\r
41 #include <GL/glxew.h>
\r
45 GLEWContext _glewctx;
\r
46 # define glewGetContext() (&_glewctx)
\r
48 WGLEWContext _wglewctx;
\r
49 # define wglewGetContext() (&_wglewctx)
\r
50 # elif !defined(__APPLE__) || defined(GLEW_APPLE_GLX)
\r
51 GLXEWContext _glxewctx;
\r
52 # define glxewGetContext() (&_glxewctx)
\r
54 #endif /* GLEW_MX */
\r
56 typedef struct GLContextStruct
\r
62 #elif defined(__APPLE__) && !defined(GLEW_APPLE_GLX)
\r
63 AGLContext ctx, octx;
\r
73 void InitContext (GLContext* ctx);
\r
74 GLboolean CreateContext (GLContext* ctx);
\r
75 void DestroyContext (GLContext* ctx);
\r
76 void VisualInfo (GLContext* ctx);
\r
77 void PrintExtensions (const char* s);
\r
78 GLboolean ParseArgs (int argc, char** argv);
\r
81 int displaystdout = 0;
\r
83 int drawableonly = 0;
\r
85 char* display = NULL;
\r
92 main (int argc, char** argv)
\r
96 /* ---------------------------------------------------------------------- */
\r
97 /* parse arguments */
\r
98 if (GL_TRUE == ParseArgs(argc-1, argv+1))
\r
100 #if defined(_WIN32)
\r
101 fprintf(stderr, "Usage: visualinfo [-a] [-s] [-h] [-pf <id>]\n");
\r
102 fprintf(stderr, " -a: show all visuals\n");
\r
103 fprintf(stderr, " -s: display to stdout instead of visualinfo.txt\n");
\r
104 fprintf(stderr, " -pf <id>: use given pixelformat\n");
\r
105 fprintf(stderr, " -h: this screen\n");
\r
107 fprintf(stderr, "Usage: visualinfo [-h] [-display <display>] [-visual <id>]\n");
\r
108 fprintf(stderr, " -h: this screen\n");
\r
109 fprintf(stderr, " -display <display>: use given display\n");
\r
110 fprintf(stderr, " -visual <id>: use given visual\n");
\r
115 /* ---------------------------------------------------------------------- */
\r
116 /* create OpenGL rendering context */
\r
118 if (GL_TRUE == CreateContext(&ctx))
\r
120 fprintf(stderr, "Error: CreateContext failed\n");
\r
121 DestroyContext(&ctx);
\r
125 /* ---------------------------------------------------------------------- */
\r
126 /* initialize GLEW */
\r
127 glewExperimental = GL_TRUE;
\r
129 err = glewContextInit(glewGetContext());
\r
131 err = err || wglewContextInit(wglewGetContext());
\r
132 # elif !defined(__APPLE__) || defined(GLEW_APPLE_GLX)
\r
133 err = err || glxewContextInit(glxewGetContext());
\r
138 if (GLEW_OK != err)
\r
140 fprintf(stderr, "Error [main]: glewInit failed: %s\n", glewGetErrorString(err));
\r
141 DestroyContext(&ctx);
\r
145 /* ---------------------------------------------------------------------- */
\r
147 #if defined(_WIN32)
\r
148 if (!displaystdout)
\r
149 file = fopen("visualinfo.txt", "w");
\r
156 /* ---------------------------------------------------------------------- */
\r
157 /* output header information */
\r
158 /* OpenGL extensions */
\r
159 fprintf(file, "OpenGL vendor string: %s\n", glGetString(GL_VENDOR));
\r
160 fprintf(file, "OpenGL renderer string: %s\n", glGetString(GL_RENDERER));
\r
161 fprintf(file, "OpenGL version string: %s\n", glGetString(GL_VERSION));
\r
162 fprintf(file, "OpenGL extensions (GL_): \n");
\r
163 PrintExtensions((char*)glGetString(GL_EXTENSIONS));
\r
164 /* GLU extensions */
\r
165 fprintf(file, "GLU version string: %s\n", gluGetString(GLU_VERSION));
\r
166 fprintf(file, "GLU extensions (GLU_): \n");
\r
167 PrintExtensions((char*)gluGetString(GLU_EXTENSIONS));
\r
169 /* ---------------------------------------------------------------------- */
\r
170 /* extensions string */
\r
171 #if defined(_WIN32)
\r
172 /* WGL extensions */
\r
173 if (WGLEW_ARB_extensions_string || WGLEW_EXT_extensions_string)
\r
175 fprintf(file, "WGL extensions (WGL_): \n");
\r
176 PrintExtensions(wglGetExtensionsStringARB ?
\r
177 (char*)wglGetExtensionsStringARB(ctx.dc) :
\r
178 (char*)wglGetExtensionsStringEXT());
\r
180 #elif defined(__APPLE__) && !defined(GLEW_APPLE_GLX)
\r
183 /* GLX extensions */
\r
184 fprintf(file, "GLX extensions (GLX_): \n");
\r
185 PrintExtensions(glXQueryExtensionsString(glXGetCurrentDisplay(),
\r
186 DefaultScreen(glXGetCurrentDisplay())));
\r
189 /* ---------------------------------------------------------------------- */
\r
190 /* enumerate all the formats */
\r
193 /* ---------------------------------------------------------------------- */
\r
194 /* release resources */
\r
195 DestroyContext(&ctx);
\r
196 if (file != stdout)
\r
201 /* do the magic to separate all extensions with comma's, except
\r
202 for the last one that _may_ terminate in a space. */
\r
203 void PrintExtensions (const char* s)
\r
215 if (*(s+1) != '\0') {
\r
220 else /* zoinks! last one terminated in a space! */
\r
228 fprintf(file, " %s\n", t);
\r
230 i = (int)strlen(p);
\r
236 fprintf(file, " %s.\n", t);
\r
239 /* ---------------------------------------------------------------------- */
\r
241 #if defined(_WIN32)
\r
244 VisualInfoARB (GLContext* ctx)
\r
246 int attrib[32], value[32], n_attrib, n_pbuffer=0, n_float=0;
\r
250 /* to get pbuffer capable pixel formats */
\r
251 attrib[0] = WGL_DRAW_TO_PBUFFER_ARB;
\r
252 attrib[1] = GL_TRUE;
\r
254 wglChoosePixelFormatARB(ctx->dc, attrib, 0, 1, &pf, &c);
\r
255 /* query number of pixel formats */
\r
256 attrib[0] = WGL_NUMBER_PIXEL_FORMATS_ARB;
\r
257 wglGetPixelFormatAttribivARB(ctx->dc, 0, 0, 1, attrib, value);
\r
259 for (i=0; i<32; i++)
\r
262 attrib[0] = WGL_SUPPORT_OPENGL_ARB;
\r
263 attrib[1] = WGL_DRAW_TO_WINDOW_ARB;
\r
264 attrib[2] = WGL_DRAW_TO_BITMAP_ARB;
\r
265 attrib[3] = WGL_ACCELERATION_ARB;
\r
266 /* WGL_NO_ACCELERATION_ARB, WGL_GENERIC_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB */
\r
267 attrib[4] = WGL_SWAP_METHOD_ARB;
\r
268 /* WGL_SWAP_EXCHANGE_ARB, WGL_SWAP_COPY_ARB, WGL_SWAP_UNDEFINED_ARB */
\r
269 attrib[5] = WGL_DOUBLE_BUFFER_ARB;
\r
270 attrib[6] = WGL_STEREO_ARB;
\r
271 attrib[7] = WGL_PIXEL_TYPE_ARB;
\r
272 /* WGL_TYPE_RGBA_ARB, WGL_TYPE_COLORINDEX_ARB,
\r
273 WGL_TYPE_RGBA_FLOAT_ATI (WGL_ATI_pixel_format_float) */
\r
274 /* Color buffer information */
\r
275 attrib[8] = WGL_COLOR_BITS_ARB;
\r
276 attrib[9] = WGL_RED_BITS_ARB;
\r
277 attrib[10] = WGL_GREEN_BITS_ARB;
\r
278 attrib[11] = WGL_BLUE_BITS_ARB;
\r
279 attrib[12] = WGL_ALPHA_BITS_ARB;
\r
280 /* Accumulation buffer information */
\r
281 attrib[13] = WGL_ACCUM_BITS_ARB;
\r
282 attrib[14] = WGL_ACCUM_RED_BITS_ARB;
\r
283 attrib[15] = WGL_ACCUM_GREEN_BITS_ARB;
\r
284 attrib[16] = WGL_ACCUM_BLUE_BITS_ARB;
\r
285 attrib[17] = WGL_ACCUM_ALPHA_BITS_ARB;
\r
286 /* Depth, stencil, and aux buffer information */
\r
287 attrib[18] = WGL_DEPTH_BITS_ARB;
\r
288 attrib[19] = WGL_STENCIL_BITS_ARB;
\r
289 attrib[20] = WGL_AUX_BUFFERS_ARB;
\r
290 /* Layer information */
\r
291 attrib[21] = WGL_NUMBER_OVERLAYS_ARB;
\r
292 attrib[22] = WGL_NUMBER_UNDERLAYS_ARB;
\r
293 attrib[23] = WGL_SWAP_LAYER_BUFFERS_ARB;
\r
294 attrib[24] = WGL_SAMPLES_ARB;
\r
295 attrib[25] = WGL_SUPPORT_GDI_ARB;
\r
297 if (WGLEW_ARB_pbuffer)
\r
299 attrib[n_attrib] = WGL_DRAW_TO_PBUFFER_ARB;
\r
300 n_pbuffer = n_attrib;
\r
303 if (WGLEW_NV_float_buffer)
\r
305 attrib[n_attrib] = WGL_FLOAT_COMPONENTS_NV;
\r
306 n_float = n_attrib;
\r
312 /* print table header */
\r
313 fprintf(file, " +-----+-------------------------+-----------------+----------+-----------------+----------+\n");
\r
314 fprintf(file, " | | visual | color | ax dp st | accum | layer |\n");
\r
315 fprintf(file, " | id | tp ac gd fm db sw st ms | sz r g b a | bf th cl | sz r g b a | ov un sw |\n");
\r
316 fprintf(file, " +-----+-------------------------+-----------------+----------+-----------------+----------+\n");
\r
317 /* loop through all the pixel formats */
\r
318 for(i = 1; i <= maxpf; i++)
\r
320 wglGetPixelFormatAttribivARB(ctx->dc, i, 0, n_attrib, attrib, value);
\r
321 /* only describe this format if it supports OpenGL */
\r
322 if (!value[0]) continue;
\r
323 /* by default show only fully accelerated window or pbuffer capable visuals */
\r
325 && ((value[2] && !value[1])
\r
326 || (!WGLEW_ARB_pbuffer || !value[n_pbuffer])
\r
327 || (value[3] != WGL_FULL_ACCELERATION_ARB))) continue;
\r
328 /* print out the information for this visual */
\r
330 fprintf(file, " |% 4d | ", i);
\r
334 if (WGLEW_ARB_pbuffer && value[n_pbuffer]) fprintf(file, "wp ");
\r
335 else fprintf(file, "wn ");
\r
339 if (value[2]) fprintf(file, "bm ");
\r
340 else if (WGLEW_ARB_pbuffer && value[n_pbuffer]) fprintf(file, "pb ");
\r
343 fprintf(file, "%s ", value[3] == WGL_FULL_ACCELERATION_ARB ? "fu" :
\r
344 value[3] == WGL_GENERIC_ACCELERATION_ARB ? "ge" :
\r
345 value[3] == WGL_NO_ACCELERATION_ARB ? "no" : ". ");
\r
347 fprintf(file, " %c ", value[25] ? 'y' : '.');
\r
349 if (WGLEW_NV_float_buffer && value[n_float]) fprintf(file, " f ");
\r
350 else if (WGLEW_ATI_pixel_format_float && value[7] == WGL_TYPE_RGBA_FLOAT_ATI) fprintf(file, " f ");
\r
351 else if (value[7] == WGL_TYPE_RGBA_ARB) fprintf(file, " i ");
\r
352 else if (value[7] == WGL_TYPE_COLORINDEX_ARB) fprintf(file, " c ");
\r
353 /* double buffer */
\r
354 fprintf(file, " %c ", value[5] ? 'y' : '.');
\r
356 if (value[4] == WGL_SWAP_EXCHANGE_ARB) fprintf(file, " x ");
\r
357 else if (value[4] == WGL_SWAP_COPY_ARB) fprintf(file, " c ");
\r
358 else if (value[4] == WGL_SWAP_UNDEFINED_ARB) fprintf(file, " . ");
\r
359 else fprintf(file, " . ");
\r
361 fprintf(file, " %c ", value[6] ? 'y' : '.');
\r
364 fprintf(file, "%2d | ", value[24]);
\r
366 fprintf(file, " . | ");
\r
368 if (value[8]) fprintf(file, "%3d ", value[8]);
\r
369 else fprintf(file, " . ");
\r
371 if (value[9]) fprintf(file, "%2d ", value[9]);
\r
372 else fprintf(file, " . ");
\r
374 if (value[10]) fprintf(file, "%2d ", value[10]);
\r
375 else fprintf(file, " . ");
\r
377 if (value[11]) fprintf(file, "%2d ", value[11]);
\r
378 else fprintf(file, " . ");
\r
380 if (value[12]) fprintf(file, "%2d | ", value[12]);
\r
381 else fprintf(file, " . | ");
\r
383 if (value[20]) fprintf(file, "%2d ", value[20]);
\r
384 else fprintf(file, " . ");
\r
386 if (value[18]) fprintf(file, "%2d ", value[18]);
\r
387 else fprintf(file, " . ");
\r
389 if (value[19]) fprintf(file, "%2d | ", value[19]);
\r
390 else fprintf(file, " . | ");
\r
392 if (value[13]) fprintf(file, "%3d ", value[13]);
\r
393 else fprintf(file, " . ");
\r
395 if (value[14]) fprintf(file, "%2d ", value[14]);
\r
396 else fprintf(file, " . ");
\r
398 if (value[15]) fprintf(file, "%2d ", value[15]);
\r
399 else fprintf(file, " . ");
\r
401 if (value[16]) fprintf(file, "%2d ", value[16]);
\r
402 else fprintf(file, " . ");
\r
404 if (value[17]) fprintf(file, "%2d | ", value[17]);
\r
405 else fprintf(file, " . | ");
\r
407 if (value[21]) fprintf(file, "%2d ", value[21]);
\r
408 else fprintf(file, " . ");
\r
410 if (value[22]) fprintf(file, "%2d ", value[22]);
\r
411 else fprintf(file, " . ");
\r
413 if (value[23]) fprintf(file, "y ");
\r
414 else fprintf(file, " . ");
\r
415 fprintf(file, "|\n");
\r
417 /* print table footer */
\r
418 fprintf(file, " +-----+-------------------------+-----------------+----------+-----------------+----------+\n");
\r
419 fprintf(file, " | | visual | color | ax dp st | accum | layer |\n");
\r
420 fprintf(file, " | id | tp ac gd fm db sw st ms | sz r g b a | bf th cl | sz r g b a | ov un sw |\n");
\r
421 fprintf(file, " +-----+-------------------------+-----------------+----------+-----------------+----------+\n");
\r
426 fprintf(file, "\n");
\r
427 /* loop through all the pixel formats */
\r
428 for(i = 1; i <= maxpf; i++)
\r
430 DescribePixelFormat(ctx->dc, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
\r
431 /* only describe this format if it supports OpenGL */
\r
432 if(!(pfd.dwFlags & PFD_SUPPORT_OPENGL)
\r
433 || (drawableonly && !(pfd.dwFlags & PFD_DRAW_TO_WINDOW))) continue;
\r
434 fprintf(file, "Visual ID: %2d depth=%d class=%s\n", i, pfd.cDepthBits,
\r
435 pfd.cColorBits <= 8 ? "PseudoColor" : "TrueColor");
\r
436 fprintf(file, " bufferSize=%d level=%d renderType=%s doubleBuffer=%d stereo=%d\n", pfd.cColorBits, pfd.bReserved, pfd.iPixelType == PFD_TYPE_RGBA ? "rgba" : "ci", pfd.dwFlags & PFD_DOUBLEBUFFER, pfd.dwFlags & PFD_STEREO);
\r
437 fprintf(file, " generic=%d generic accelerated=%d\n", (pfd.dwFlags & PFD_GENERIC_FORMAT) == PFD_GENERIC_FORMAT, (pfd.dwFlags & PFD_GENERIC_ACCELERATED) == PFD_GENERIC_ACCELERATED);
\r
438 fprintf(file, " rgba: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n", pfd.cRedBits, pfd.cGreenBits, pfd.cBlueBits, pfd.cAlphaBits);
\r
439 fprintf(file, " auxBuffers=%d depthSize=%d stencilSize=%d\n", pfd.cAuxBuffers, pfd.cDepthBits, pfd.cStencilBits);
\r
440 fprintf(file, " accum: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n", pfd.cAccumRedBits, pfd.cAccumGreenBits, pfd.cAccumBlueBits, pfd.cAccumAlphaBits);
\r
441 fprintf(file, " multiSample=%d multisampleBuffers=%d\n", 0, 0);
\r
442 fprintf(file, " Opaque.\n");
\r
449 VisualInfoGDI (GLContext* ctx)
\r
452 PIXELFORMATDESCRIPTOR pfd;
\r
454 /* calling DescribePixelFormat() with NULL pfd (!!!) return maximum
\r
455 number of pixel formats */
\r
456 maxpf = DescribePixelFormat(ctx->dc, 1, 0, NULL);
\r
460 fprintf(file, "-----------------------------------------------------------------------------\n");
\r
461 fprintf(file, " visual x bf lv rg d st ge ge r g b a ax dp st accum buffs ms \n");
\r
462 fprintf(file, " id dep tp sp sz l ci b ro ne ac sz sz sz sz bf th cl sz r g b a ns b\n");
\r
463 fprintf(file, "-----------------------------------------------------------------------------\n");
\r
465 /* loop through all the pixel formats */
\r
466 for(i = 1; i <= maxpf; i++)
\r
468 DescribePixelFormat(ctx->dc, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
\r
469 /* only describe this format if it supports OpenGL */
\r
470 if(!(pfd.dwFlags & PFD_SUPPORT_OPENGL)
\r
471 || (drawableonly && (pfd.dwFlags & PFD_DRAW_TO_BITMAP))) continue;
\r
472 /* other criteria could be tested here for actual pixel format
\r
473 choosing in an application:
\r
475 for (...each pixel format...) {
\r
476 if (pfd.dwFlags & PFD_SUPPORT_OPENGL &&
\r
477 pfd.dwFlags & PFD_DOUBLEBUFFER &&
\r
478 pfd.cDepthBits >= 24 &&
\r
479 pfd.cColorBits >= 24)
\r
484 ... not found so exit ...
\r
486 ... found so use it ...
\r
488 /* print out the information for this pixel format */
\r
489 fprintf(file, "0x%02x ", i);
\r
490 fprintf(file, "%3d ", pfd.cColorBits);
\r
491 if(pfd.dwFlags & PFD_DRAW_TO_WINDOW) fprintf(file, "wn ");
\r
492 else if(pfd.dwFlags & PFD_DRAW_TO_BITMAP) fprintf(file, "bm ");
\r
493 else fprintf(file, "pb ");
\r
494 /* should find transparent pixel from LAYERPLANEDESCRIPTOR */
\r
495 fprintf(file, " . ");
\r
496 fprintf(file, "%3d ", pfd.cColorBits);
\r
497 /* bReserved field indicates number of over/underlays */
\r
498 if(pfd.bReserved) fprintf(file, " %d ", pfd.bReserved);
\r
499 else fprintf(file, " . ");
\r
500 fprintf(file, " %c ", pfd.iPixelType == PFD_TYPE_RGBA ? 'r' : 'c');
\r
501 fprintf(file, "%c ", pfd.dwFlags & PFD_DOUBLEBUFFER ? 'y' : '.');
\r
502 fprintf(file, " %c ", pfd.dwFlags & PFD_STEREO ? 'y' : '.');
\r
504 fprintf(file, " %c ", pfd.dwFlags & PFD_GENERIC_FORMAT ? 'y' : '.');
\r
505 fprintf(file, " %c ", pfd.dwFlags & PFD_GENERIC_ACCELERATED ? 'y' : '.');
\r
506 if(pfd.cRedBits && pfd.iPixelType == PFD_TYPE_RGBA)
\r
507 fprintf(file, "%2d ", pfd.cRedBits);
\r
508 else fprintf(file, " . ");
\r
509 if(pfd.cGreenBits && pfd.iPixelType == PFD_TYPE_RGBA)
\r
510 fprintf(file, "%2d ", pfd.cGreenBits);
\r
511 else fprintf(file, " . ");
\r
512 if(pfd.cBlueBits && pfd.iPixelType == PFD_TYPE_RGBA)
\r
513 fprintf(file, "%2d ", pfd.cBlueBits);
\r
514 else fprintf(file, " . ");
\r
515 if(pfd.cAlphaBits && pfd.iPixelType == PFD_TYPE_RGBA)
\r
516 fprintf(file, "%2d ", pfd.cAlphaBits);
\r
517 else fprintf(file, " . ");
\r
518 if(pfd.cAuxBuffers) fprintf(file, "%2d ", pfd.cAuxBuffers);
\r
519 else fprintf(file, " . ");
\r
520 if(pfd.cDepthBits) fprintf(file, "%2d ", pfd.cDepthBits);
\r
521 else fprintf(file, " . ");
\r
522 if(pfd.cStencilBits) fprintf(file, "%2d ", pfd.cStencilBits);
\r
523 else fprintf(file, " . ");
\r
524 if(pfd.cAccumBits) fprintf(file, "%3d ", pfd.cAccumBits);
\r
525 else fprintf(file, " . ");
\r
526 if(pfd.cAccumRedBits) fprintf(file, "%2d ", pfd.cAccumRedBits);
\r
527 else fprintf(file, " . ");
\r
528 if(pfd.cAccumGreenBits) fprintf(file, "%2d ", pfd.cAccumGreenBits);
\r
529 else fprintf(file, " . ");
\r
530 if(pfd.cAccumBlueBits) fprintf(file, "%2d ", pfd.cAccumBlueBits);
\r
531 else fprintf(file, " . ");
\r
532 if(pfd.cAccumAlphaBits) fprintf(file, "%2d ", pfd.cAccumAlphaBits);
\r
533 else fprintf(file, " . ");
\r
534 /* no multisample in win32 */
\r
535 fprintf(file, " . .\n");
\r
537 /* print table footer */
\r
538 fprintf(file, "-----------------------------------------------------------------------------\n");
\r
539 fprintf(file, " visual x bf lv rg d st ge ge r g b a ax dp st accum buffs ms \n");
\r
540 fprintf(file, " id dep tp sp sz l ci b ro ne ac sz sz sz sz bf th cl sz r g b a ns b\n");
\r
541 fprintf(file, "-----------------------------------------------------------------------------\n");
\r
545 fprintf(file, "\n");
\r
546 /* loop through all the pixel formats */
\r
547 for(i = 1; i <= maxpf; i++)
\r
549 DescribePixelFormat(ctx->dc, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
\r
550 /* only describe this format if it supports OpenGL */
\r
551 if(!(pfd.dwFlags & PFD_SUPPORT_OPENGL)
\r
552 || (drawableonly && !(pfd.dwFlags & PFD_DRAW_TO_WINDOW))) continue;
\r
553 fprintf(file, "Visual ID: %2d depth=%d class=%s\n", i, pfd.cDepthBits,
\r
554 pfd.cColorBits <= 8 ? "PseudoColor" : "TrueColor");
\r
555 fprintf(file, " bufferSize=%d level=%d renderType=%s doubleBuffer=%ld stereo=%ld\n", pfd.cColorBits, pfd.bReserved, pfd.iPixelType == PFD_TYPE_RGBA ? "rgba" : "ci", pfd.dwFlags & PFD_DOUBLEBUFFER, pfd.dwFlags & PFD_STEREO);
\r
556 fprintf(file, " generic=%d generic accelerated=%d\n", (pfd.dwFlags & PFD_GENERIC_FORMAT) == PFD_GENERIC_FORMAT, (pfd.dwFlags & PFD_GENERIC_ACCELERATED) == PFD_GENERIC_ACCELERATED);
\r
557 fprintf(file, " rgba: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n", pfd.cRedBits, pfd.cGreenBits, pfd.cBlueBits, pfd.cAlphaBits);
\r
558 fprintf(file, " auxBuffers=%d depthSize=%d stencilSize=%d\n", pfd.cAuxBuffers, pfd.cDepthBits, pfd.cStencilBits);
\r
559 fprintf(file, " accum: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n", pfd.cAccumRedBits, pfd.cAccumGreenBits, pfd.cAccumBlueBits, pfd.cAccumAlphaBits);
\r
560 fprintf(file, " multiSample=%d multisampleBuffers=%d\n", 0, 0);
\r
561 fprintf(file, " Opaque.\n");
\r
567 VisualInfo (GLContext* ctx)
\r
569 if (WGLEW_ARB_pixel_format)
\r
570 VisualInfoARB(ctx);
\r
572 VisualInfoGDI(ctx);
\r
575 /* ---------------------------------------------------------------------- */
\r
577 #elif defined(__APPLE__) && !defined(GLEW_APPLE_GLX)
\r
580 VisualInfo (GLContext* ctx)
\r
583 int attrib[] = { AGL_RGBA, AGL_NONE };
\r
586 pf = aglChoosePixelFormat(NULL, 0, attrib);
\r
589 aglDescribePixelFormat(pf, GL_RGBA, &value);
\r
590 fprintf(stderr, "%d\n", value);
\r
591 pf = aglNextPixelFormat(pf);
\r
599 VisualInfo (GLContext* ctx)
\r
605 fbc = glXGetFBConfigs(ctx->dpy, DefaultScreen(ctx->dpy), &n_fbc);
\r
611 /* print table header */
\r
612 fprintf(file, " +-----+-------------------------+-----------------+----------+-------------+-------+------+\n");
\r
613 fprintf(file, " | | visual | color | ax dp st | accum | ms | cav |\n");
\r
614 fprintf(file, " | id | tp xr cl fm db st lv xp | sz r g b a | bf th cl | r g b a | ns b | eat |\n");
\r
615 fprintf(file, " +-----+-------------------------+-----------------+----------+-------------+-------+------+\n");
\r
616 /* loop through all the fbcs */
\r
617 for (i=0; i<n_fbc; i++)
\r
619 /* print out the information for this fbc */
\r
621 ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_FBCONFIG_ID, &value);
\r
622 if (ret != Success)
\r
624 fprintf(file, "| ? |");
\r
628 fprintf(file, " |% 4d | ", value);
\r
631 ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_DRAWABLE_TYPE, &value);
\r
632 if (ret != Success)
\r
634 fprintf(file, " ? ");
\r
638 if (value & GLX_WINDOW_BIT)
\r
640 if (value & GLX_PBUFFER_BIT)
\r
642 fprintf(file, "wp ");
\r
646 fprintf(file, "wn ");
\r
651 if (value & GLX_PBUFFER_BIT)
\r
653 fprintf(file, "pb ");
\r
655 else if (value & GLX_PIXMAP_BIT)
\r
657 fprintf(file, "pm ");
\r
661 fprintf(file, " ? ");
\r
666 ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_X_RENDERABLE, &value);
\r
667 if (ret != Success)
\r
669 fprintf(file, " ? ");
\r
673 fprintf(file, value ? " y " : " n ");
\r
676 ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_X_VISUAL_TYPE, &value);
\r
677 if (ret != Success)
\r
679 fprintf(file, " ? ");
\r
683 if (GLX_TRUE_COLOR == value)
\r
684 fprintf(file, "tc ");
\r
685 else if (GLX_DIRECT_COLOR == value)
\r
686 fprintf(file, "dc ");
\r
687 else if (GLX_PSEUDO_COLOR == value)
\r
688 fprintf(file, "pc ");
\r
689 else if (GLX_STATIC_COLOR == value)
\r
690 fprintf(file, "sc ");
\r
691 else if (GLX_GRAY_SCALE == value)
\r
692 fprintf(file, "gs ");
\r
693 else if (GLX_STATIC_GRAY == value)
\r
694 fprintf(file, "sg ");
\r
695 else if (GLX_X_VISUAL_TYPE == value)
\r
696 fprintf(file, " . ");
\r
698 fprintf(file, " ? ");
\r
701 ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_RENDER_TYPE, &value);
\r
702 if (ret != Success)
\r
704 fprintf(file, " ? ");
\r
708 if (GLXEW_NV_float_buffer)
\r
711 ret2 = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_FLOAT_COMPONENTS_NV, &value2);
\r
712 if (Success == ret2 && GL_TRUE == value2)
\r
714 fprintf(file, " f ");
\r
716 else if (value & GLX_RGBA_BIT)
\r
717 fprintf(file, " i ");
\r
718 else if (value & GLX_COLOR_INDEX_BIT)
\r
719 fprintf(file, " c ");
\r
721 fprintf(file, " ? ");
\r
725 if (value & GLX_RGBA_FLOAT_ATI_BIT)
\r
726 fprintf(file, " f ");
\r
727 else if (value & GLX_RGBA_BIT)
\r
728 fprintf(file, " i ");
\r
729 else if (value & GLX_COLOR_INDEX_BIT)
\r
730 fprintf(file, " c ");
\r
732 fprintf(file, " ? ");
\r
735 /* double buffer */
\r
736 ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_DOUBLEBUFFER, &value);
\r
737 fprintf(file, " %c ", Success != ret ? '?' : (value ? 'y' : '.'));
\r
739 ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_STEREO, &value);
\r
740 fprintf(file, " %c ", Success != ret ? '?' : (value ? 'y' : '.'));
\r
742 ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_LEVEL, &value);
\r
743 if (Success != ret)
\r
745 fprintf(file, " ? ");
\r
749 fprintf(file, "%2d ", value);
\r
752 ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_TRANSPARENT_TYPE, &value);
\r
753 if (Success != ret)
\r
755 fprintf(file, " ? | ");
\r
759 if (GLX_TRANSPARENT_RGB == value)
\r
760 fprintf(file, " r | ");
\r
761 else if (GLX_TRANSPARENT_INDEX == value)
\r
762 fprintf(file, " i | ");
\r
763 else if (GLX_NONE == value)
\r
764 fprintf(file, " . | ");
\r
766 fprintf(file, " ? | ");
\r
769 ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_BUFFER_SIZE, &value);
\r
770 if (Success != ret)
\r
772 fprintf(file, " ? ");
\r
777 fprintf(file, "%3d ", value);
\r
779 fprintf(file, " . ");
\r
782 ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_RED_SIZE, &value);
\r
783 if (Success != ret)
\r
785 fprintf(file, " ? ");
\r
790 fprintf(file, "%2d ", value);
\r
792 fprintf(file, " . ");
\r
795 ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_GREEN_SIZE, &value);
\r
796 if (Success != ret)
\r
798 fprintf(file, " ? ");
\r
803 fprintf(file, "%2d ", value);
\r
805 fprintf(file, " . ");
\r
808 ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_BLUE_SIZE, &value);
\r
809 if (Success != ret)
\r
811 fprintf(file, " ? ");
\r
816 fprintf(file, "%2d ", value);
\r
818 fprintf(file, " . ");
\r
821 ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_ALPHA_SIZE, &value);
\r
822 if (Success != ret)
\r
824 fprintf(file, " ? | ");
\r
829 fprintf(file, "%2d | ", value);
\r
831 fprintf(file, " . | ");
\r
834 ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_AUX_BUFFERS, &value);
\r
835 if (Success != ret)
\r
837 fprintf(file, " ? ");
\r
842 fprintf(file, "%2d ", value);
\r
844 fprintf(file, " . ");
\r
847 ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_DEPTH_SIZE, &value);
\r
848 if (Success != ret)
\r
850 fprintf(file, " ? ");
\r
855 fprintf(file, "%2d ", value);
\r
857 fprintf(file, " . ");
\r
860 ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_STENCIL_SIZE, &value);
\r
861 if (Success != ret)
\r
863 fprintf(file, " ? | ");
\r
868 fprintf(file, "%2d | ", value);
\r
870 fprintf(file, " . | ");
\r
872 /* accum red size */
\r
873 ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_ACCUM_RED_SIZE, &value);
\r
874 if (Success != ret)
\r
876 fprintf(file, " ? ");
\r
881 fprintf(file, "%2d ", value);
\r
883 fprintf(file, " . ");
\r
885 /* accum green size */
\r
886 ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_ACCUM_GREEN_SIZE, &value);
\r
887 if (Success != ret)
\r
889 fprintf(file, " ? ");
\r
894 fprintf(file, "%2d ", value);
\r
896 fprintf(file, " . ");
\r
898 /* accum blue size */
\r
899 ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_ACCUM_BLUE_SIZE, &value);
\r
900 if (Success != ret)
\r
902 fprintf(file, " ? ");
\r
907 fprintf(file, "%2d ", value);
\r
909 fprintf(file, " . ");
\r
911 /* accum alpha size */
\r
912 ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_ACCUM_ALPHA_SIZE, &value);
\r
913 if (Success != ret)
\r
915 fprintf(file, " ? | ");
\r
920 fprintf(file, "%2d | ", value);
\r
922 fprintf(file, " . | ");
\r
925 ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_SAMPLES, &value);
\r
926 if (Success != ret)
\r
928 fprintf(file, " ? ");
\r
932 fprintf(file, "%2d ", value);
\r
934 ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_SAMPLE_BUFFERS, &value);
\r
935 if (Success != ret)
\r
937 fprintf(file, " ? | ");
\r
941 fprintf(file, "%2d | ", value);
\r
944 ret = glXGetFBConfigAttrib(ctx->dpy, fbc[i], GLX_CONFIG_CAVEAT, &value);
\r
945 if (Success != ret)
\r
947 fprintf(file, "???? |");
\r
951 if (GLX_NONE == value)
\r
952 fprintf(file, "none |\n");
\r
953 else if (GLX_SLOW_CONFIG == value)
\r
954 fprintf(file, "slow |\n");
\r
955 else if (GLX_NON_CONFORMANT_CONFIG == value)
\r
956 fprintf(file, "ncft |\n");
\r
958 fprintf(file, "???? |\n");
\r
961 /* print table footer */
\r
962 fprintf(file, " +-----+-------------------------+-----------------+----------+-------------+-------+------+\n");
\r
963 fprintf(file, " | id | tp xr cl fm db st lv xp | sz r g b a | bf th cl | r g b a | ns b | eat |\n");
\r
964 fprintf(file, " | | visual | color | ax dp st | accum | ms | cav |\n");
\r
965 fprintf(file, " +-----+-------------------------+-----------------+----------+-------------+-------+------+\n");
\r
972 /* ------------------------------------------------------------------------ */
\r
974 #if defined(_WIN32)
\r
976 void InitContext (GLContext* ctx)
\r
983 GLboolean CreateContext (GLContext* ctx)
\r
986 PIXELFORMATDESCRIPTOR pfd;
\r
987 /* check for input */
\r
988 if (NULL == ctx) return GL_TRUE;
\r
989 /* register window class */
\r
990 ZeroMemory(&wc, sizeof(WNDCLASS));
\r
991 wc.hInstance = GetModuleHandle(NULL);
\r
992 wc.lpfnWndProc = DefWindowProc;
\r
993 wc.lpszClassName = "GLEW";
\r
994 if (0 == RegisterClass(&wc)) return GL_TRUE;
\r
995 /* create window */
\r
996 ctx->wnd = CreateWindow("GLEW", "GLEW", 0, CW_USEDEFAULT, CW_USEDEFAULT,
\r
997 CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL,
\r
998 GetModuleHandle(NULL), NULL);
\r
999 if (NULL == ctx->wnd) return GL_TRUE;
\r
1000 /* get the device context */
\r
1001 ctx->dc = GetDC(ctx->wnd);
\r
1002 if (NULL == ctx->dc) return GL_TRUE;
\r
1003 /* find pixel format */
\r
1004 ZeroMemory(&pfd, sizeof(PIXELFORMATDESCRIPTOR));
\r
1005 if (visual == -1) /* find default */
\r
1007 pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
\r
1009 pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
\r
1010 visual = ChoosePixelFormat(ctx->dc, &pfd);
\r
1011 if (0 == visual) return GL_TRUE;
\r
1013 /* set the pixel format for the dc */
\r
1014 if (FALSE == SetPixelFormat(ctx->dc, visual, &pfd)) return GL_TRUE;
\r
1015 /* create rendering context */
\r
1016 ctx->rc = wglCreateContext(ctx->dc);
\r
1017 if (NULL == ctx->rc) return GL_TRUE;
\r
1018 if (FALSE == wglMakeCurrent(ctx->dc, ctx->rc)) return GL_TRUE;
\r
1022 void DestroyContext (GLContext* ctx)
\r
1024 if (NULL == ctx) return;
\r
1025 if (NULL != ctx->rc) wglMakeCurrent(NULL, NULL);
\r
1026 if (NULL != ctx->rc) wglDeleteContext(wglGetCurrentContext());
\r
1027 if (NULL != ctx->wnd && NULL != ctx->dc) ReleaseDC(ctx->wnd, ctx->dc);
\r
1028 if (NULL != ctx->wnd) DestroyWindow(ctx->wnd);
\r
1029 UnregisterClass("GLEW", GetModuleHandle(NULL));
\r
1032 /* ------------------------------------------------------------------------ */
\r
1034 #elif defined(__APPLE__) && !defined(GLEW_APPLE_GLX)
\r
1036 void InitContext (GLContext* ctx)
\r
1042 GLboolean CreateContext (GLContext* ctx)
\r
1044 int attrib[] = { AGL_RGBA, AGL_NONE };
\r
1045 AGLPixelFormat pf;
\r
1047 if (NULL == ctx) return GL_TRUE;
\r
1048 /*int major, minor;
\r
1049 SetPortWindowPort(wnd);
\r
1050 aglGetVersion(&major, &minor);
\r
1051 fprintf(stderr, "GL %d.%d\n", major, minor);*/
\r
1052 pf = aglChoosePixelFormat(NULL, 0, attrib);
\r
1053 if (NULL == pf) return GL_TRUE;
\r
1054 ctx->ctx = aglCreateContext(pf, NULL);
\r
1055 if (NULL == ctx->ctx || AGL_NO_ERROR != aglGetError()) return GL_TRUE;
\r
1056 aglDestroyPixelFormat(pf);
\r
1057 /*aglSetDrawable(ctx, GetWindowPort(wnd));*/
\r
1058 ctx->octx = aglGetCurrentContext();
\r
1059 if (NULL == aglSetCurrentContext(ctx->ctx)) return GL_TRUE;
\r
1063 void DestroyContext (GLContext* ctx)
\r
1065 if (NULL == ctx) return;
\r
1066 aglSetCurrentContext(ctx->octx);
\r
1067 if (NULL != ctx->ctx) aglDestroyContext(ctx->ctx);
\r
1070 /* ------------------------------------------------------------------------ */
\r
1072 #else /* __UNIX || (__APPLE__ && GLEW_APPLE_GLX) */
\r
1074 void InitContext (GLContext* ctx)
\r
1083 GLboolean CreateContext (GLContext* ctx)
\r
1085 int attrib[] = { GLX_RGBA, GLX_DOUBLEBUFFER, None };
\r
1087 XSetWindowAttributes swa;
\r
1089 if (NULL == ctx) return GL_TRUE;
\r
1090 /* open display */
\r
1091 ctx->dpy = XOpenDisplay(display);
\r
1092 if (NULL == ctx->dpy) return GL_TRUE;
\r
1093 /* query for glx */
\r
1094 if (!glXQueryExtension(ctx->dpy, &erb, &evb)) return GL_TRUE;
\r
1095 /* choose visual */
\r
1096 ctx->vi = glXChooseVisual(ctx->dpy, DefaultScreen(ctx->dpy), attrib);
\r
1097 if (NULL == ctx->vi) return GL_TRUE;
\r
1098 /* create context */
\r
1099 ctx->ctx = glXCreateContext(ctx->dpy, ctx->vi, None, True);
\r
1100 if (NULL == ctx->ctx) return GL_TRUE;
\r
1101 /* create window */
\r
1102 /*wnd = XCreateSimpleWindow(dpy, RootWindow(dpy, vi->screen), 0, 0, 1, 1, 1, 0, 0);*/
\r
1103 ctx->cmap = XCreateColormap(ctx->dpy, RootWindow(ctx->dpy, ctx->vi->screen),
\r
1104 ctx->vi->visual, AllocNone);
\r
1105 swa.border_pixel = 0;
\r
1106 swa.colormap = ctx->cmap;
\r
1107 ctx->wnd = XCreateWindow(ctx->dpy, RootWindow(ctx->dpy, ctx->vi->screen),
\r
1108 0, 0, 1, 1, 0, ctx->vi->depth, InputOutput, ctx->vi->visual,
\r
1109 CWBorderPixel | CWColormap, &swa);
\r
1110 /* make context current */
\r
1111 if (!glXMakeCurrent(ctx->dpy, ctx->wnd, ctx->ctx)) return GL_TRUE;
\r
1115 void DestroyContext (GLContext* ctx)
\r
1117 if (NULL != ctx->dpy && NULL != ctx->ctx) glXDestroyContext(ctx->dpy, ctx->ctx);
\r
1118 if (NULL != ctx->dpy && 0 != ctx->wnd) XDestroyWindow(ctx->dpy, ctx->wnd);
\r
1119 if (NULL != ctx->dpy && 0 != ctx->cmap) XFreeColormap(ctx->dpy, ctx->cmap);
\r
1120 if (NULL != ctx->vi) XFree(ctx->vi);
\r
1121 if (NULL != ctx->dpy) XCloseDisplay(ctx->dpy);
\r
1124 #endif /* __UNIX || (__APPLE__ && GLEW_APPLE_GLX) */
\r
1126 GLboolean ParseArgs (int argc, char** argv)
\r
1131 #if defined(_WIN32)
\r
1132 if (!strcmp(argv[p], "-pf") || !strcmp(argv[p], "-pixelformat"))
\r
1134 if (++p >= argc) return GL_TRUE;
\r
1136 visual = strtol(argv[p], NULL, 0);
\r
1138 else if (!strcmp(argv[p], "-a"))
\r
1142 else if (!strcmp(argv[p], "-s"))
\r
1144 displaystdout = 1;
\r
1146 else if (!strcmp(argv[p], "-h"))
\r
1153 if (!strcmp(argv[p], "-display"))
\r
1155 if (++p >= argc) return GL_TRUE;
\r
1156 display = argv[p];
\r
1158 else if (!strcmp(argv[p], "-visual"))
\r
1160 if (++p >= argc) return GL_TRUE;
\r
1161 visual = (int)strtol(argv[p], NULL, 0);
\r
1163 else if (!strcmp(argv[p], "-h"))
\r