From 2af35db1a112c49991a80f48e3cd8d8814deb321 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kera=CC=88nen=20Pasi?= Date: Tue, 3 Dec 2013 10:39:23 +0200 Subject: Fixes to QML retina display issues. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Task-id: QTRD-2661 Change-Id: I05fa1d9c3d078a7ed552b2b225f0d9bb1c03a0aa Reviewed-by: Miikka Heikkinen Reviewed-by: Tomi Korpipää --- .../engine/abstract3dcontroller_p.h | 1 + src/datavisualization/engine/bars3dcontroller_p.h | 2 +- .../engine/scatter3dcontroller_p.h | 2 +- .../engine/surface3dcontroller_p.h | 2 +- src/datavisualizationqml2/abstractdeclarative.cpp | 34 +++++++- src/datavisualizationqml2/abstractdeclarative_p.h | 4 + .../datavisualizationqml2.pro | 8 +- src/datavisualizationqml2/declarativebars.cpp | 70 ++++++---------- src/datavisualizationqml2/declarativebars_p.h | 6 +- .../declarativebarsrenderer.cpp | 87 -------------------- .../declarativebarsrenderer_p.h | 65 --------------- src/datavisualizationqml2/declarativerenderer.cpp | 93 ++++++++++++++++++++++ src/datavisualizationqml2/declarativerenderer_p.h | 66 +++++++++++++++ src/datavisualizationqml2/declarativescatter.cpp | 56 ++++--------- src/datavisualizationqml2/declarativescatter_p.h | 6 +- .../declarativescatterrenderer.cpp | 88 -------------------- .../declarativescatterrenderer_p.h | 65 --------------- src/datavisualizationqml2/declarativesurface.cpp | 58 ++++---------- src/datavisualizationqml2/declarativesurface_p.h | 6 +- .../declarativesurfacerenderer.cpp | 87 -------------------- .../declarativesurfacerenderer_p.h | 65 --------------- 21 files changed, 261 insertions(+), 610 deletions(-) delete mode 100644 src/datavisualizationqml2/declarativebarsrenderer.cpp delete mode 100644 src/datavisualizationqml2/declarativebarsrenderer_p.h create mode 100644 src/datavisualizationqml2/declarativerenderer.cpp create mode 100644 src/datavisualizationqml2/declarativerenderer_p.h delete mode 100644 src/datavisualizationqml2/declarativescatterrenderer.cpp delete mode 100644 src/datavisualizationqml2/declarativescatterrenderer_p.h delete mode 100644 src/datavisualizationqml2/declarativesurfacerenderer.cpp delete mode 100644 src/datavisualizationqml2/declarativesurfacerenderer_p.h diff --git a/src/datavisualization/engine/abstract3dcontroller_p.h b/src/datavisualization/engine/abstract3dcontroller_p.h index e1f69053..4ecfacdc 100644 --- a/src/datavisualization/engine/abstract3dcontroller_p.h +++ b/src/datavisualization/engine/abstract3dcontroller_p.h @@ -195,6 +195,7 @@ public: inline bool isInitialized() { return (m_renderer != 0); } virtual void synchDataToRenderer(); virtual void render(const GLuint defaultFboHandle = 0); + virtual void initializeOpenGL() = 0; void setRenderer(Abstract3DRenderer *renderer); virtual void addSeries(QAbstract3DSeries *series); diff --git a/src/datavisualization/engine/bars3dcontroller_p.h b/src/datavisualization/engine/bars3dcontroller_p.h index 71009024..54385571 100644 --- a/src/datavisualization/engine/bars3dcontroller_p.h +++ b/src/datavisualization/engine/bars3dcontroller_p.h @@ -76,7 +76,7 @@ public: explicit Bars3DController(QRect rect); ~Bars3DController(); - void initializeOpenGL(); + virtual void initializeOpenGL(); virtual void synchDataToRenderer(); // bar thickness, spacing between bars, and is spacing relative to thickness or absolute diff --git a/src/datavisualization/engine/scatter3dcontroller_p.h b/src/datavisualization/engine/scatter3dcontroller_p.h index 838c8010..00c87d4f 100644 --- a/src/datavisualization/engine/scatter3dcontroller_p.h +++ b/src/datavisualization/engine/scatter3dcontroller_p.h @@ -66,7 +66,7 @@ public: explicit Scatter3DController(QRect rect); ~Scatter3DController(); - void initializeOpenGL(); + virtual void initializeOpenGL(); // Change selection mode void setSelectionMode(QDataVis::SelectionFlags mode); diff --git a/src/datavisualization/engine/surface3dcontroller_p.h b/src/datavisualization/engine/surface3dcontroller_p.h index ef9c8494..b9bd60a1 100644 --- a/src/datavisualization/engine/surface3dcontroller_p.h +++ b/src/datavisualization/engine/surface3dcontroller_p.h @@ -75,7 +75,7 @@ public: explicit Surface3DController(QRect rect); ~Surface3DController(); - void initializeOpenGL(); + virtual void initializeOpenGL(); virtual void synchDataToRenderer(); void setGradient(const QLinearGradient &gradient); diff --git a/src/datavisualizationqml2/abstractdeclarative.cpp b/src/datavisualizationqml2/abstractdeclarative.cpp index a22caf9f..1bfa2911 100644 --- a/src/datavisualizationqml2/abstractdeclarative.cpp +++ b/src/datavisualizationqml2/abstractdeclarative.cpp @@ -17,12 +17,16 @@ ****************************************************************************/ #include "abstractdeclarative_p.h" +#include "declarativerenderer_p.h" #include "q3dvalueaxis.h" QT_DATAVISUALIZATION_BEGIN_NAMESPACE AbstractDeclarative::AbstractDeclarative(QQuickItem *parent) : - QQuickItem(parent) + QQuickItem(parent), + m_controller(0), + m_initialisedSize(0, 0), + m_devicePixelRatio(1.0) { } @@ -79,6 +83,34 @@ void AbstractDeclarative::setSharedController(Abstract3DController *controller) &AbstractDeclarative::selectionModeChanged); } +QSGNode *AbstractDeclarative::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) +{ + qreal devicePixelRatio = window()->devicePixelRatio(); + + // If old node exists and has right size and right device pixel ratio, reuse it. + if (oldNode && m_initialisedSize == boundingRect().size().toSize() && devicePixelRatio == m_devicePixelRatio) { + // Update bounding rectangle (that has same size as before). + static_cast(oldNode)->setRect(boundingRect()); + return oldNode; + } + + // Create a new render node when size changes or if there is no node yet + m_initialisedSize = boundingRect().size().toSize(); + m_devicePixelRatio = devicePixelRatio; + + // Delete old node + if (oldNode) + delete oldNode; + + // Create a new one and set it's bounding rectangle + DeclarativeRenderer *node = new DeclarativeRenderer(window(), m_controller); + node->setDevicePixelRatio(float(m_devicePixelRatio)); + node->setRect(boundingRect()); + m_controller->scene()->setDevicePixelRatio(m_devicePixelRatio); + m_controller->setBoundingRect(boundingRect().toRect()); + return node; +} + QAbstract3DInputHandler* AbstractDeclarative::inputHandler() const { return m_controller->activeInputHandler(); diff --git a/src/datavisualizationqml2/abstractdeclarative_p.h b/src/datavisualizationqml2/abstractdeclarative_p.h index fd7d89f2..aa3cf498 100644 --- a/src/datavisualizationqml2/abstractdeclarative_p.h +++ b/src/datavisualizationqml2/abstractdeclarative_p.h @@ -36,6 +36,7 @@ #include #include #include +#include QT_DATAVISUALIZATION_BEGIN_NAMESPACE @@ -75,6 +76,7 @@ protected: virtual void mouseReleaseEvent(QMouseEvent *event); virtual void mouseMoveEvent(QMouseEvent *event); virtual void wheelEvent(QWheelEvent *event); + virtual QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *); signals: // Signals shadow quality changes. @@ -87,6 +89,8 @@ signals: private: Abstract3DController *m_controller; + QSize m_initialisedSize; + qreal m_devicePixelRatio; }; QT_DATAVISUALIZATION_END_NAMESPACE diff --git a/src/datavisualizationqml2/datavisualizationqml2.pro b/src/datavisualizationqml2/datavisualizationqml2.pro index 2ae9ae1a..b9785f44 100644 --- a/src/datavisualizationqml2/datavisualizationqml2.pro +++ b/src/datavisualizationqml2/datavisualizationqml2.pro @@ -21,27 +21,23 @@ INCLUDEPATH += ../../include \ SOURCES += \ datavisualizationqml2_plugin.cpp \ declarativebars.cpp \ - declarativebarsrenderer.cpp \ declarativescatter.cpp \ - declarativescatterrenderer.cpp \ declarativesurface.cpp \ - declarativesurfacerenderer.cpp \ abstractdeclarative.cpp \ colorgradient.cpp \ declarativeseries.cpp \ + declarativerenderer.cpp \ declarativetheme.cpp HEADERS += \ datavisualizationqml2_plugin.h \ declarativebars_p.h \ - declarativebarsrenderer_p.h \ declarativescatter_p.h \ - declarativescatterrenderer_p.h \ declarativesurface_p.h \ - declarativesurfacerenderer_p.h \ abstractdeclarative_p.h \ colorgradient_p.h \ declarativeseries_p.h \ + declarativerenderer_p.h \ declarativetheme_p.h OTHER_FILES = qmldir diff --git a/src/datavisualizationqml2/declarativebars.cpp b/src/datavisualizationqml2/declarativebars.cpp index 91b338bd..905a842e 100644 --- a/src/datavisualizationqml2/declarativebars.cpp +++ b/src/datavisualizationqml2/declarativebars.cpp @@ -17,7 +17,7 @@ ****************************************************************************/ #include "declarativebars_p.h" -#include "declarativebarsrenderer_p.h" +#include "declarativerenderer_p.h" #include "q3dvalueaxis.h" #include "qitemmodelbardataproxy.h" @@ -25,8 +25,7 @@ QT_DATAVISUALIZATION_BEGIN_NAMESPACE DeclarativeBars::DeclarativeBars(QQuickItem *parent) : AbstractDeclarative(parent), - m_shared(0), - m_initialisedSize(0, 0) + m_barsController(0) { setFlags(QQuickItem::ItemHasContents); setAcceptedMouseButtons(Qt::AllButtons); @@ -36,110 +35,87 @@ DeclarativeBars::DeclarativeBars(QQuickItem *parent) setSmooth(true); // Create the shared component on the main GUI thread. - m_shared = new Bars3DController(boundingRect().toRect()); - AbstractDeclarative::setSharedController(m_shared); + m_barsController = new Bars3DController(boundingRect().toRect()); + AbstractDeclarative::setSharedController(m_barsController); } DeclarativeBars::~DeclarativeBars() { - delete m_shared; -} - -QSGNode *DeclarativeBars::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) -{ - // If old node exists and has right size, reuse it. - if (oldNode && m_initialisedSize == boundingRect().size().toSize()) { - // Update bounding rectangle (that has same size as before). - static_cast( oldNode )->setRect(boundingRect()); - return oldNode; - } - - // Create a new render node when size changes or if there is no node yet - m_initialisedSize = boundingRect().size().toSize(); - - // Delete old node - if (oldNode) - delete oldNode; - - // Create a new one and set it's bounding rectangle - DeclarativeBarsRenderer *node = new DeclarativeBarsRenderer(window(), m_shared); - node->setRect(boundingRect()); - m_shared->setBoundingRect(boundingRect().toRect()); - return node; + delete m_barsController; } void DeclarativeBars::setBarColor(const QColor &baseColor) { - m_shared->setBaseColor(baseColor); + m_barsController->setBaseColor(baseColor); } Q3DCategoryAxis *DeclarativeBars::rowAxis() const { - return static_cast(m_shared->axisX()); + return static_cast(m_barsController->axisX()); } void DeclarativeBars::setRowAxis(Q3DCategoryAxis *axis) { - m_shared->setAxisX(axis); + m_barsController->setAxisX(axis); } Q3DValueAxis *DeclarativeBars::valueAxis() const { - return static_cast(m_shared->axisY()); + return static_cast(m_barsController->axisY()); } void DeclarativeBars::setValueAxis(Q3DValueAxis *axis) { - m_shared->setAxisY(axis); + m_barsController->setAxisY(axis); } Q3DCategoryAxis *DeclarativeBars::columnAxis() const { - return static_cast(m_shared->axisZ()); + return static_cast(m_barsController->axisZ()); } void DeclarativeBars::setColumnAxis(Q3DCategoryAxis *axis) { - m_shared->setAxisZ(axis); + m_barsController->setAxisZ(axis); } void DeclarativeBars::setBarThickness(float thicknessRatio) { if (thicknessRatio != barThickness()) { - m_shared->setBarSpecs(GLfloat(thicknessRatio), barSpacing(), isBarSpacingRelative()); + m_barsController->setBarSpecs(GLfloat(thicknessRatio), barSpacing(), isBarSpacingRelative()); emit barThicknessChanged(thicknessRatio); } } float DeclarativeBars::barThickness() const { - return m_shared->barThickness(); + return m_barsController->barThickness(); } void DeclarativeBars::setBarSpacing(QSizeF spacing) { if (spacing != barSpacing()) { - m_shared->setBarSpecs(GLfloat(barThickness()), spacing, isBarSpacingRelative()); + m_barsController->setBarSpecs(GLfloat(barThickness()), spacing, isBarSpacingRelative()); emit barSpacingChanged(spacing); } } QSizeF DeclarativeBars::barSpacing() const { - return m_shared->barSpacing(); + return m_barsController->barSpacing(); } void DeclarativeBars::setBarSpacingRelative(bool relative) { if (relative != isBarSpacingRelative()) { - m_shared->setBarSpecs(GLfloat(barThickness()), barSpacing(), relative); + m_barsController->setBarSpecs(GLfloat(barThickness()), barSpacing(), relative); emit barSpacingRelativeChanged(relative); } } bool DeclarativeBars::isBarSpacingRelative() const { - return m_shared->isBarSpecRelative(); + return m_barsController->isBarSpecRelative(); } QQmlListProperty DeclarativeBars::seriesList() @@ -158,18 +134,18 @@ void DeclarativeBars::appendSeriesFunc(QQmlListProperty *list, QBa int DeclarativeBars::countSeriesFunc(QQmlListProperty *list) { - return reinterpret_cast(list->data)->m_shared->barSeriesList().size(); + return reinterpret_cast(list->data)->m_barsController->barSeriesList().size(); } QBar3DSeries *DeclarativeBars::atSeriesFunc(QQmlListProperty *list, int index) { - return reinterpret_cast(list->data)->m_shared->barSeriesList().at(index); + return reinterpret_cast(list->data)->m_barsController->barSeriesList().at(index); } void DeclarativeBars::clearSeriesFunc(QQmlListProperty *list) { DeclarativeBars *declBars = reinterpret_cast(list->data); - QList realList = declBars->m_shared->barSeriesList(); + QList realList = declBars->m_barsController->barSeriesList(); int count = realList.size(); for (int i = 0; i < count; i++) declBars->removeSeries(realList.at(i)); @@ -177,12 +153,12 @@ void DeclarativeBars::clearSeriesFunc(QQmlListProperty *list) void DeclarativeBars::addSeries(QBar3DSeries *series) { - m_shared->addSeries(series); + m_barsController->addSeries(series); } void DeclarativeBars::removeSeries(QBar3DSeries *series) { - m_shared->removeSeries(series); + m_barsController->removeSeries(series); series->setParent(this); // Reparent as removing will leave series parentless } diff --git a/src/datavisualizationqml2/declarativebars_p.h b/src/datavisualizationqml2/declarativebars_p.h index 6db17788..4bfe3755 100644 --- a/src/datavisualizationqml2/declarativebars_p.h +++ b/src/datavisualizationqml2/declarativebars_p.h @@ -93,12 +93,8 @@ signals: void barSpacingRelativeChanged(bool relative); void meshFileNameChanged(QString filename); -protected: - QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *); - private: - Bars3DController *m_shared; - QSize m_initialisedSize; + Bars3DController *m_barsController; }; QT_DATAVISUALIZATION_END_NAMESPACE diff --git a/src/datavisualizationqml2/declarativebarsrenderer.cpp b/src/datavisualizationqml2/declarativebarsrenderer.cpp deleted file mode 100644 index 3925e062..00000000 --- a/src/datavisualizationqml2/declarativebarsrenderer.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc -** All rights reserved. -** For any questions to Digia, please use contact form at http://qt.digia.com -** -** This file is part of the QtDataVisualization module. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** contact form at http://qt.digia.com -** -****************************************************************************/ - -#include "declarativebarsrenderer_p.h" - -#include -#include - -QT_DATAVISUALIZATION_BEGIN_NAMESPACE - -DeclarativeBarsRenderer::DeclarativeBarsRenderer(QQuickWindow *window, Bars3DController *renderer) - : m_fbo(0), - m_texture(0), - m_window(window), - m_barsRenderer(renderer) -{ - connect(m_window, &QQuickWindow::beforeSynchronizing, this, - &DeclarativeBarsRenderer::synchDataToRenderer, Qt::DirectConnection); - connect(m_window, &QQuickWindow::beforeRendering, this, - &DeclarativeBarsRenderer::renderFBO, Qt::DirectConnection); - connect(m_barsRenderer, &Abstract3DController::needRender, m_window, - &QQuickWindow::update); -} - -DeclarativeBarsRenderer::~DeclarativeBarsRenderer() -{ - delete m_texture; - delete m_fbo; -} - -void DeclarativeBarsRenderer::synchDataToRenderer() -{ - m_barsRenderer->initializeOpenGL(); - m_barsRenderer->synchDataToRenderer(); -} - -void DeclarativeBarsRenderer::renderFBO() -{ - QSize size = rect().size().toSize(); - - // Create FBO - if (!m_fbo) { - QOpenGLFramebufferObjectFormat format; - format.setAttachment(QOpenGLFramebufferObject::Depth); - m_fbo = new QOpenGLFramebufferObject(size, format); - m_texture = m_window->createTextureFromId(m_fbo->texture(), size); - - setTexture(m_texture); - - // Flip texture - // TODO: Can be gotten rid of once support for texture flipping becomes available (in Qt5.2) - QSize ts = m_texture->textureSize(); - QRectF sourceRect(0, 0, ts.width(), ts.height()); - float tmp = sourceRect.top(); - sourceRect.setTop(sourceRect.bottom()); - sourceRect.setBottom(tmp); - QSGGeometry *geometry = this->geometry(); - QSGGeometry::updateTexturedRectGeometry(geometry, rect(), - m_texture->convertToNormalizedSourceRect(sourceRect)); - markDirty(DirtyMaterial); - //qDebug() << "create node" << m_fbo->handle() << m_texture->textureId() << m_fbo->size(); - } - - // Call the shared rendering function - m_fbo->bind(); - - m_barsRenderer->render(m_fbo->handle()); - - m_fbo->release(); -} - -QT_DATAVISUALIZATION_END_NAMESPACE diff --git a/src/datavisualizationqml2/declarativebarsrenderer_p.h b/src/datavisualizationqml2/declarativebarsrenderer_p.h deleted file mode 100644 index 3be9b911..00000000 --- a/src/datavisualizationqml2/declarativebarsrenderer_p.h +++ /dev/null @@ -1,65 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc -** All rights reserved. -** For any questions to Digia, please use contact form at http://qt.digia.com -** -** This file is part of the QtDataVisualization module. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** contact form at http://qt.digia.com -** -****************************************************************************/ - -// -// W A R N I N G -// ------------- -// -// This file is not part of the QtDataVisualization API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. - -#ifndef DECLARATIVEBARSRENDERER_H -#define DECLARATIVEBARSRENDERER_H - -#include "datavisualizationglobal_p.h" -#include "bars3dcontroller_p.h" -#include - -class QOpenGLFramebufferObject; -class QSGTexture; -class QQuickWindow; - -QT_DATAVISUALIZATION_BEGIN_NAMESPACE - -class DeclarativeBarsRenderer : public QObject, public QSGSimpleTextureNode -{ - Q_OBJECT - -public: - DeclarativeBarsRenderer(QQuickWindow *window, Bars3DController *shared); - ~DeclarativeBarsRenderer(); - -public slots: - // Used to synch up data model from controller to renderer while main thread is locked - void synchDataToRenderer(); - // Renders view to FBO before render cycle starts. - void renderFBO(); - -private: - QOpenGLFramebufferObject *m_fbo; - QSGTexture *m_texture; - QQuickWindow *m_window; - Bars3DController *m_barsRenderer; -}; - -QT_DATAVISUALIZATION_END_NAMESPACE - -#endif diff --git a/src/datavisualizationqml2/declarativerenderer.cpp b/src/datavisualizationqml2/declarativerenderer.cpp new file mode 100644 index 00000000..419ef74e --- /dev/null +++ b/src/datavisualizationqml2/declarativerenderer.cpp @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the QtDataVisualization module. +** +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** +****************************************************************************/ + +#include "declarativerenderer_p.h" + +#include +#include + +QT_DATAVISUALIZATION_BEGIN_NAMESPACE + +DeclarativeRenderer::DeclarativeRenderer(QQuickWindow *window, Abstract3DController *controller) : + m_fbo(0), + m_texture(0), + m_window(window), + m_controller(controller) +{ + connect(m_window, &QQuickWindow::beforeSynchronizing, this, + &DeclarativeRenderer::synchDataToRenderer, Qt::DirectConnection); + connect(m_window, &QQuickWindow::beforeRendering, this, + &DeclarativeRenderer::renderFBO, Qt::DirectConnection); + connect(m_controller, &Abstract3DController::needRender, m_window, + &QQuickWindow::update); +} + +DeclarativeRenderer::~DeclarativeRenderer() +{ + delete m_texture; + delete m_fbo; +} + +void DeclarativeRenderer::synchDataToRenderer() +{ + m_controller->initializeOpenGL(); + m_controller->synchDataToRenderer(); +} + +void DeclarativeRenderer::setDevicePixelRatio(float devicePixelRatio ) +{ + m_devicePixelRatio = devicePixelRatio; +} + +void DeclarativeRenderer::renderFBO() +{ + QSize size = rect().size().toSize(); + size.setWidth(size.width() * m_devicePixelRatio); + size.setHeight(size.height() * m_devicePixelRatio); + + // Create FBO + if (!m_fbo) { + QOpenGLFramebufferObjectFormat format; + format.setAttachment(QOpenGLFramebufferObject::Depth); + m_fbo = new QOpenGLFramebufferObject(size, format); + m_texture = m_window->createTextureFromId(m_fbo->texture(), size); + + setTexture(m_texture); + + // Flip texture + // TODO: Can be gotten rid of once support for texture flipping becomes available (in Qt5.2) + QSize ts = m_texture->textureSize(); + QRectF sourceRect(0, 0, ts.width(), ts.height()); + float tmp = sourceRect.top(); + sourceRect.setTop(sourceRect.bottom()); + sourceRect.setBottom(tmp); + QSGGeometry *geometry = this->geometry(); + QSGGeometry::updateTexturedRectGeometry(geometry, rect(), + m_texture->convertToNormalizedSourceRect(sourceRect)); + markDirty(DirtyMaterial); + } + + // Call the graph rendering function + m_fbo->bind(); + + m_controller->render(m_fbo->handle()); + + m_fbo->release(); +} + +QT_DATAVISUALIZATION_END_NAMESPACE diff --git a/src/datavisualizationqml2/declarativerenderer_p.h b/src/datavisualizationqml2/declarativerenderer_p.h new file mode 100644 index 00000000..07d95c2c --- /dev/null +++ b/src/datavisualizationqml2/declarativerenderer_p.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the QtDataVisualization module. +** +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** +****************************************************************************/ + +// +// W A R N I N G +// ------------- +// +// This file is not part of the QtDataVisualization API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. + +#ifndef ABSTRACTDECLARATIVERENDERER_P_H +#define ABSTRACTDECLARATIVERENDERER_P_H + +#include "datavisualizationglobal_p.h" +#include +#include + +class QOpenGLFramebufferObject; +class QSGTexture; +class QQuickWindow; + +QT_DATAVISUALIZATION_BEGIN_NAMESPACE + +class DeclarativeRenderer : public QObject, public QSGSimpleTextureNode +{ + Q_OBJECT +public: + explicit DeclarativeRenderer(QQuickWindow *window, Abstract3DController *shared); + virtual ~DeclarativeRenderer(); + +public slots: + // Used to synch up data model from controller to renderer while main thread is locked + void synchDataToRenderer(); + // Renders view to FBO before render cycle starts. + void renderFBO(); + void setDevicePixelRatio(float devicePixelRatio); + +private: + QOpenGLFramebufferObject *m_fbo; + QSGTexture *m_texture; + QQuickWindow *m_window; + Abstract3DController *m_controller; + float m_devicePixelRatio; +}; + +QT_DATAVISUALIZATION_END_NAMESPACE + +#endif // ABSTRACTDECLARATIVERENDERER_P_H diff --git a/src/datavisualizationqml2/declarativescatter.cpp b/src/datavisualizationqml2/declarativescatter.cpp index 2848997f..40ef2926 100644 --- a/src/datavisualizationqml2/declarativescatter.cpp +++ b/src/datavisualizationqml2/declarativescatter.cpp @@ -17,15 +17,14 @@ ****************************************************************************/ #include "declarativescatter_p.h" -#include "declarativescatterrenderer_p.h" +#include "declarativerenderer_p.h" #include "qitemmodelscatterdataproxy.h" QT_DATAVISUALIZATION_BEGIN_NAMESPACE DeclarativeScatter::DeclarativeScatter(QQuickItem *parent) : AbstractDeclarative(parent), - m_shared(0), - m_initialisedSize(0, 0) + m_scatterController(0) { setFlags(QQuickItem::ItemHasContents); setAcceptedMouseButtons(Qt::AllButtons); @@ -35,66 +34,43 @@ DeclarativeScatter::DeclarativeScatter(QQuickItem *parent) setSmooth(true); // Create the shared component on the main GUI thread. - m_shared = new Scatter3DController(boundingRect().toRect()); - setSharedController(m_shared); + m_scatterController = new Scatter3DController(boundingRect().toRect()); + setSharedController(m_scatterController); } DeclarativeScatter::~DeclarativeScatter() { - delete m_shared; -} - -QSGNode *DeclarativeScatter::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) -{ - // If old node exists and has right size, reuse it. - if (oldNode && m_initialisedSize == boundingRect().size().toSize()) { - // Update bounding rectangle (that has same size as before). - static_cast( oldNode )->setRect(boundingRect()); - return oldNode; - } - - // Create a new render node when size changes or if there is no node yet - m_initialisedSize = boundingRect().size().toSize(); - - // Delete old node - if (oldNode) - delete oldNode; - - // Create a new one and set it's bounding rectangle - DeclarativeScatterRenderer *node = new DeclarativeScatterRenderer(window(), m_shared); - node->setRect(boundingRect()); - m_shared->setBoundingRect(boundingRect().toRect()); - return node; + delete m_scatterController; } Q3DValueAxis *DeclarativeScatter::axisX() const { - return static_cast(m_shared->axisX()); + return static_cast(m_scatterController->axisX()); } void DeclarativeScatter::setAxisX(Q3DValueAxis *axis) { - m_shared->setAxisX(axis); + m_scatterController->setAxisX(axis); } Q3DValueAxis *DeclarativeScatter::axisY() const { - return static_cast(m_shared->axisY()); + return static_cast(m_scatterController->axisY()); } void DeclarativeScatter::setAxisY(Q3DValueAxis *axis) { - m_shared->setAxisY(axis); + m_scatterController->setAxisY(axis); } Q3DValueAxis *DeclarativeScatter::axisZ() const { - return static_cast(m_shared->axisZ()); + return static_cast(m_scatterController->axisZ()); } void DeclarativeScatter::setAxisZ(Q3DValueAxis *axis) { - m_shared->setAxisZ(axis); + m_scatterController->setAxisZ(axis); } QQmlListProperty DeclarativeScatter::seriesList() @@ -113,18 +89,18 @@ void DeclarativeScatter::appendSeriesFunc(QQmlListProperty *li int DeclarativeScatter::countSeriesFunc(QQmlListProperty *list) { - return reinterpret_cast(list->data)->m_shared->scatterSeriesList().size(); + return reinterpret_cast(list->data)->m_scatterController->scatterSeriesList().size(); } QScatter3DSeries *DeclarativeScatter::atSeriesFunc(QQmlListProperty *list, int index) { - return reinterpret_cast(list->data)->m_shared->scatterSeriesList().at(index); + return reinterpret_cast(list->data)->m_scatterController->scatterSeriesList().at(index); } void DeclarativeScatter::clearSeriesFunc(QQmlListProperty *list) { DeclarativeScatter *declScatter = reinterpret_cast(list->data); - QList realList = declScatter->m_shared->scatterSeriesList(); + QList realList = declScatter->m_scatterController->scatterSeriesList(); int count = realList.size(); for (int i = 0; i < count; i++) declScatter->removeSeries(realList.at(i)); @@ -132,12 +108,12 @@ void DeclarativeScatter::clearSeriesFunc(QQmlListProperty *lis void DeclarativeScatter::addSeries(QScatter3DSeries *series) { - m_shared->addSeries(series); + m_scatterController->addSeries(series); } void DeclarativeScatter::removeSeries(QScatter3DSeries *series) { - m_shared->removeSeries(series); + m_scatterController->removeSeries(series); series->setParent(this); // Reparent as removing will leave series parentless } diff --git a/src/datavisualizationqml2/declarativescatter_p.h b/src/datavisualizationqml2/declarativescatter_p.h index 7490deda..8445b3d6 100644 --- a/src/datavisualizationqml2/declarativescatter_p.h +++ b/src/datavisualizationqml2/declarativescatter_p.h @@ -75,11 +75,7 @@ signals: void meshFileNameChanged(QString filename); protected: - Scatter3DController *m_shared; - QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *); - -private: - QSize m_initialisedSize; + Scatter3DController *m_scatterController; }; QT_DATAVISUALIZATION_END_NAMESPACE diff --git a/src/datavisualizationqml2/declarativescatterrenderer.cpp b/src/datavisualizationqml2/declarativescatterrenderer.cpp deleted file mode 100644 index 39aaa22e..00000000 --- a/src/datavisualizationqml2/declarativescatterrenderer.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc -** All rights reserved. -** For any questions to Digia, please use contact form at http://qt.digia.com -** -** This file is part of the QtDataVisualization module. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** contact form at http://qt.digia.com -** -****************************************************************************/ - -#include "declarativescatterrenderer_p.h" - -#include -#include - -QT_DATAVISUALIZATION_BEGIN_NAMESPACE - -DeclarativeScatterRenderer::DeclarativeScatterRenderer(QQuickWindow *window, - Scatter3DController *renderer) - : m_fbo(0), - m_texture(0), - m_window(window), - m_scatterRenderer(renderer) -{ - connect(m_window, &QQuickWindow::beforeSynchronizing, this, - &DeclarativeScatterRenderer::synchDataToRenderer, Qt::DirectConnection); - connect(m_window, &QQuickWindow::beforeRendering, this, - &DeclarativeScatterRenderer::renderFBO, Qt::DirectConnection); - connect(m_scatterRenderer, &Abstract3DController::needRender, m_window, - &QQuickWindow::update); -} - -DeclarativeScatterRenderer::~DeclarativeScatterRenderer() -{ - delete m_texture; - delete m_fbo; -} - -void DeclarativeScatterRenderer::synchDataToRenderer() -{ - m_scatterRenderer->initializeOpenGL(); - m_scatterRenderer->synchDataToRenderer(); -} - -void DeclarativeScatterRenderer::renderFBO() -{ - QSize size = rect().size().toSize(); - - // Create FBO - if (!m_fbo) { - QOpenGLFramebufferObjectFormat format; - format.setAttachment(QOpenGLFramebufferObject::Depth); - m_fbo = new QOpenGLFramebufferObject(size, format); - m_texture = m_window->createTextureFromId(m_fbo->texture(), size); - - setTexture(m_texture); - - // Flip texture - // TODO: Can be gotten rid of once support for texture flipping becomes available (in Qt5.2) - QSize ts = m_texture->textureSize(); - QRectF sourceRect(0, 0, ts.width(), ts.height()); - float tmp = sourceRect.top(); - sourceRect.setTop(sourceRect.bottom()); - sourceRect.setBottom(tmp); - QSGGeometry *geometry = this->geometry(); - QSGGeometry::updateTexturedRectGeometry(geometry, rect(), - m_texture->convertToNormalizedSourceRect(sourceRect)); - markDirty(DirtyMaterial); - //qDebug() << "create node" << m_fbo->handle() << m_texture->textureId() << m_fbo->size(); - } - - // Call the shared rendering function - m_fbo->bind(); - - m_scatterRenderer->render(m_fbo->handle()); - - m_fbo->release(); -} - -QT_DATAVISUALIZATION_END_NAMESPACE diff --git a/src/datavisualizationqml2/declarativescatterrenderer_p.h b/src/datavisualizationqml2/declarativescatterrenderer_p.h deleted file mode 100644 index 0bbd01ec..00000000 --- a/src/datavisualizationqml2/declarativescatterrenderer_p.h +++ /dev/null @@ -1,65 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc -** All rights reserved. -** For any questions to Digia, please use contact form at http://qt.digia.com -** -** This file is part of the QtDataVisualization module. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** contact form at http://qt.digia.com -** -****************************************************************************/ - -// -// W A R N I N G -// ------------- -// -// This file is not part of the QtDataVisualization API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. - -#ifndef DECLARATIVESCATTERRENDERER_P_H -#define DECLARATIVESCATTERRENDERER_P_H - -#include "datavisualizationglobal_p.h" -#include "scatter3dcontroller_p.h" -#include - -class QOpenGLFramebufferObject; -class QSGTexture; -class QQuickWindow; - -QT_DATAVISUALIZATION_BEGIN_NAMESPACE - -class DeclarativeScatterRenderer : public QObject, public QSGSimpleTextureNode -{ - Q_OBJECT - -public: - DeclarativeScatterRenderer(QQuickWindow *window, Scatter3DController *shared); - ~DeclarativeScatterRenderer(); - -public slots: - // Used to synch up data model from controller to renderer while main thread is locked - void synchDataToRenderer(); - // Renders view to FBO before render cycle starts. - void renderFBO(); - -private: - QOpenGLFramebufferObject *m_fbo; - QSGTexture *m_texture; - QQuickWindow *m_window; - Scatter3DController *m_scatterRenderer; -}; - -QT_DATAVISUALIZATION_END_NAMESPACE - -#endif diff --git a/src/datavisualizationqml2/declarativesurface.cpp b/src/datavisualizationqml2/declarativesurface.cpp index 8c50ab34..a450645f 100644 --- a/src/datavisualizationqml2/declarativesurface.cpp +++ b/src/datavisualizationqml2/declarativesurface.cpp @@ -17,7 +17,7 @@ ****************************************************************************/ #include "declarativesurface_p.h" -#include "declarativesurfacerenderer_p.h" +#include "declarativerenderer_p.h" #include "q3dvalueaxis.h" #include "qitemmodelsurfacedataproxy.h" @@ -25,8 +25,7 @@ QT_DATAVISUALIZATION_BEGIN_NAMESPACE DeclarativeSurface::DeclarativeSurface(QQuickItem *parent) : AbstractDeclarative(parent), - m_shared(0), - m_initialisedSize(0, 0), + m_surfaceController(0), m_gradient(0) { setFlags(QQuickItem::ItemHasContents); @@ -37,13 +36,13 @@ DeclarativeSurface::DeclarativeSurface(QQuickItem *parent) setSmooth(true); // Create the shared component on the main GUI thread. - m_shared = new Surface3DController(boundingRect().toRect()); - setSharedController(m_shared); + m_surfaceController = new Surface3DController(boundingRect().toRect()); + setSharedController(m_surfaceController); } DeclarativeSurface::~DeclarativeSurface() { - delete m_shared; + delete m_surfaceController; } void DeclarativeSurface::handleGradientUpdate() @@ -52,57 +51,34 @@ void DeclarativeSurface::handleGradientUpdate() setControllerGradient(*m_gradient); } -QSGNode *DeclarativeSurface::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) -{ - // If old node exists and has right size, reuse it. - if (oldNode && m_initialisedSize == boundingRect().size().toSize()) { - // Update bounding rectangle (that has same size as before). - static_cast( oldNode )->setRect(boundingRect()); - return oldNode; - } - - // Create a new render node when size changes or if there is no node yet - m_initialisedSize = boundingRect().size().toSize(); - - // Delete old node - if (oldNode) - delete oldNode; - - // Create a new one and set its bounding rectangle - DeclarativeSurfaceRenderer *node = new DeclarativeSurfaceRenderer(window(), m_shared); - node->setRect(boundingRect()); - m_shared->setBoundingRect(boundingRect().toRect()); - return node; -} - Q3DValueAxis *DeclarativeSurface::axisX() const { - return static_cast(m_shared->axisX()); + return static_cast(m_surfaceController->axisX()); } void DeclarativeSurface::setAxisX(Q3DValueAxis *axis) { - m_shared->setAxisX(axis); + m_surfaceController->setAxisX(axis); } Q3DValueAxis *DeclarativeSurface::axisY() const { - return static_cast(m_shared->axisY()); + return static_cast(m_surfaceController->axisY()); } void DeclarativeSurface::setAxisY(Q3DValueAxis *axis) { - m_shared->setAxisY(axis); + m_surfaceController->setAxisY(axis); } Q3DValueAxis *DeclarativeSurface::axisZ() const { - return static_cast(m_shared->axisZ()); + return static_cast(m_surfaceController->axisZ()); } void DeclarativeSurface::setAxisZ(Q3DValueAxis *axis) { - m_shared->setAxisZ(axis); + m_surfaceController->setAxisZ(axis); } void DeclarativeSurface::setGradient(ColorGradient *gradient) @@ -144,7 +120,7 @@ void DeclarativeSurface::setControllerGradient(const ColorGradient &gradient) } newGradient.setStops(stops); - m_shared->setGradient(newGradient); + m_surfaceController->setGradient(newGradient); } QQmlListProperty DeclarativeSurface::seriesList() @@ -163,18 +139,18 @@ void DeclarativeSurface::appendSeriesFunc(QQmlListProperty *li int DeclarativeSurface::countSeriesFunc(QQmlListProperty *list) { - return reinterpret_cast(list->data)->m_shared->surfaceSeriesList().size(); + return reinterpret_cast(list->data)->m_surfaceController->surfaceSeriesList().size(); } QSurface3DSeries *DeclarativeSurface::atSeriesFunc(QQmlListProperty *list, int index) { - return reinterpret_cast(list->data)->m_shared->surfaceSeriesList().at(index); + return reinterpret_cast(list->data)->m_surfaceController->surfaceSeriesList().at(index); } void DeclarativeSurface::clearSeriesFunc(QQmlListProperty *list) { DeclarativeSurface *declSurface = reinterpret_cast(list->data); - QList realList = declSurface->m_shared->surfaceSeriesList(); + QList realList = declSurface->m_surfaceController->surfaceSeriesList(); int count = realList.size(); for (int i = 0; i < count; i++) declSurface->removeSeries(realList.at(i)); @@ -182,12 +158,12 @@ void DeclarativeSurface::clearSeriesFunc(QQmlListProperty *lis void DeclarativeSurface::addSeries(QSurface3DSeries *series) { - m_shared->addSeries(series); + m_surfaceController->addSeries(series); } void DeclarativeSurface::removeSeries(QSurface3DSeries *series) { - m_shared->removeSeries(series); + m_surfaceController->removeSeries(series); series->setParent(this); // Reparent as removing will leave series parentless } diff --git a/src/datavisualizationqml2/declarativesurface_p.h b/src/datavisualizationqml2/declarativesurface_p.h index 600aeb98..4c7377be 100644 --- a/src/datavisualizationqml2/declarativesurface_p.h +++ b/src/datavisualizationqml2/declarativesurface_p.h @@ -80,14 +80,10 @@ public: protected: void handleGradientUpdate(); - QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *); - private: - Surface3DController *m_shared; - void setControllerGradient(const ColorGradient &gradient); - QSize m_initialisedSize; + Surface3DController *m_surfaceController; ColorGradient *m_gradient; // Not owned }; diff --git a/src/datavisualizationqml2/declarativesurfacerenderer.cpp b/src/datavisualizationqml2/declarativesurfacerenderer.cpp deleted file mode 100644 index 87a290ce..00000000 --- a/src/datavisualizationqml2/declarativesurfacerenderer.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc -** All rights reserved. -** For any questions to Digia, please use contact form at http://qt.digia.com -** -** This file is part of the QtDataVisualization module. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** contact form at http://qt.digia.com -** -****************************************************************************/ - -#include "declarativesurfacerenderer_p.h" - -#include -#include - -QT_DATAVISUALIZATION_BEGIN_NAMESPACE - -DeclarativeSurfaceRenderer::DeclarativeSurfaceRenderer(QQuickWindow *window, - Surface3DController *renderer) - : m_fbo(0), - m_texture(0), - m_window(window), - m_surfaceRenderer(renderer) -{ - connect(m_window, &QQuickWindow::beforeSynchronizing, this, - &DeclarativeSurfaceRenderer::synchDataToRenderer, Qt::DirectConnection); - connect(m_window, &QQuickWindow::beforeRendering, this, - &DeclarativeSurfaceRenderer::renderFBO, Qt::DirectConnection); - connect(m_surfaceRenderer, &Abstract3DController::needRender, m_window, - &QQuickWindow::update); -} - -DeclarativeSurfaceRenderer::~DeclarativeSurfaceRenderer() -{ - delete m_texture; - delete m_fbo; -} - -void DeclarativeSurfaceRenderer::synchDataToRenderer() -{ - m_surfaceRenderer->initializeOpenGL(); - m_surfaceRenderer->synchDataToRenderer(); -} - -void DeclarativeSurfaceRenderer::renderFBO() -{ - QSize size = rect().size().toSize(); - - // Create FBO - if (!m_fbo) { - QOpenGLFramebufferObjectFormat format; - format.setAttachment(QOpenGLFramebufferObject::Depth); - m_fbo = new QOpenGLFramebufferObject(size, format); - m_texture = m_window->createTextureFromId(m_fbo->texture(), size); - - setTexture(m_texture); - - // Flip texture - // TODO: Can be gotten rid of once support for texture flipping becomes available (in Qt5.2) - QSize ts = m_texture->textureSize(); - QRectF sourceRect(0, 0, ts.width(), ts.height()); - float tmp = sourceRect.top(); - sourceRect.setTop(sourceRect.bottom()); - sourceRect.setBottom(tmp); - QSGGeometry *geometry = this->geometry(); - QSGGeometry::updateTexturedRectGeometry(geometry, rect(), - m_texture->convertToNormalizedSourceRect(sourceRect)); - markDirty(DirtyMaterial); - } - - // Call the shared rendering function - m_fbo->bind(); - - m_surfaceRenderer->render(m_fbo->handle()); - - m_fbo->release(); -} - -QT_DATAVISUALIZATION_END_NAMESPACE diff --git a/src/datavisualizationqml2/declarativesurfacerenderer_p.h b/src/datavisualizationqml2/declarativesurfacerenderer_p.h deleted file mode 100644 index 09128f59..00000000 --- a/src/datavisualizationqml2/declarativesurfacerenderer_p.h +++ /dev/null @@ -1,65 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc -** All rights reserved. -** For any questions to Digia, please use contact form at http://qt.digia.com -** -** This file is part of the QtDataVisualization module. -** -** Licensees holding valid Qt Enterprise licenses may use this file in -** accordance with the Qt Enterprise License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. -** -** If you have questions regarding the use of this file, please use -** contact form at http://qt.digia.com -** -****************************************************************************/ - -// -// W A R N I N G -// ------------- -// -// This file is not part of the QtDataVisualization API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. - -#ifndef DECLARATIVESURFACERENDERER_H -#define DECLARATIVESURFACERENDERER_H - -#include "datavisualizationglobal_p.h" -#include "surface3dcontroller_p.h" -#include - -class QOpenGLFramebufferObject; -class QSGTexture; -class QQuickWindow; - -QT_DATAVISUALIZATION_BEGIN_NAMESPACE - -class DeclarativeSurfaceRenderer : public QObject, public QSGSimpleTextureNode -{ - Q_OBJECT - -public: - DeclarativeSurfaceRenderer(QQuickWindow *window, Surface3DController *shared); - ~DeclarativeSurfaceRenderer(); - -public slots: - // Used to synch up data model from controller to renderer while main thread is locked - void synchDataToRenderer(); - // Renders view to FBO before render cycle starts. - void renderFBO(); - -private: - QOpenGLFramebufferObject *m_fbo; - QSGTexture *m_texture; - QQuickWindow *m_window; - Surface3DController *m_surfaceRenderer; -}; - -QT_DATAVISUALIZATION_END_NAMESPACE - -#endif -- cgit v1.2.3