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>
This commit is contained in:
parent
facf3b15b3
commit
4da32851de
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue