aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@theqtcompany.com>2015-04-16 15:41:26 +0200
committerLaszlo Agocs <laszlo.agocs@theqtcompany.com>2015-04-28 15:01:49 +0000
commit4da32851de3a1f462e1077fd9c59849863547af9 (patch)
tree1193eb0b4e94721f6af880a6ea558bd5726e6f0b /examples
parentfacf3b15b304a2876b3810f4dade4f233924e35e (diff)
Recreate the FBO on dpr change in rendercontrol example
Even when the window size is not changing. This provides a useful example of connecting to the screenChanged() signal. Task-number: QTBUG-45613 Change-Id: I0652838d9c0cfec8b64b3422997159f385445b20 Reviewed-by: Gunnar Sletta <gunnar@sletta.org>
Diffstat (limited to 'examples')
-rw-r--r--examples/quick/rendercontrol/window_singlethreaded.cpp30
-rw-r--r--examples/quick/rendercontrol/window_singlethreaded.h3
2 files changed, 28 insertions, 5 deletions
diff --git a/examples/quick/rendercontrol/window_singlethreaded.cpp b/examples/quick/rendercontrol/window_singlethreaded.cpp
index fb6dc2d223..a5748530df 100644
--- a/examples/quick/rendercontrol/window_singlethreaded.cpp
+++ b/examples/quick/rendercontrol/window_singlethreaded.cpp
@@ -48,6 +48,7 @@
#include <QOpenGLBuffer>
#include <QOpenGLVertexArrayObject>
#include <QOffscreenSurface>
+#include <QScreen>
#include <QQmlEngine>
#include <QQmlComponent>
#include <QQuickItem>
@@ -59,7 +60,8 @@ WindowSingleThreaded::WindowSingleThreaded()
: m_rootItem(0),
m_fbo(0),
m_quickInitialized(false),
- m_quickReady(false)
+ m_quickReady(false),
+ m_dpr(0)
{
setSurfaceType(QSurface::OpenGLSurface);
@@ -108,6 +110,11 @@ WindowSingleThreaded::WindowSingleThreaded()
connect(m_quickWindow, &QQuickWindow::sceneGraphInvalidated, this, &WindowSingleThreaded::destroyFbo);
connect(m_renderControl, &QQuickRenderControl::renderRequested, this, &WindowSingleThreaded::requestUpdate);
connect(m_renderControl, &QQuickRenderControl::sceneChanged, this, &WindowSingleThreaded::requestUpdate);
+
+ // Just recreating the FBO on resize is not sufficient, when moving between screens
+ // with different devicePixelRatio the QWindow size may remain the same but the FBO
+ // dimension is to change regardless.
+ connect(this, &QWindow::screenChanged, this, &WindowSingleThreaded::handleScreenChange);
}
WindowSingleThreaded::~WindowSingleThreaded()
@@ -139,7 +146,8 @@ void WindowSingleThreaded::createFbo()
{
// The scene graph has been initialized. It is now time to create an FBO and associate
// it with the QQuickWindow.
- m_fbo = new QOpenGLFramebufferObject(size() * devicePixelRatio(), QOpenGLFramebufferObject::CombinedDepthStencil);
+ m_dpr = devicePixelRatio();
+ m_fbo = new QOpenGLFramebufferObject(size() * m_dpr, QOpenGLFramebufferObject::CombinedDepthStencil);
m_quickWindow->setRenderTarget(m_fbo);
}
@@ -246,10 +254,8 @@ void WindowSingleThreaded::exposeEvent(QExposeEvent *)
}
}
-void WindowSingleThreaded::resizeEvent(QResizeEvent *)
+void WindowSingleThreaded::resizeFbo()
{
- // If this is a resize after the scene is up and running, recreate the fbo and the
- // Quick item and scene.
if (m_rootItem && m_context->makeCurrent(m_offscreenSurface)) {
delete m_fbo;
createFbo();
@@ -259,6 +265,20 @@ void WindowSingleThreaded::resizeEvent(QResizeEvent *)
}
}
+void WindowSingleThreaded::resizeEvent(QResizeEvent *)
+{
+ // If this is a resize after the scene is up and running, recreate the fbo and the
+ // Quick item and scene.
+ if (m_fbo && m_fbo->size() != size() * devicePixelRatio())
+ resizeFbo();
+}
+
+void WindowSingleThreaded::handleScreenChange()
+{
+ if (m_dpr != devicePixelRatio())
+ resizeFbo();
+}
+
void WindowSingleThreaded::mousePressEvent(QMouseEvent *e)
{
// Use the constructor taking localPos and screenPos. That puts localPos into the
diff --git a/examples/quick/rendercontrol/window_singlethreaded.h b/examples/quick/rendercontrol/window_singlethreaded.h
index 5344199c18..534d6b9bc3 100644
--- a/examples/quick/rendercontrol/window_singlethreaded.h
+++ b/examples/quick/rendercontrol/window_singlethreaded.h
@@ -77,10 +77,12 @@ private slots:
void destroyFbo();
void render();
void requestUpdate();
+ void handleScreenChange();
private:
void startQuick(const QString &filename);
void updateSizes();
+ void resizeFbo();
QOpenGLContext *m_context;
QOffscreenSurface *m_offscreenSurface;
@@ -94,6 +96,7 @@ private:
bool m_quickReady;
QTimer m_updateTimer;
CubeRenderer *m_cubeRenderer;
+ qreal m_dpr;
};
#endif