Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
gfx.cpp
Go to the documentation of this file.
1 /* Copyright (c) 2013 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 #define WSDL_NO_KEYSYM
32 #include "lib/ogl.h"
33 
34 #if OS_WIN
35 # include "lib/sysdep/os/win/wgfx.h"
36 #endif
37 
38 
39 namespace gfx {
40 
41 std::wstring CardName()
42 {
43  // GL_VENDOR+GL_RENDERER are good enough here, so we don't use wgfx_CardName,
44  // plus that 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  wchar_t cardName[128];
48  const char* vendor = (const char*)glGetString(GL_VENDOR);
49  const char* renderer = (const char*)glGetString(GL_RENDERER);
50  // (happens if called before ogl_Init or between glBegin and glEnd.)
51  if(!vendor || !renderer)
52  return L"";
53  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  SHORTEN(L"ATI Technologies Inc.", 3);
61  SHORTEN(L"NVIDIA Corporation", 6);
62  SHORTEN(L"S3 Graphics", 2); // returned by EnumDisplayDevices
63  SHORTEN(L"S3 Graphics, Incorporated", 2); // returned by GL_VENDOR
64 #undef SHORTEN
65 
66  return cardName;
67 }
68 
69 
70 std::wstring DriverInfo()
71 {
72  std::wstring driverInfo;
73 #if OS_WIN
74  driverInfo = wgfx_DriverInfo();
75  if(driverInfo.empty())
76 #endif
77  {
78  const char* version = (const char*)glGetString(GL_VERSION);
79  if(version)
80  {
81  // add "OpenGL" to differentiate this from the real driver version
82  // (returned by platform-specific detect routines).
83  driverInfo = std::wstring(L"OpenGL ") + std::wstring(version, version+strlen(version));
84  }
85  }
86 
87  if(driverInfo.empty())
88  return L"(unknown)";
89  return driverInfo;
90 }
91 
92 
93 size_t MemorySizeMiB()
94 {
95  // TODO: not implemented, SDL_GetVideoInfo only works on some platforms in SDL 1.2
96  // and no replacement is available in SDL2, and it can crash with Nvidia Optimus
97  // see http://trac.wildfiregames.com/ticket/2145
98  debug_warn(L"MemorySizeMiB not implemented");
99  return 0;
100 }
101 
102 } // namespace gfx
size_t MemorySizeMiB()
not implemented
Definition: gfx.cpp:93
#define SHORTEN(what, charsToKeep)
int swprintf_s(wchar_t *buf, size_t max_chars, const wchar_t *fmt,...) WPRINTF_ARGS(3)
std::wstring CardName()
Definition: gfx.cpp:41
#define ARRAY_SIZE(name)
std::wstring DriverInfo()
Definition: gfx.cpp:70
static Vendors vendor
Definition: x86_x64.cpp:170
#define debug_warn(expr)
display the error dialog with the given text.
Definition: debug.h:324
std::wstring wgfx_DriverInfo()
Definition: wgfx.cpp:159