LCOV - code coverage report
Current view: top level - source/lib/sysdep - gfx.cpp (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 0 21 0.0 %
Date: 2021-09-24 14:46:47 Functions: 0 2 0.0 %

          Line data    Source code
       1             : /* Copyright (C) 2020 Wildfire Games.
       2             :  *
       3             :  * Permission is hereby granted, free of charge, to any person obtaining
       4             :  * a copy of this software and associated documentation files (the
       5             :  * "Software"), to deal in the Software without restriction, including
       6             :  * without limitation the rights to use, copy, modify, merge, publish,
       7             :  * distribute, sublicense, and/or sell copies of the Software, and to
       8             :  * permit persons to whom the Software is furnished to do so, subject to
       9             :  * the following conditions:
      10             :  *
      11             :  * The above copyright notice and this permission notice shall be included
      12             :  * in all copies or substantial portions of the Software.
      13             :  *
      14             :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
      15             :  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
      16             :  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
      17             :  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
      18             :  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
      19             :  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
      20             :  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
      21             :  */
      22             : 
      23             : /*
      24             :  * graphics card detection.
      25             :  */
      26             : 
      27             : #include "precompiled.h"
      28             : #include "lib/sysdep/gfx.h"
      29             : 
      30             : #include "lib/external_libraries/libsdl.h"
      31             : #include "lib/ogl.h"
      32             : 
      33             : #if OS_WIN
      34             : # include "lib/sysdep/os/win/wgfx.h"
      35             : #endif
      36             : 
      37             : #include <string>
      38             : 
      39             : namespace gfx {
      40             : 
      41           0 : std::wstring CardName()
      42             : {
      43             :     // GL_VENDOR+GL_RENDERER are good enough here, so we don't use WMI to detect the cards.
      44             :     // On top of that WMI can cause crashes with Nvidia Optimus and some netbooks
      45             :     // see http://trac.wildfiregames.com/ticket/1952
      46             :     //     http://trac.wildfiregames.com/ticket/1575
      47           0 :     wchar_t cardName[128];
      48           0 :     const char* vendor   = (const char*)glGetString(GL_VENDOR);
      49           0 :     const char* renderer = (const char*)glGetString(GL_RENDERER);
      50             :     // (happens if called before ogl_Init or between glBegin and glEnd.)
      51           0 :     if(!vendor || !renderer)
      52           0 :         return L"";
      53           0 :     swprintf_s(cardName, ARRAY_SIZE(cardName), L"%hs %hs", vendor, renderer);
      54             : 
      55             :     // remove crap from vendor names. (don't dare touch the model name -
      56             :     // it's too risky, there are too many different strings)
      57             : #define SHORTEN(what, charsToKeep)\
      58             :     if(!wcsncmp(cardName, what, ARRAY_SIZE(what)-1))\
      59             :         memmove(cardName+charsToKeep, cardName+ARRAY_SIZE(what)-1, (wcslen(cardName)-(ARRAY_SIZE(what)-1)+1)*sizeof(wchar_t));
      60           0 :     SHORTEN(L"ATI Technologies Inc.", 3);
      61           0 :     SHORTEN(L"NVIDIA Corporation", 6);
      62           0 :     SHORTEN(L"S3 Graphics", 2);                   // returned by EnumDisplayDevices
      63           0 :     SHORTEN(L"S3 Graphics, Incorporated", 2); // returned by GL_VENDOR
      64             : #undef SHORTEN
      65             : 
      66           0 :     return cardName;
      67             : }
      68             : 
      69             : 
      70           0 : std::wstring DriverInfo()
      71             : {
      72           0 :     std::wstring driverInfo;
      73             : #if OS_WIN
      74             :     driverInfo = wgfx_DriverInfo();
      75             :     if(driverInfo.empty())
      76             : #endif
      77           0 :     {
      78           0 :         const char* version = (const char*)glGetString(GL_VERSION);
      79           0 :         if(version)
      80             :         {
      81             :             // add "OpenGL" to differentiate this from the real driver version
      82             :             // (returned by platform-specific detect routines).
      83           0 :             driverInfo = std::wstring(L"OpenGL ") + std::wstring(version, version+strlen(version));
      84             :         }
      85             :     }
      86             : 
      87           0 :     if(driverInfo.empty())
      88           0 :         return L"(unknown)";
      89           0 :     return driverInfo;
      90             : }
      91             : 
      92             : }   // namespace gfx

Generated by: LCOV version 1.13