mirror of
https://github.com/JulianGro/overte.git
synced 2025-08-08 06:07:27 +02:00
HMDTools dialog restoration phase 2, electric boogaloo
This commit is contained in:
parent
5878a4661c
commit
a260be9a4d
3 changed files with 55 additions and 47 deletions
|
@ -37,6 +37,24 @@ HMDToolsDialog::HMDToolsDialog(QWidget* parent) :
|
||||||
_previousDialogScreen(NULL),
|
_previousDialogScreen(NULL),
|
||||||
_inHDMMode(false)
|
_inHDMMode(false)
|
||||||
{
|
{
|
||||||
|
// FIXME do we want to support more than one connected HMD? It seems like a pretty corner case
|
||||||
|
foreach(auto dp, getDisplayPlugins()) {
|
||||||
|
// The first plugin is always the standard 2D display, by convention
|
||||||
|
if (_defaultPluginName.isEmpty()) {
|
||||||
|
_defaultPluginName = dp->getName();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dp->isHmd()) {
|
||||||
|
// Not all HMD's have corresponding screens
|
||||||
|
if (dp->getHmdScreen() >= 0) {
|
||||||
|
_hmdScreenNumber = dp->getHmdScreen();
|
||||||
|
}
|
||||||
|
_hmdPluginName = dp->getName();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this->setWindowTitle("HMD Tools");
|
this->setWindowTitle("HMD Tools");
|
||||||
|
|
||||||
// Create layouter
|
// Create layouter
|
||||||
|
@ -90,25 +108,6 @@ HMDToolsDialog::HMDToolsDialog(QWidget* parent) :
|
||||||
|
|
||||||
// keep track of changes to the number of screens
|
// keep track of changes to the number of screens
|
||||||
connect(QApplication::desktop(), &QDesktopWidget::screenCountChanged, this, &HMDToolsDialog::screenCountChanged);
|
connect(QApplication::desktop(), &QDesktopWidget::screenCountChanged, this, &HMDToolsDialog::screenCountChanged);
|
||||||
|
|
||||||
|
|
||||||
// FIXME do we want to support more than one connected HMD? It seems like a pretty corner case
|
|
||||||
foreach(auto dp, getDisplayPlugins()) {
|
|
||||||
// The first plugin is always the standard 2D display, by convention
|
|
||||||
if (_defaultPluginName.isEmpty()) {
|
|
||||||
_defaultPluginName = dp->getName();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dp->isHmd()) {
|
|
||||||
// Not all HMD's have corresponding screens
|
|
||||||
if (dp->getHmdScreen() >= 0) {
|
|
||||||
_hmdScreenNumber = dp->getHmdScreen();
|
|
||||||
}
|
|
||||||
_hmdPluginName = dp->getName();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HMDToolsDialog::~HMDToolsDialog() {
|
HMDToolsDialog::~HMDToolsDialog() {
|
||||||
|
|
|
@ -38,6 +38,7 @@ const QString & Oculus_0_5_DisplayPlugin::getName() const {
|
||||||
return NAME;
|
return NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Oculus_0_5_DisplayPlugin::isSupported() const {
|
bool Oculus_0_5_DisplayPlugin::isSupported() const {
|
||||||
if (!ovr_Initialize(nullptr)) {
|
if (!ovr_Initialize(nullptr)) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -46,6 +47,21 @@ bool Oculus_0_5_DisplayPlugin::isSupported() const {
|
||||||
if (ovrHmd_Detect() > 0) {
|
if (ovrHmd_Detect() > 0) {
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto hmd = ovrHmd_Create(0);
|
||||||
|
if (hmd) {
|
||||||
|
QPoint targetPosition{ hmd->WindowsPos.x, hmd->WindowsPos.y };
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ovr_Shutdown();
|
ovr_Shutdown();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -55,26 +71,16 @@ void Oculus_0_5_DisplayPlugin::activate(PluginContainer * container) {
|
||||||
Q_ASSERT(false);
|
Q_ASSERT(false);
|
||||||
qFatal("Failed to Initialize SDK");
|
qFatal("Failed to Initialize SDK");
|
||||||
}
|
}
|
||||||
|
_hswDismissed = false;
|
||||||
_hmd = ovrHmd_Create(0);
|
_hmd = ovrHmd_Create(0);
|
||||||
if (!_hmd) {
|
if (!_hmd) {
|
||||||
qFatal("Failed to acquire HMD");
|
qFatal("Failed to acquire HMD");
|
||||||
}
|
}
|
||||||
|
|
||||||
OculusBaseDisplayPlugin::activate(container);
|
OculusBaseDisplayPlugin::activate(container);
|
||||||
QScreen* target{nullptr};
|
int screen = getHmdScreen();
|
||||||
QPoint targetPosition{ _hmd->WindowsPos.x, _hmd->WindowsPos.y };
|
if (screen != -1) {
|
||||||
foreach(auto screen, qApp->screens()) {
|
container->setFullscreen(qApp->screens()[screen]);
|
||||||
QRect screenPosition = screen->geometry();
|
|
||||||
QPoint position = screenPosition.topLeft();
|
|
||||||
if (position == targetPosition) {
|
|
||||||
target = screen;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (target) {
|
|
||||||
container->setFullscreen(target);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_window->installEventFilter(this);
|
_window->installEventFilter(this);
|
||||||
|
@ -137,10 +143,7 @@ void Oculus_0_5_DisplayPlugin::display(GLuint finalTexture, const glm::uvec2& sc
|
||||||
bool _hswDismissed{false};
|
bool _hswDismissed{false};
|
||||||
// Pass input events on to the application
|
// Pass input events on to the application
|
||||||
bool Oculus_0_5_DisplayPlugin::eventFilter(QObject* receiver, QEvent* event) {
|
bool Oculus_0_5_DisplayPlugin::eventFilter(QObject* receiver, QEvent* event) {
|
||||||
|
if (!_hswDismissed && (event->type() == QEvent::KeyPress)) {
|
||||||
switch (event->type()) {
|
|
||||||
case QEvent::KeyPress:
|
|
||||||
if (!_hswDismissed) {
|
|
||||||
static ovrHSWDisplayState hswState;
|
static ovrHSWDisplayState hswState;
|
||||||
ovrHmd_GetHSWDisplayState(_hmd, &hswState);
|
ovrHmd_GetHSWDisplayState(_hmd, &hswState);
|
||||||
if (hswState.Displayed) {
|
if (hswState.Displayed) {
|
||||||
|
@ -149,7 +152,6 @@ bool Oculus_0_5_DisplayPlugin::eventFilter(QObject* receiver, QEvent* event) {
|
||||||
_hswDismissed = true;
|
_hswDismissed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return OculusBaseDisplayPlugin::eventFilter(receiver, event);
|
return OculusBaseDisplayPlugin::eventFilter(receiver, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,7 +161,10 @@ bool Oculus_0_5_DisplayPlugin::eventFilter(QObject* receiver, QEvent* event) {
|
||||||
// thread
|
// thread
|
||||||
void Oculus_0_5_DisplayPlugin::finishFrame() {
|
void Oculus_0_5_DisplayPlugin::finishFrame() {
|
||||||
_window->doneCurrent();
|
_window->doneCurrent();
|
||||||
// _hmdWindow->doneCurrent();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
int Oculus_0_5_DisplayPlugin::getHmdScreen() const {
|
||||||
|
return _hmdScreen;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -24,6 +24,8 @@ public:
|
||||||
|
|
||||||
virtual bool eventFilter(QObject* receiver, QEvent* event) override;
|
virtual bool eventFilter(QObject* receiver, QEvent* event) override;
|
||||||
|
|
||||||
|
virtual int getHmdScreen() const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void preRender() override;
|
virtual void preRender() override;
|
||||||
virtual void preDisplay() override;
|
virtual void preDisplay() override;
|
||||||
|
@ -33,6 +35,8 @@ protected:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ovrTexture _eyeTextures[2];
|
ovrTexture _eyeTextures[2];
|
||||||
|
mutable int _hmdScreen{ -1 };
|
||||||
|
bool _hswDismissed{ false };
|
||||||
static const QString NAME;
|
static const QString NAME;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue