1 | /****************************************************************************
|
---|
2 | ** $Id: glinfo_win.cpp 160 2006-12-11 20:15:57Z dmik $
|
---|
3 | **
|
---|
4 | ** Copyright (C) 1992-2003 Trolltech AS. All rights reserved.
|
---|
5 | **
|
---|
6 | ** This file is part of an example program for Qt. This example
|
---|
7 | ** program may be used, distributed and modified without limitation.
|
---|
8 | **
|
---|
9 | *****************************************************************************/
|
---|
10 |
|
---|
11 | #if defined(Q_CC_MSVC)
|
---|
12 | #pragma warning(disable:4305) // init: truncation from const double to float
|
---|
13 | #endif
|
---|
14 |
|
---|
15 | #include "glinfo.h"
|
---|
16 | #include <qgl.h>
|
---|
17 | #include <windows.h>
|
---|
18 | #include <GL/gl.h>
|
---|
19 | #include <GL/glu.h>
|
---|
20 |
|
---|
21 | typedef const char * (WINAPI * PFNWGLGETEXTENSIONSSTRINGARBPROC) (HDC hdc);
|
---|
22 |
|
---|
23 | GLInfo::GLInfo()
|
---|
24 | {
|
---|
25 | QGLWidget gl((QGLWidget *) 0);
|
---|
26 | gl.makeCurrent();
|
---|
27 |
|
---|
28 | // get hold of WGL extensions
|
---|
29 | PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB =
|
---|
30 | (PFNWGLGETEXTENSIONSSTRINGARBPROC) wglGetProcAddress( "wglGetExtensionsStringARB" );
|
---|
31 | QString wglExts;
|
---|
32 | if ( wglGetExtensionsStringARB ) {
|
---|
33 | wglExts = (char *) wglGetExtensionsStringARB( wglGetCurrentDC() );
|
---|
34 | wglExts.replace( ' ', '\n' );
|
---|
35 | }
|
---|
36 | infotext.sprintf( "OpenGL vendor string: %s\n", (const char *) glGetString( GL_VENDOR ) );
|
---|
37 | infotext.sprintf( "%sOpenGL renderer string: %s\n", infotext.ascii(), glGetString( GL_RENDERER ) );
|
---|
38 | infotext.sprintf( "%sOpenGL version string: %s\n", infotext.ascii(), glGetString( GL_VERSION ) );
|
---|
39 | infotext.sprintf( "%s\nWGL extensions:\n%s\n", infotext.ascii(),
|
---|
40 | !wglExts.isEmpty() ? wglExts.ascii() : "None\n" );
|
---|
41 | infotext.sprintf( "%sOpenGL extensions:\n", infotext.ascii() );
|
---|
42 | infotext += QString( (char *) glGetString( GL_EXTENSIONS ) ).replace( ' ', '\n' );
|
---|
43 |
|
---|
44 | infotext += "\n PF Color Draw Trans buff lev render DB ste r g b a aux dep ste accum buffers MS MS\n"
|
---|
45 | " id depth to parent size el type reo sz sz sz sz buf th ncl r g b a num bufs\n"
|
---|
46 | "----------------------------------------------------------------------------------------------------\n";
|
---|
47 | HDC dc;
|
---|
48 | dc = GetDC( gl.winId() );
|
---|
49 |
|
---|
50 | QString str;
|
---|
51 | int i, maxpf;
|
---|
52 | PIXELFORMATDESCRIPTOR pfd;
|
---|
53 |
|
---|
54 | /* calling DescribePixelFormat() with NULL args return maximum
|
---|
55 | number of pixel formats */
|
---|
56 | maxpf = DescribePixelFormat( dc, 0, 0, NULL );
|
---|
57 |
|
---|
58 | for(i = 1; i <= maxpf; i++) {
|
---|
59 | str = "";
|
---|
60 | DescribePixelFormat( dc, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd );
|
---|
61 | if ( !(pfd.dwFlags & PFD_SUPPORT_OPENGL) )
|
---|
62 | continue;
|
---|
63 | str.sprintf( "0x%02x %2d ", i, pfd.cColorBits );
|
---|
64 | if( pfd.dwFlags & PFD_DRAW_TO_WINDOW && pfd.dwFlags & PFD_DRAW_TO_BITMAP )
|
---|
65 | str.sprintf( "%swin/bmp ", str.ascii() );
|
---|
66 | else if( pfd.dwFlags & PFD_DRAW_TO_WINDOW )
|
---|
67 | str.sprintf( "%swindow ", str.ascii() );
|
---|
68 | else if( pfd.dwFlags & PFD_DRAW_TO_BITMAP )
|
---|
69 | str.sprintf( "%sbitmap ", str.ascii() );
|
---|
70 | else
|
---|
71 | str.sprintf( "%s. ", str.ascii() );
|
---|
72 |
|
---|
73 | LAYERPLANEDESCRIPTOR lpfd;
|
---|
74 | if ( pfd.bReserved ) {
|
---|
75 | wglDescribeLayerPlane( dc, i, pfd.bReserved,
|
---|
76 | sizeof( LAYERPLANEDESCRIPTOR ), &lpfd );
|
---|
77 | if ( lpfd.dwFlags & LPD_TRANSPARENT && lpfd.iPixelType == PFD_TYPE_RGBA )
|
---|
78 | str.sprintf( "%s%06x %2d ", str.ascii(), lpfd.crTransparent );
|
---|
79 | else
|
---|
80 | str.sprintf( "%s%d %2d ", str.ascii(), lpfd.crTransparent, pfd.cColorBits );
|
---|
81 | } else {
|
---|
82 | str.sprintf( "%s0 %2d ", str.ascii(), pfd.cColorBits );
|
---|
83 | }
|
---|
84 | str.sprintf( "%s%d ", str.ascii(), pfd.bReserved );
|
---|
85 | if ( pfd.bReserved ) {
|
---|
86 | bool mpTypeRgba = pfd.iPixelType == PFD_TYPE_RGBA;
|
---|
87 | bool lpTypeRgba = lpfd.iPixelType == PFD_TYPE_RGBA;
|
---|
88 | QString type;
|
---|
89 | if ( mpTypeRgba && lpTypeRgba )
|
---|
90 | type = "rg/rg ";
|
---|
91 | else if ( mpTypeRgba && !lpTypeRgba )
|
---|
92 | type = "rg/ci ";
|
---|
93 | else if ( !mpTypeRgba && lpTypeRgba )
|
---|
94 | type = "ci/rg ";
|
---|
95 | else
|
---|
96 | type = "ci/ci ";
|
---|
97 | str.sprintf("%s%s ", str.ascii(), type.ascii() );
|
---|
98 | } else {
|
---|
99 | str.sprintf("%s%s", str.ascii(), pfd.iPixelType == PFD_TYPE_RGBA ? "rgba " : "ci " );
|
---|
100 | }
|
---|
101 | str.sprintf( "%s%c %c ", str.ascii(),
|
---|
102 | pfd.dwFlags & PFD_DOUBLEBUFFER ? 'y' : 'n',
|
---|
103 | pfd.dwFlags & PFD_STEREO ? 'y' : 'n' );
|
---|
104 | str.sprintf( "%s%d ", str.ascii(), pfd.cRedBits );
|
---|
105 | str.sprintf( "%s%d ", str.ascii(), pfd.cGreenBits );
|
---|
106 | str.sprintf( "%s%d ", str.ascii(), pfd.cBlueBits );
|
---|
107 | str.sprintf( "%s%d ", str.ascii(), pfd.cAlphaBits );
|
---|
108 | str.sprintf( "%s%d ", str.ascii(), pfd.cAuxBuffers );
|
---|
109 | str.sprintf( "%s%2d ", str.ascii(), pfd.cDepthBits );
|
---|
110 | str.sprintf( "%s%2d ", str.ascii(), pfd.cStencilBits );
|
---|
111 | str.sprintf( "%s%2d ", str.ascii(), pfd.cAccumRedBits );
|
---|
112 | str.sprintf( "%s%2d ", str.ascii(), pfd.cAccumGreenBits );
|
---|
113 | str.sprintf( "%s%2d ", str.ascii(), pfd.cAccumBlueBits );
|
---|
114 | str.sprintf( "%s%2d ", str.ascii(), pfd.cAccumAlphaBits );
|
---|
115 |
|
---|
116 | /* no multisample in Win32 */
|
---|
117 | str.append( "0 0\n" );
|
---|
118 | infotext.append( str );
|
---|
119 | }
|
---|
120 | ReleaseDC( gl.winId(), dc );
|
---|
121 | }
|
---|
122 |
|
---|
123 | QString GLInfo::info()
|
---|
124 | {
|
---|
125 | return infotext;
|
---|
126 | }
|
---|