Fixing offscreen rendering on retina display, even without a proxy window

This commit is contained in:
Bradley Austin Davis 2015-05-13 12:26:46 -07:00
parent ad5f1214bf
commit a0097bcff8
4 changed files with 16 additions and 3 deletions

View file

@ -4690,6 +4690,11 @@ int Application::getMaxOctreePacketsPerSecond() {
return _maxOctreePPS;
}
qreal Application::getDevicePixelRatio() {
return _window ? _window->windowHandle()->devicePixelRatio() : 1.0;
}
AbstractViewStateInterface* AbstractViewStateInterface::instance() {
return qApp;
}

View file

@ -300,7 +300,7 @@ public:
virtual const glm::vec3& getAvatarPosition() const { return _myAvatar->getPosition(); }
virtual void overrideEnvironmentData(const EnvironmentData& newData) { _environment.override(newData); }
virtual void endOverrideEnvironmentData() { _environment.endOverride(); }
virtual qreal getDevicePixelRatio();
NodeBounds& getNodeBoundsDisplay() { return _nodeBoundsDisplay; }

View file

@ -56,6 +56,7 @@ public:
virtual const glm::vec3& getAvatarPosition() const = 0;
virtual void postLambdaEvent(std::function<void()> f) = 0;
virtual qreal getDevicePixelRatio() = 0;
static AbstractViewStateInterface* instance();
};

View file

@ -11,6 +11,7 @@
#include <QOpenGLDebugLogger>
#include <QGLWidget>
#include <QtQml>
#include "AbstractViewStateInterface.h"
Q_DECLARE_LOGGING_CATEGORY(offscreenFocus)
Q_LOGGING_CATEGORY(offscreenFocus, "hifi.offscreen.focus")
@ -87,8 +88,14 @@ void OffscreenQmlSurface::create(QOpenGLContext* shareContext) {
}
void OffscreenQmlSurface::resize(const QSize& newSize) {
qreal pixelRatio = _renderControl->_renderWindow ? _renderControl->_renderWindow->devicePixelRatio() : 1.0;
// Qt bug in 5.4 forces this check of pixel ratio,
// even though we're rendering offscreen.
qreal pixelRatio = 1.0;
if (_renderControl && _renderControl->_renderWindow) {
pixelRatio = _renderControl->_renderWindow->devicePixelRatio();
} else {
pixelRatio = AbstractViewStateInterface::instance()->getDevicePixelRatio();
}
QSize newOffscreenSize = newSize * pixelRatio;
if (newOffscreenSize == _fboCache.getSize()) {
return;