Skip to content

Commit 68fd9d2

Browse files
committed
fix: detect Wine host, use D3D11 on macOS
MacOS doesn't support a cool enough desktop OpenGL version for us to launch when using the Desktop OpenGL backend of ANGLE. We now detect the presence of Wine and query it for the host platform (analogous to `uname`). On Wine macOS we select D3D11. This platform requires use of libraries like D3DMetal/GPTK in Kegworks to emulate D3D11 enough. On Wine Linux we select Desktop OpenGL as D3D11 requires use of DXVK to function well enough. On proper Windows we select D3D11 and for any other platforms we don't indicate any preference for now.
1 parent c5b1170 commit 68fd9d2

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

engine/system/win/sys_video.cpp

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,24 @@ void sys_IVideo::FreeHandle(sys_IVideo* hnd)
9999
}
100100

101101

102-
using WineGetVersionFun = const char* ();
103-
static bool RunningOnWine()
102+
static std::string GetWineHostVersion()
104103
{
105104
#ifdef _WIN32
105+
using WineHostVersionFun = void (const char** /*sysname*/, const char** /*release*/);
106106
HMODULE mod = GetModuleHandleA("ntdll.dll");
107107
if (!mod)
108-
return false;
109-
auto ptr = GetProcAddress(mod, "wine_get_version");
110-
return !!ptr;
108+
return "";
109+
auto ptr = GetProcAddress(mod, "wine_get_host_version");
110+
if (!ptr)
111+
return "";
112+
auto fun = (WineHostVersionFun*)ptr;
113+
const char* sysname{};
114+
const char* release{};
115+
fun(&sysname, &release);
116+
return sysname ? sysname : "";
117+
#else
118+
return "";
111119
#endif
112-
return false;
113120
}
114121

115122
sys_video_c::sys_video_c(sys_IMain* sysHnd)
@@ -121,9 +128,16 @@ sys_video_c::sys_video_c(sys_IMain* sysHnd)
121128

122129
strcpy(curTitle, CFG_TITLE);
123130

124-
const int platformType = RunningOnWine()
125-
? GLFW_ANGLE_PLATFORM_TYPE_OPENGL
126-
: GLFW_ANGLE_PLATFORM_TYPE_D3D11;
131+
int platformType = GLFW_ANGLE_PLATFORM_TYPE_NONE;
132+
#ifdef _WIN32
133+
const std::string wineHost = GetWineHostVersion();
134+
if (wineHost == "Linux")
135+
platformType = GLFW_ANGLE_PLATFORM_TYPE_OPENGL;
136+
else if (wineHost == "Darwin")
137+
platformType = GLFW_ANGLE_PLATFORM_TYPE_D3D11;
138+
else // Native Windows
139+
platformType = GLFW_ANGLE_PLATFORM_TYPE_D3D11;
140+
#endif
127141
glfwInitHint(GLFW_ANGLE_PLATFORM_TYPE, platformType);
128142
glfwInit();
129143
}

0 commit comments

Comments
 (0)