diff options
author | Laszlo Agocs <laszlo.agocs@qt.io> | 2019-09-16 16:05:39 +0200 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@qt.io> | 2019-09-18 04:27:46 +0200 |
commit | 5d3589b30f1181d1a945902bf8915f1170e457b9 (patch) | |
tree | 7539693d063fa6ae23084d2ca5a4e5280ad32e3e | |
parent | 105c879435d4b459f4168a4aef5f74dc8a3f6016 (diff) |
Avoid changing function signature in public header
Change-Id: I0be124dfcafa2244531281ffd1ac6b559d82c604
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
-rw-r--r-- | src/quick/items/qquickwindow.cpp | 9 | ||||
-rw-r--r-- | src/quick/scenegraph/coreapi/qsgabstractrenderer.cpp | 48 | ||||
-rw-r--r-- | src/quick/scenegraph/coreapi/qsgabstractrenderer.h | 10 | ||||
-rw-r--r-- | src/quick/scenegraph/qsgopengllayer.cpp | 2 | ||||
-rw-r--r-- | src/quick/scenegraph/qsgrhilayer.cpp | 5 |
5 files changed, 64 insertions, 10 deletions
diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp index cd620e3408..e00789be85 100644 --- a/src/quick/items/qquickwindow.cpp +++ b/src/quick/items/qquickwindow.cpp @@ -500,10 +500,10 @@ void QQuickWindowPrivate::renderSceneGraph(const QSize &size, const QSize &surfa renderer->setDeviceRect(rect); renderer->setViewportRect(rect); if (QQuickRenderControl::renderWindowFor(q)) { - renderer->setProjectionMatrixToRect(QRect(QPoint(0, 0), size), false); + renderer->setProjectionMatrixToRect(QRect(QPoint(0, 0), size)); renderer->setDevicePixelRatio(devicePixelRatio); } else { - renderer->setProjectionMatrixToRect(QRect(QPoint(0, 0), rect.size()), false); + renderer->setProjectionMatrixToRect(QRect(QPoint(0, 0), rect.size())); renderer->setDevicePixelRatio(1); } } else { @@ -520,7 +520,10 @@ void QQuickWindowPrivate::renderSceneGraph(const QSize &size, const QSize &surfa renderer->setDeviceRect(rect); renderer->setViewportRect(rect); const bool flipY = rhi ? !rhi->isYUpInNDC() : false; - renderer->setProjectionMatrixToRect(QRectF(QPoint(0, 0), logicalSize), flipY); + QSGAbstractRenderer::MatrixTransformFlags matrixFlags = 0; + if (flipY) + matrixFlags |= QSGAbstractRenderer::MatrixTransformFlipY; + renderer->setProjectionMatrixToRect(QRectF(QPoint(0, 0), logicalSize), matrixFlags); renderer->setDevicePixelRatio(devicePixelRatio); } diff --git a/src/quick/scenegraph/coreapi/qsgabstractrenderer.cpp b/src/quick/scenegraph/coreapi/qsgabstractrenderer.cpp index 679ad1d445..62ed342244 100644 --- a/src/quick/scenegraph/coreapi/qsgabstractrenderer.cpp +++ b/src/quick/scenegraph/coreapi/qsgabstractrenderer.cpp @@ -73,6 +73,22 @@ QT_BEGIN_NAMESPACE */ /*! + \enum QSGAbstractRenderer::MatrixTransformFlag + + Used with setProjectionMatrixToRect() to indicate the expectations towards + the generated projection matrix. + + \value MatrixTransformFlipY The traditional assumption in Qt Quick is that + Y points up in the normalized device coordinate system. There is at least + one modern graphics API where this is not the case (Vulkan). This flag can + then be used to get a projection that is appropriate for such an API. + + \sa setProjectionMatrixToRect() + + \since 5.14 + */ + +/*! \fn void QSGAbstractRenderer::renderScene(GLuint fboId = 0) Render the scene to the specified \a fboId @@ -224,14 +240,38 @@ QRect QSGAbstractRenderer::viewportRect() const Convenience method that calls setProjectionMatrix() with an orthographic matrix generated from \a rect. - \a flipY must be \c true when the graphics API uses Y down in its - normalized device coordinate system (for example, Vulkan), \c false - otherwise. + \note This function assumes that the graphics API uses Y up in its + normalized device coordinate system. \sa setProjectionMatrix(), projectionMatrix() */ -void QSGAbstractRenderer::setProjectionMatrixToRect(const QRectF &rect, bool flipY) +void QSGAbstractRenderer::setProjectionMatrixToRect(const QRectF &rect) +{ + QMatrix4x4 matrix; + matrix.ortho(rect.x(), + rect.x() + rect.width(), + rect.y() + rect.height(), + rect.y(), + 1, + -1); + setProjectionMatrix(matrix); + setProjectionMatrixWithNativeNDC(matrix); +} + +/*! + Convenience method that calls setProjectionMatrix() with an + orthographic matrix generated from \a rect. + + Set MatrixTransformFlipY in \a flags when the graphics API uses Y down in + its normalized device coordinate system (for example, Vulkan). + + \sa setProjectionMatrix(), projectionMatrix() + + \since 5.14 + */ +void QSGAbstractRenderer::setProjectionMatrixToRect(const QRectF &rect, MatrixTransformFlags flags) { + const bool flipY = flags.testFlag(MatrixTransformFlipY); QMatrix4x4 matrix; matrix.ortho(rect.x(), rect.x() + rect.width(), diff --git a/src/quick/scenegraph/coreapi/qsgabstractrenderer.h b/src/quick/scenegraph/coreapi/qsgabstractrenderer.h index 08e600e0b8..1594352dab 100644 --- a/src/quick/scenegraph/coreapi/qsgabstractrenderer.h +++ b/src/quick/scenegraph/coreapi/qsgabstractrenderer.h @@ -63,6 +63,13 @@ public: Q_DECLARE_FLAGS(ClearMode, ClearModeBit) Q_FLAG(ClearMode) + enum MatrixTransformFlag + { + MatrixTransformFlipY = 0x01 + }; + Q_DECLARE_FLAGS(MatrixTransformFlags, MatrixTransformFlag) + Q_FLAG(MatrixTransformFlags) + ~QSGAbstractRenderer() override; void setRootNode(QSGRootNode *node); @@ -75,7 +82,8 @@ public: inline void setViewportRect(const QSize &size) { setViewportRect(QRect(QPoint(), size)); } QRect viewportRect() const; - void setProjectionMatrixToRect(const QRectF &rect, bool flipY = false); + void setProjectionMatrixToRect(const QRectF &rect); + void setProjectionMatrixToRect(const QRectF &rect, MatrixTransformFlags flags); void setProjectionMatrix(const QMatrix4x4 &matrix); void setProjectionMatrixWithNativeNDC(const QMatrix4x4 &matrix); QMatrix4x4 projectionMatrix() const; diff --git a/src/quick/scenegraph/qsgopengllayer.cpp b/src/quick/scenegraph/qsgopengllayer.cpp index 8db4cba58a..ae5032231d 100644 --- a/src/quick/scenegraph/qsgopengllayer.cpp +++ b/src/quick/scenegraph/qsgopengllayer.cpp @@ -408,7 +408,7 @@ void QSGOpenGLLayer::grab() m_mirrorVertical ? m_rect.bottom() : m_rect.top(), m_mirrorHorizontal ? -m_rect.width() : m_rect.width(), m_mirrorVertical ? -m_rect.height() : m_rect.height()); - m_renderer->setProjectionMatrixToRect(mirrored, false); + m_renderer->setProjectionMatrixToRect(mirrored); m_renderer->setClearColor(Qt::transparent); if (m_multisampling) { diff --git a/src/quick/scenegraph/qsgrhilayer.cpp b/src/quick/scenegraph/qsgrhilayer.cpp index 80ca40d50a..757410eded 100644 --- a/src/quick/scenegraph/qsgrhilayer.cpp +++ b/src/quick/scenegraph/qsgrhilayer.cpp @@ -388,7 +388,10 @@ void QSGRhiLayer::grab() m_mirrorHorizontal ? -m_rect.width() : m_rect.width(), m_mirrorVertical ? m_rect.height() : -m_rect.height()); } - m_renderer->setProjectionMatrixToRect(mirrored, !m_rhi->isYUpInNDC()); + QSGAbstractRenderer::MatrixTransformFlags matrixFlags = 0; + if (!m_rhi->isYUpInNDC()) + matrixFlags |= QSGAbstractRenderer::MatrixTransformFlipY; + m_renderer->setProjectionMatrixToRect(mirrored, matrixFlags); m_renderer->setClearColor(Qt::transparent); m_renderer->setRenderTarget(m_rt); m_renderer->setCommandBuffer(m_context->currentFrameCommandBuffer()); |