Linux multi-monitor fullscreen support
[ryzomcore.git] / ryzom / tools / client / client_config_qt / src / system.cpp
blob635800878f10000ee11713d16b5f9b49ac359865
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "stdpch.h"
18 #include "system.h"
20 #include <nel/3d/driver.h>
21 #include <nel/3d/dru.h>
22 #include <QtOpenGL/QGLWidget>
24 CSystem::CSystem()
26 GatherSysInfo();
27 #ifdef Q_OS_WIN32
28 GatherD3DInfo();
29 #endif
30 GatherOpenGLInfo();
33 CSystem::~CSystem()
37 bool CSystem::parseDriverVersion(const std::string &device, uint64 driver, std::string &version)
39 // file version
40 uint32 version1 = driver >> 48;
41 uint32 version2 = (driver >> 32) & 0xffff;
42 uint32 version3 = (driver >> 16) & 0xffff;
43 uint32 version4 = driver & 0xffff;
45 if (device.find("NVIDIA") != std::string::npos)
47 // nvidia should be something like 9.18.13.2018 and 9.18.13.1422
48 // which respectively corresponds to drivers 320.18 and 314.22
49 uint32 nvVersionMajor = (version3 % 10) * 100 + (version4 / 100);
50 uint32 nvVersionMinor = version4 % 100;
52 version = NLMISC::toString("%u.%u", nvVersionMajor, nvVersionMinor);
54 else
56 version = NLMISC::toString("%u.%u.%u.%u", version1, version2, version3, version4);
59 return true;
62 void CSystem::GatherSysInfo()
64 std::string device;
65 uint64 driver;
67 if( NLMISC::CSystemInfo::getVideoInfo( device, driver ) )
69 sysInfo.videoDevice = device;
71 CSystem::parseDriverVersion(device, driver, sysInfo.videoDriverVersion);
73 else
75 sysInfo.videoDevice = "video card";
76 sysInfo.videoDriverVersion = "0.0.0.0";
79 sysInfo.osName = NLMISC::CSystemInfo::getOS();
80 sysInfo.cpuName = NLMISC::CSystemInfo::getProc();
81 sysInfo.totalRAM = NLMISC::CSystemInfo::totalPhysicalMemory();
82 sysInfo.totalRAM /= ( 1024 * 1024 );
85 #ifdef Q_OS_WIN32
86 void CSystem::GatherD3DInfo()
88 NL3D::IDriver *driver = NULL;
89 try
91 driver = NL3D::CDRU::createD3DDriver();
93 NL3D::IDriver::CAdapter adapter;
95 if( driver->getAdapter( 0xffffffff, adapter ) )
97 d3dInfo.device = adapter.Description;
98 d3dInfo.driver = adapter.Driver;
100 CSystem::parseDriverVersion(d3dInfo.device, adapter.DriverVersion, d3dInfo.driverVersion);
103 GetVideoModes( d3dInfo.modes, driver );
105 driver->release();
108 catch(const NLMISC::Exception &e)
110 nlwarning( e.what() );
113 #endif
115 void CSystem::GatherOpenGLInfo()
117 QGLWidget *gl = new QGLWidget();
119 gl->makeCurrent();
121 const char *s = NULL;
122 s = reinterpret_cast< const char * >( glGetString( GL_VENDOR ) );
123 if( s != NULL )
124 openglInfo.vendor.assign( s );
126 s = reinterpret_cast< const char * >( glGetString( GL_RENDERER ) );
127 if( s != NULL )
128 openglInfo.renderer.assign( s );
130 s = reinterpret_cast< const char * >( glGetString( GL_VERSION ) );
131 if( s != NULL )
132 openglInfo.driverVersion.assign( s );
134 s = reinterpret_cast< const char * >( glGetString( GL_EXTENSIONS ) );
135 if( s != NULL )
137 openglInfo.extensions.assign( s );
138 for( std::string::iterator itr = openglInfo.extensions.begin(); itr != openglInfo.extensions.end(); ++itr )
139 if( *itr == ' ' )
140 *itr = '\n';
143 delete gl;
147 NL3D::IDriver *driver = NL3D::CDRU::createGlDriver();
148 driver->init(0);
149 GetVideoModes( openglInfo.modes, driver );
150 driver->release();
152 catch(const NLMISC::Exception &e)
154 nlwarning( e.what() );
158 void CSystem::GetVideoModes( std::vector< CVideoMode > &dst, NL3D::IDriver *driver ) const
160 std::vector< NL3D::GfxMode > modes;
161 driver->getModes( modes );
164 // auto mode
165 CVideoMode mode;
166 mode.depth = 0;
167 mode.width = 0;
168 mode.height = 0;
169 mode.frequency = 0;
170 dst.push_back( mode );
173 for( std::vector< NL3D::GfxMode >::iterator itr = modes.begin(); itr != modes.end(); ++itr )
175 if( ( itr->Width >= 800 ) && ( itr->Height >= 600 ) && ( itr->Depth >= 16 ) )
177 CVideoMode mode;
178 mode.depth = itr->Depth;
179 mode.width = itr->Width;
180 mode.height = itr->Height;
181 mode.frequency = itr->Frequency;
183 dst.push_back( mode );