better check for oculus display in oculus legacy plugin because the sdk is buggy

This commit is contained in:
SamGondelman 2016-06-23 13:50:17 -07:00
parent a48cce2975
commit 284fcc8a0b

View file

@ -66,18 +66,47 @@ bool OculusLegacyDisplayPlugin::isSupported() const {
}
auto hmd = ovrHmd_Create(0);
// The Oculus SDK seems to have trouble finding the right screen sometimes, so we have to guess
// Guesses, in order of best match:
// - resolution and position match
// - resolution and one component of position match
// - resolution matches
// - position matches
QList<int> matches({ -1, -1, -1, -1 });
if (hmd) {
QPoint targetPosition{ hmd->WindowsPos.x, hmd->WindowsPos.y };
QSize targetResolution{ hmd->Resolution.w, hmd->Resolution.h };
auto screens = qApp->screens();
for(int i = 0; i < screens.size(); ++i) {
auto screen = screens[i];
QPoint position = screen->geometry().topLeft();
if (position == targetPosition) {
_hmdScreen = i;
break;
QSize resolution = screen->geometry().size();
if (position == targetPosition && resolution == targetResolution) {
matches[0] = i;
} else if ((position.x() == targetPosition.x() || position.y() == targetPosition.y()) &&
resolution == targetResolution) {
matches[1] = i;
} else if (resolution == targetResolution) {
matches[2] = i;
} else if (position == targetPosition) {
matches[3] = i;
}
}
}
for (int screen : matches) {
if (screen != -1) {
_hmdScreen = screen;
break;
}
}
if (_hmdScreen == -1) {
qDebug() << "Could not find Rift screen";
result = false;
}
ovr_Shutdown();
return result;