From 759acfa17539865d6b34ebc517951637af39c7d7 Mon Sep 17 00:00:00 2001 From: Bradley Austin Davis Date: Thu, 16 Apr 2015 19:07:21 -0700 Subject: [PATCH] Working on getting the offscreen UI working on retina --- interface/src/Application.cpp | 12 +++++++++++- libraries/render-utils/src/OffscreenUi.cpp | 18 ++++++++++-------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 930e244136..d0ae13ce21 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -764,6 +764,16 @@ void Application::initializeUi() { return QPointF(p); }); offscreenUi->resume(); + connect(_window, &MainWindow::windowGeometryChanged, [this](const QRect & r){ + static qreal oldDevicePixelRatio = 0; + qreal devicePixelRatio = _glWidget->devicePixelRatio(); + if (devicePixelRatio != oldDevicePixelRatio) { + oldDevicePixelRatio = devicePixelRatio; + qDebug() << "Device pixel ratio changed, triggering GL resize"; + resizeGL(_glWidget->width(), + _glWidget->height()); + } + }); } void Application::paintGL() { @@ -906,7 +916,7 @@ void Application::resizeGL(int width, int height) { glLoadIdentity(); auto offscreenUi = DependencyManager::get(); - offscreenUi->resize(QSize(width, height)); + offscreenUi->resize(_glWidget->size()); // update Stats width // let's set horizontal offset to give stats some margin to mirror diff --git a/libraries/render-utils/src/OffscreenUi.cpp b/libraries/render-utils/src/OffscreenUi.cpp index d0e54b08a9..d2d314bf96 100644 --- a/libraries/render-utils/src/OffscreenUi.cpp +++ b/libraries/render-utils/src/OffscreenUi.cpp @@ -79,7 +79,8 @@ void OffscreenUi::resize(const QSize & newSize) { makeCurrent(); // Clear out any fbos with the old size - _fboCache.setSize(newSize); + qreal pixelRatio = _renderControl->_renderWindow ? _renderControl->_renderWindow->devicePixelRatio() : 1.0; + _fboCache.setSize(newSize * pixelRatio); // Update our members if (_rootItem) { @@ -203,7 +204,7 @@ QPointF OffscreenUi::mapWindowToUi(const QPointF & p, QObject * dest) { } vec2 pos = toGlm(p); pos /= sourceSize; - pos *= vec2(toGlm(_quickWindow->renderTargetSize())); + pos *= vec2(toGlm(_quickWindow->size())); return QPointF(pos.x, pos.y); } @@ -300,11 +301,13 @@ void OffscreenUi::setProxyWindow(QWindow * window) { void OffscreenUi::show(const QUrl & url, const QString & name) { QQuickItem * item = _rootItem->findChild(name); + if (nullptr == item) { + load(url); + item = _rootItem->findChild(name); + } + if (nullptr != item) { item->setEnabled(true); - item->setVisible(true); - } else { - load(url); } } @@ -312,7 +315,7 @@ void OffscreenUi::toggle(const QUrl & url, const QString & name) { QQuickItem * item = _rootItem->findChild(name); // First load? if (nullptr == item) { - load(url); + show(url, name); return; } @@ -320,12 +323,11 @@ void OffscreenUi::toggle(const QUrl & url, const QString & name) { // dialogs can still swallow keyboard input) bool newFlag = !item->isEnabled(); item->setEnabled(newFlag); - // item->setVisible(newFlag); - } void OffscreenUi::load(const QUrl & url) { + qDebug() << "Loading from url: " << url; QVariant returnedValue; QVariant msg = url; QMetaObject::invokeMethod(_rootItem, "loadChild",