| 44 | void ShortenWideStringPrefix(std::wstring& toShorten, |
| 45 | ReplacementPhrase phrase) { |
| 46 | |
| 47 | const size_t phraseLength = wcslen(phrase.longPhrase); |
| 48 | |
| 49 | // we only care if it matches the start of the string, |
| 50 | // hence the 0 == ... rather than npos != ... |
| 51 | const bool startsWithPhrase = (0 == toShorten.find(phrase.longPhrase, |
| 52 | 0, // start at character 0 |
| 53 | phraseLength)); |
| 54 | |
| 55 | if(startsWithPhrase) { |
| 56 | toShorten.replace(0, |
| 57 | phraseLength, |
| 58 | phrase.shortPhrase); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | template <size_t ArraySize> |
| 63 | void ShortenWideStringPrefixes(std::wstring& toShorten, |
| 64 | std::array<ReplacementPhrase, ArraySize> phrases) { |
| 65 | for(auto phrase : phrases) { |
| 66 | ShortenWideStringPrefix(toShorten, phrase); |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | |
42 | | // GL_VENDOR+GL_RENDERER are good enough here, so we don't use wgfx_CardName, |
43 | | // plus that can cause crashes with Nvidia Optimus and some netbooks |
44 | | // see http://trac.wildfiregames.com/ticket/1952 |
45 | | // http://trac.wildfiregames.com/ticket/1575 |
46 | | wchar_t cardName[128]; |
47 | | const char* vendor = (const char*)glGetString(GL_VENDOR); |
48 | | const char* renderer = (const char*)glGetString(GL_RENDERER); |
49 | | // (happens if called before ogl_Init or between glBegin and glEnd.) |
50 | | if(!vendor || !renderer) |
51 | | return L""; |
52 | | swprintf_s(cardName, ARRAY_SIZE(cardName), L"%hs %hs", vendor, renderer); |
| 75 | std::wstring cardName; |
| 77 | { |
| 78 | // GL_VENDOR+GL_RENDERER are good enough here, so we don't use wgfx_CardName, |
| 79 | // plus that can cause crashes with Nvidia Optimus and some netbooks |
| 80 | // see http://trac.wildfiregames.com/ticket/1952 |
| 81 | // http://trac.wildfiregames.com/ticket/1575 |
| 82 | const char* const vendor = reinterpret_cast<const char*>(glGetString(GL_VENDOR)); |
| 83 | const char* const renderer = reinterpret_cast<const char*>(glGetString(GL_RENDERER)); |
| 84 | |
| 85 | // (happens if called before ogl_Init or between glBegin and glEnd.) |
| 86 | if(!vendor || !renderer) { |
| 87 | return L""; |
| 88 | } |
| 89 | |
| 90 | wchar_t cardNameBuffer[128]; |
| 91 | swprintf_s(cardNameBuffer, ARRAY_SIZE(cardNameBuffer), L"%hs %hs", vendor, renderer); |
| 92 | |
| 93 | cardName.assign(cardNameBuffer); |
| 94 | } |
| 95 | |
56 | | #define SHORTEN(what, charsToKeep)\ |
57 | | if(!wcsncmp(cardName, what, ARRAY_SIZE(what)-1))\ |
58 | | memmove(cardName+charsToKeep, cardName+ARRAY_SIZE(what)-1, (wcslen(cardName)-(ARRAY_SIZE(what)-1)+1)*sizeof(wchar_t)); |
59 | | SHORTEN(L"ATI Technologies Inc.", 3); |
60 | | SHORTEN(L"NVIDIA Corporation", 6); |
61 | | SHORTEN(L"S3 Graphics", 2); // returned by EnumDisplayDevices |
62 | | SHORTEN(L"S3 Graphics, Incorporated", 2); // returned by GL_VENDOR |
63 | | #undef SHORTEN |
| 99 | ShortenWideStringPrefixes( |
| 100 | cardName, |
| 101 | std::array<ReplacementPhrase, 4> { |
| 102 | ReplacementPhrase { L"ATI Technologies Inc.", L"ATI" }, |
| 103 | { L"NVIDIA Corporation", L"NVIDIA" }, |
| 104 | { L"S3 Graphics", L"S3" }, // returned by EnumDisplayDevices |
| 105 | { L"S3 Graphics, Incorporated", L"S3" } // returned by GL_VENDOR |
| 106 | } |
| 107 | ); |
| 108 | |