1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2010 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 // ***************************************************************************
21 // display_dlg.cpp : implementation file
22 // ***************************************************************************
25 #include "client_config.h"
26 #include "display_dlg.h"
30 using namespace NLMISC
;
33 // ***************************************************************************
35 std::vector
<string
> GLExtensions
;
36 std::string GLRenderer
;
38 std::string GLVersion
;
39 std::string D3DDescription
;
40 std::string D3DDeviceName
;
41 std::string D3DDriver
;
42 std::string D3DDriverVersion
;
43 std::string D3DVendor
;
46 uint HardwareSoundBuffer
;
50 bool GetGLInformation ()
54 GLExtensions
.clear ();
61 // Register a window class
63 memset(&wc
,0,sizeof(wc
));
64 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;//| CS_DBLCLKS;
65 wc
.lpfnWndProc
= DefWindowProc
;
68 wc
.hInstance
= GetModuleHandle(NULL
);
69 wc
.hIcon
= (HICON
)NULL
;
70 wc
.hCursor
= LoadCursor(NULL
,IDC_ARROW
);
71 wc
.hbrBackground
= WHITE_BRUSH
;
72 wc
.lpszClassName
= "RyzomGetGlInformation";
73 wc
.lpszMenuName
= NULL
;
74 if ( !RegisterClass(&wc
) )
78 ULONG WndFlags
= WS_OVERLAPPEDWINDOW
+WS_CLIPCHILDREN
+WS_CLIPSIBLINGS
;
84 HWND hWnd
= CreateWindow ( "RyzomGetGlInformation",
87 CW_USEDEFAULT
,CW_USEDEFAULT
,
88 WndRect
.right
,WndRect
.bottom
,
91 GetModuleHandle(NULL
),
96 HDC hDC
= GetDC(hWnd
);
98 // Remove current gl context
99 wglMakeCurrent (hDC
, NULL
);
101 // Select pixel format
102 int depth
= GetDeviceCaps (hDC
, BITSPIXEL
);
103 PIXELFORMATDESCRIPTOR pfd
;
104 memset(&pfd
,0,sizeof(pfd
));
105 pfd
.nSize
= sizeof(pfd
);
107 pfd
.dwFlags
= PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
| PFD_DOUBLEBUFFER
;
108 pfd
.iPixelType
= PFD_TYPE_RGBA
;
109 pfd
.cColorBits
= (char)depth
;
117 pfd
.iLayerType
= PFD_MAIN_PLANE
;
118 int pf
=ChoosePixelFormat(hDC
, &pfd
);
121 if ( !SetPixelFormat(hDC
, pf
, &pfd
) )
124 // Create final context
125 HGLRC hRC
= wglCreateContext (hDC
);
126 wglMakeCurrent(hDC
, hRC
);
128 // *** GET INFORMATION
130 GLVendor
= (const char *) glGetString (GL_VENDOR
);
131 GLRenderer
= (const char *) glGetString (GL_RENDERER
);
132 GLVersion
= (const char *) glGetString (GL_VERSION
);
134 // Get extension string
135 string glext
= (char*)glGetString(GL_EXTENSIONS
);
136 const char *token
= strtok ( (char*)glext
.c_str (), " ");
137 while( token
!= NULL
)
139 GLExtensions
.push_back (token
);
140 token
= strtok( NULL
, " ");
144 typedef const char* (APIENTRY
* PFNWGFGETEXTENSIONSSTRINGARB
) (HDC
);
145 PFNWGFGETEXTENSIONSSTRINGARB wglGetExtensionsStringARB
;
146 if ((wglGetExtensionsStringARB
=(PFNWGFGETEXTENSIONSSTRINGARB
)wglGetProcAddress("wglGetExtensionsStringARB")))
148 // Get extension string
149 glext
= wglGetExtensionsStringARB (hDC
);
150 token
= strtok ( (char*)glext
.c_str (), " ");
151 while( token
!= NULL
)
153 GLExtensions
.push_back (token
);
154 token
= strtok( NULL
, " ");
158 // *** RELEASE OPENGL
161 wglDeleteContext(hRC
);
164 ReleaseDC (hWnd
,hDC
);
165 DestroyWindow (hWnd
);
172 // ***************************************************************************
174 bool GetD3DInformation (NL3D::IDriver
*d3dDriver
)
176 IDriver::CAdapter desc
;
177 if (d3dDriver
->getAdapter (0xffffffff, desc
))
179 D3DDescription
= desc
.Description
;
180 D3DDeviceName
= desc
.DeviceName
;
181 D3DDriver
= desc
.Driver
;
182 D3DDriverVersion
= toString ((uint16
)(desc
.DriverVersion
>>48))+"."+
183 toString ((uint16
)(desc
.DriverVersion
>>32))+"."+
184 toString ((uint16
)(desc
.DriverVersion
>>16))+"."+
185 toString ((uint16
)(desc
.DriverVersion
&0xffff));
186 D3DVendor
= desc
.Vendor
;
192 // ***************************************************************************
194 bool GetVideoMemory ()
199 // Initialise Direct Draw
201 HRESULT result
= DirectDrawCreate(NULL
, &dd
, NULL
);
205 memset (&caps
, 0, sizeof(DDCAPS
));
206 caps
.dwSize
= sizeof(DDCAPS
);
207 dd
->GetCaps (&caps
, NULL
);
208 VideoMemory
= caps
.dwVidMemTotal
;
217 // ***************************************************************************
219 bool GetHardwareSoundBuffer ()
222 HardwareSoundBuffer
= 0;
224 // The DirectSound object
225 #if (DIRECTSOUND_VERSION >= 0x0800)
226 LPDIRECTSOUND8 _DirectSound
;
228 LPDIRECTSOUND _DirectSound
;
231 #if (DIRECTSOUND_VERSION >= 0x0800)
232 if (DirectSoundCreate8(NULL
, &_DirectSound
, NULL
) == DS_OK
)
234 if (DirectSoundCreate(NULL
, &_DirectSound
, NULL
) == DS_OK
)
238 memset (&caps
, 0, sizeof (DSCAPS
));
239 caps
.dwSize
= sizeof (DSCAPS
);
241 HRESULT result
= _DirectSound
->GetCaps (&caps
);
244 HardwareSoundBuffer
= caps
.dwFreeHw3DStaticBuffers
;
247 _DirectSound
->Release ();
252 // ***************************************************************************
254 bool GetSystemInformation (IDriver
*d3dDriver
)
256 bool result
= GetGLInformation ();
257 result
|= GetD3DInformation (d3dDriver
);
258 result
|= GetVideoMemory ();
259 result
|= GetHardwareSoundBuffer ();
260 SystemMemory
= CSystemInfo::totalPhysicalMemory ();
261 CPUFrequency
= (uint
)(CSystemInfo::getProcessorFrequency () / (uint64
)1000000);
264 // ***************************************************************************
266 std::vector
<CVideoMode
> VideoModes
[2];
268 // ***************************************************************************
270 void RegisterVideoModes (uint driverId
, IDriver
*driver
)
272 vector
<GfxMode
> modes
;
273 driver
->getModes (modes
);
276 VideoModes
[driverId
].clear();
277 for (i
=0; i
<modes
.size(); i
++)
280 if ((modes
[i
].Depth
== 32) && (modes
[i
].Width
>= 800) && (modes
[i
].Width
>= 600))
284 mode
.Width
= modes
[i
].Width
;
285 mode
.Height
= modes
[i
].Height
;
286 mode
.ColorDepth
= modes
[i
].Depth
;
287 mode
.Frequency
= modes
[i
].Frequency
;
288 VideoModes
[driverId
].push_back (mode
);
293 // ***************************************************************************
294 // CDisplayDlg dialog
295 // ***************************************************************************
297 CDisplayDlg::CDisplayDlg(CWnd
* pParent
/*=NULL*/)
298 : CBaseDialog(CDisplayDlg::IDD
, pParent
)
300 //{{AFX_DATA_INIT(CDisplayDlg)
301 DriverChoiceMode
= DrvChooseUnknwown
;
311 // ***************************************************************************
313 void CDisplayDlg::DoDataExchange(CDataExchange
* pDX
)
315 CDialog::DoDataExchange(pDX
);
316 //{{AFX_DATA_MAP(CDisplayDlg)
317 DDX_Control(pDX
, IDC_DISPLAY_FS_TEXT0
, TextFS0
);
318 DDX_Control(pDX
, IDC_DISPLAY_WND_TEXT0
, TextWnd0
);
319 DDX_Control(pDX
, IDC_DISPLAY_WND_TEXT1
, TextWnd1
);
320 DDX_Control(pDX
, IDC_DISPLAY_WND_TEXT2
, TextWnd2
);
321 DDX_Control(pDX
, IDC_DISPLAY_WND_TEXT3
, TextWnd3
);
322 DDX_Control(pDX
, IDC_POSITION_Y
, PositionYCtrl
);
323 DDX_Control(pDX
, IDC_POSITION_X
, PositionXCtrl
);
324 DDX_Control(pDX
, IDC_HEIGHT
, HeightCtrl
);
325 DDX_Control(pDX
, IDC_WIDTH
, WidthCtrl
);
326 DDX_Control(pDX
, IDC_MODE
, ModeCtrl
);
327 DDX_Radio(pDX
, IDC_DRV3D_AUTO
, DriverChoiceMode
);
328 DDX_Radio(pDX
, IDC_FULLSCREEN
, Windowed
);
329 DDX_Text(pDX
, IDC_WIDTH
, Width
);
330 DDX_Text(pDX
, IDC_HEIGHT
, Height
);
331 DDX_CBIndex(pDX
, IDC_MODE
, Mode
);
332 DDX_Text(pDX
, IDC_POSITION_X
, PositionX
);
333 DDX_Text(pDX
, IDC_POSITION_Y
, PositionY
);
337 // ***************************************************************************
339 BEGIN_MESSAGE_MAP(CDisplayDlg
, CDialog
)
340 //{{AFX_MSG_MAP(CDisplayDlg)
341 ON_BN_CLICKED(IDC_FULLSCREEN
, OnFullscreen
)
342 ON_BN_CLICKED(IDC_WINDOW
, OnWindow
)
343 ON_BN_CLICKED(IDC_DIRECT3D
, OnDirect3d
)
344 ON_BN_CLICKED(IDC_DRV3D_AUTO
, OnDrv3DAuto
)
345 ON_EN_CHANGE(IDC_HEIGHT
, OnChangeHeight
)
346 ON_BN_CLICKED(IDC_OPENGL
, OnOpengl
)
347 ON_EN_CHANGE(IDC_POSITION_X
, OnChangePositionX
)
348 ON_EN_CHANGE(IDC_WIDTH
, OnChangeWidth
)
349 ON_EN_CHANGE(IDC_POSITION_Y
, OnChangePositionY
)
350 ON_CBN_SELCHANGE(IDC_MODE
, OnSelchangeMode
)
354 // ***************************************************************************
355 // CDisplayDlg message handlers
356 // ***************************************************************************
358 void CDisplayDlg::OnFullscreen()
366 // ***************************************************************************
368 void CDisplayDlg::OnWindow()
376 // ***************************************************************************
378 void CDisplayDlg::updateState ()
380 ModeCtrl
.EnableWindow (Windowed
== 0);
381 TextFS0
.EnableWindow (Windowed
== 0);
382 WidthCtrl
.EnableWindow (Windowed
== 1);
383 HeightCtrl
.EnableWindow (Windowed
== 1);
384 PositionXCtrl
.EnableWindow (Windowed
== 1);
385 PositionYCtrl
.EnableWindow (Windowed
== 1);
386 TextWnd0
.EnableWindow (Windowed
== 1);
387 TextWnd1
.EnableWindow (Windowed
== 1);
388 TextWnd2
.EnableWindow (Windowed
== 1);
389 TextWnd3
.EnableWindow (Windowed
== 1);
391 // Fill the combobox values
392 ModeCtrl
.ResetContent ();
394 if (DriverChoiceMode
!= DrvChooseUnknwown
)
396 TDriver actualDriver
= getActualDriver();
397 for (i
=0; i
<VideoModes
[actualDriver
].size (); i
++)
399 ucstring videoMode
= toString (VideoModes
[actualDriver
][i
].Width
) + "x" + toString (VideoModes
[actualDriver
][i
].Height
) +
400 " " + toString (VideoModes
[actualDriver
][i
].ColorDepth
) + " " + CI18N::get ("uiConfigBits") + " " +
401 toString (VideoModes
[actualDriver
][i
].Frequency
) + " " + CI18N::get ("uiConfigHz");
403 // hulud : Don't know how to set a wide string in a combo box...
404 ModeCtrl
.SendMessage (CB_INSERTSTRING
, -1, (LPARAM
)(videoMode
.toString().c_str()));
409 ModeCtrl
.SetCurSel (Mode
);
412 // ***************************************************************************
414 BOOL
CDisplayDlg::OnInitDialog()
416 CDialog::OnInitDialog();
420 return TRUE
; // return TRUE unless you set the focus to a control
421 // EXCEPTION: OCX Property Pages should return FALSE
424 // ***************************************************************************
426 void CDisplayDlg::OnDirect3d()
434 // ***************************************************************************
435 void CDisplayDlg::OnDrv3DAuto()
443 // ***************************************************************************
445 void CDisplayDlg::OnChangeHeight()
450 // ***************************************************************************
452 void CDisplayDlg::OnOpengl()
460 // ***************************************************************************
462 void CDisplayDlg::OnChangePositionX()
467 // ***************************************************************************
469 void CDisplayDlg::OnChangeWidth()
474 // ***************************************************************************
476 void CDisplayDlg::OnChangePositionY()
481 // ***************************************************************************
483 void CDisplayDlg::OnSelchangeMode()
488 // ***************************************************************************
489 CDisplayDlg::TDriver
CDisplayDlg::getActualDriver() const
491 switch(DriverChoiceMode
)
493 case DrvChooseOpenGL
: return OpenGL
;
494 case DrvChooseDirect3D
: return Direct3D
;
497 // D3D better on ATI Radeon cards
498 std::string deviceName
;
500 CSystemInfo::getVideoInfo(deviceName
, drvVersion
);
501 return strstr(toLower(deviceName
).c_str(), "radeon") != NULL
? Direct3D
: OpenGL
;