diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2016-11-22 13:29:55 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2016-11-22 22:29:16 +0000 |
commit | 07cde200e55ee03bf9e2f9af89c20f91072deccc (patch) | |
tree | a59282f7fa93a57e60d4f9e66b29535d64864c39 | |
parent | 39bed6135cd08b346866bb35ac95eaaf6f69b95c (diff) |
Move rebuildGeometry() functions of nodes
Move QSGDefaultImageNode::rebuildGeometry(),
QSGDefaultNinePatchNode::rebuildGeometry() to
QSGImageNode::rebuildGeometry(),
QSGNinePatchNode::rebuildGeometry()
respectively.
This makes it possible to use then from the D3D12 plugin
when built without OpenGL support.
Task-number: QTBUG-57185
Change-Id: Ib88c5622f7048618151a63d7536d76296a25842e
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
-rw-r--r-- | src/plugins/scenegraph/d3d12/qsgd3d12publicnodes.cpp | 14 | ||||
-rw-r--r-- | src/quick/scenegraph/util/qsgdefaultimagenode.cpp | 29 | ||||
-rw-r--r-- | src/quick/scenegraph/util/qsgdefaultimagenode_p.h | 6 | ||||
-rw-r--r-- | src/quick/scenegraph/util/qsgdefaultninepatchnode.cpp | 52 | ||||
-rw-r--r-- | src/quick/scenegraph/util/qsgdefaultninepatchnode_p.h | 3 | ||||
-rw-r--r-- | src/quick/scenegraph/util/qsgimagenode.cpp | 29 | ||||
-rw-r--r-- | src/quick/scenegraph/util/qsgimagenode.h | 6 | ||||
-rw-r--r-- | src/quick/scenegraph/util/qsgninepatchnode.cpp | 52 | ||||
-rw-r--r-- | src/quick/scenegraph/util/qsgninepatchnode.h | 4 |
9 files changed, 96 insertions, 99 deletions
diff --git a/src/plugins/scenegraph/d3d12/qsgd3d12publicnodes.cpp b/src/plugins/scenegraph/d3d12/qsgd3d12publicnodes.cpp index 783caa280f..1f01c440e5 100644 --- a/src/plugins/scenegraph/d3d12/qsgd3d12publicnodes.cpp +++ b/src/plugins/scenegraph/d3d12/qsgd3d12publicnodes.cpp @@ -39,10 +39,6 @@ #include "qsgd3d12publicnodes_p.h" -// for rebuildGeometry -#include <private/qsgdefaultninepatchnode_p.h> -#include <private/qsgdefaultimagenode_p.h> - QT_BEGIN_NAMESPACE QSGD3D12RectangleNode::QSGD3D12RectangleNode() @@ -138,7 +134,7 @@ void QSGD3D12ImageNode::setRect(const QRectF &r) return; m_rect = r; - QSGDefaultImageNode::rebuildGeometry(&m_geometry, texture(), m_rect, m_sourceRect, m_texCoordMode); + QSGImageNode::rebuildGeometry(&m_geometry, texture(), m_rect, m_sourceRect, m_texCoordMode); markDirty(DirtyGeometry); } @@ -153,7 +149,7 @@ void QSGD3D12ImageNode::setSourceRect(const QRectF &r) return; m_sourceRect = r; - QSGDefaultImageNode::rebuildGeometry(&m_geometry, texture(), m_rect, m_sourceRect, m_texCoordMode); + QSGImageNode::rebuildGeometry(&m_geometry, texture(), m_rect, m_sourceRect, m_texCoordMode); markDirty(DirtyGeometry); } @@ -170,7 +166,7 @@ void QSGD3D12ImageNode::setTexture(QSGTexture *texture) delete m_material.texture(); m_material.setTexture(texture); - QSGDefaultImageNode::rebuildGeometry(&m_geometry, texture, m_rect, m_sourceRect, m_texCoordMode); + QSGImageNode::rebuildGeometry(&m_geometry, texture, m_rect, m_sourceRect, m_texCoordMode); DirtyState dirty = DirtyMaterial; const bool wasAtlas = m_isAtlasTexture; @@ -192,7 +188,7 @@ void QSGD3D12ImageNode::setTextureCoordinatesTransform(TextureCoordinatesTransfo return; m_texCoordMode = mode; - QSGDefaultImageNode::rebuildGeometry(&m_geometry, texture(), m_rect, m_sourceRect, m_texCoordMode); + QSGImageNode::rebuildGeometry(&m_geometry, texture(), m_rect, m_sourceRect, m_texCoordMode); markDirty(DirtyMaterial); } @@ -247,7 +243,7 @@ void QSGD3D12NinePatchNode::setPadding(qreal left, qreal top, qreal right, qreal void QSGD3D12NinePatchNode::update() { - QSGDefaultNinePatchNode::rebuildGeometry(m_material.texture(), &m_geometry, m_padding, m_bounds, m_devicePixelRatio); + QSGNinePatchNode::rebuildGeometry(m_material.texture(), &m_geometry, m_padding, m_bounds, m_devicePixelRatio); markDirty(QSGNode::DirtyGeometry | QSGNode::DirtyMaterial); } diff --git a/src/quick/scenegraph/util/qsgdefaultimagenode.cpp b/src/quick/scenegraph/util/qsgdefaultimagenode.cpp index 6afe591dca..63773887a0 100644 --- a/src/quick/scenegraph/util/qsgdefaultimagenode.cpp +++ b/src/quick/scenegraph/util/qsgdefaultimagenode.cpp @@ -173,33 +173,4 @@ bool QSGDefaultImageNode::ownsTexture() const return m_ownsTexture; } -void QSGDefaultImageNode::rebuildGeometry(QSGGeometry *g, - QSGTexture *texture, - const QRectF &rect, - QRectF sourceRect, - TextureCoordinatesTransformMode texCoordMode) -{ - if (!texture) - return; - - if (!sourceRect.width() || !sourceRect.height()) { - QSize ts = texture->textureSize(); - sourceRect = QRectF(0, 0, ts.width(), ts.height()); - } - - // Maybe transform the texture coordinates - if (texCoordMode.testFlag(QSGImageNode::MirrorHorizontally)) { - float tmp = sourceRect.left(); - sourceRect.setLeft(sourceRect.right()); - sourceRect.setRight(tmp); - } - if (texCoordMode.testFlag(QSGImageNode::MirrorVertically)) { - float tmp = sourceRect.top(); - sourceRect.setTop(sourceRect.bottom()); - sourceRect.setBottom(tmp); - } - - QSGGeometry::updateTexturedRectGeometry(g, rect, texture->convertToNormalizedSourceRect(sourceRect)); -} - QT_END_NAMESPACE diff --git a/src/quick/scenegraph/util/qsgdefaultimagenode_p.h b/src/quick/scenegraph/util/qsgdefaultimagenode_p.h index eb6c487c18..bb9ebec885 100644 --- a/src/quick/scenegraph/util/qsgdefaultimagenode_p.h +++ b/src/quick/scenegraph/util/qsgdefaultimagenode_p.h @@ -85,12 +85,6 @@ public: void setOwnsTexture(bool owns) override; bool ownsTexture() const override; - static void rebuildGeometry(QSGGeometry *g, - QSGTexture *texture, - const QRectF &rect, - QRectF sourceRect, - TextureCoordinatesTransformMode texCoordMode); - private: QSGGeometry m_geometry; QSGOpaqueTextureMaterial m_opaque_material; diff --git a/src/quick/scenegraph/util/qsgdefaultninepatchnode.cpp b/src/quick/scenegraph/util/qsgdefaultninepatchnode.cpp index e5a53a3617..6023a9af93 100644 --- a/src/quick/scenegraph/util/qsgdefaultninepatchnode.cpp +++ b/src/quick/scenegraph/util/qsgdefaultninepatchnode.cpp @@ -81,56 +81,4 @@ void QSGDefaultNinePatchNode::update() markDirty(QSGNode::DirtyGeometry | QSGNode::DirtyMaterial); } -void QSGDefaultNinePatchNode::rebuildGeometry(QSGTexture *texture, QSGGeometry *geometry, const QVector4D &padding, - const QRectF &bounds, qreal dpr) -{ - if (padding.x() <= 0 && padding.y() <= 0 && padding.z() <= 0 && padding.w() <= 0) { - geometry->allocate(4, 0); - QSGGeometry::updateTexturedRectGeometry(geometry, bounds, texture->normalizedTextureSubRect()); - return; - } - - QRectF tc = texture->normalizedTextureSubRect(); - QSize ts = texture->textureSize(); - ts.setHeight(ts.height() / dpr); - ts.setWidth(ts.width() / dpr); - - qreal invtw = tc.width() / ts.width(); - qreal invth = tc.height() / ts.height(); - - struct Coord { qreal p; qreal t; }; - Coord cx[4] = { { bounds.left(), tc.left() }, - { bounds.left() + padding.x(), tc.left() + padding.x() * invtw }, - { bounds.right() - padding.z(), tc.right() - padding.z() * invtw }, - { bounds.right(), tc.right() } - }; - Coord cy[4] = { { bounds.top(), tc.top() }, - { bounds.top() + padding.y(), tc.top() + padding.y() * invth }, - { bounds.bottom() - padding.w(), tc.bottom() - padding.w() * invth }, - { bounds.bottom(), tc.bottom() } - }; - - geometry->allocate(16, 28); - QSGGeometry::TexturedPoint2D *v = geometry->vertexDataAsTexturedPoint2D(); - for (int y = 0; y < 4; ++y) { - for (int x = 0; x < 4; ++x) { - v->set(cx[x].p, cy[y].p, cx[x].t, cy[y].t); - ++v; - } - } - - quint16 *i = geometry->indexDataAsUShort(); - for (int r = 0; r < 3; ++r) { - if (r > 0) - *i++ = 4 * r; - for (int c = 0; c < 4; ++c) { - i[0] = 4 * r + c; - i[1] = 4 * r + c + 4; - i += 2; - } - if (r < 2) - *i++ = 4 * r + 3 + 4; - } -} - QT_END_NAMESPACE diff --git a/src/quick/scenegraph/util/qsgdefaultninepatchnode_p.h b/src/quick/scenegraph/util/qsgdefaultninepatchnode_p.h index 675cf48f47..3752a75ac6 100644 --- a/src/quick/scenegraph/util/qsgdefaultninepatchnode_p.h +++ b/src/quick/scenegraph/util/qsgdefaultninepatchnode_p.h @@ -70,9 +70,6 @@ public: void setPadding(qreal left, qreal top, qreal right, qreal bottom) override; void update() override; - static void rebuildGeometry(QSGTexture *texture, QSGGeometry *geometry, const QVector4D &padding, - const QRectF &bounds, qreal dpr); - private: QRectF m_bounds; qreal m_devicePixelRatio; diff --git a/src/quick/scenegraph/util/qsgimagenode.cpp b/src/quick/scenegraph/util/qsgimagenode.cpp index a78bfc1c66..c03c91d1cb 100644 --- a/src/quick/scenegraph/util/qsgimagenode.cpp +++ b/src/quick/scenegraph/util/qsgimagenode.cpp @@ -187,4 +187,33 @@ QT_BEGIN_NAMESPACE \return \c true if the node takes ownership of the texture; otherwise \c false. */ +void QSGImageNode::rebuildGeometry(QSGGeometry *g, + QSGTexture *texture, + const QRectF &rect, + QRectF sourceRect, + TextureCoordinatesTransformMode texCoordMode) +{ + if (!texture) + return; + + if (!sourceRect.width() || !sourceRect.height()) { + QSize ts = texture->textureSize(); + sourceRect = QRectF(0, 0, ts.width(), ts.height()); + } + + // Maybe transform the texture coordinates + if (texCoordMode.testFlag(QSGImageNode::MirrorHorizontally)) { + float tmp = sourceRect.left(); + sourceRect.setLeft(sourceRect.right()); + sourceRect.setRight(tmp); + } + if (texCoordMode.testFlag(QSGImageNode::MirrorVertically)) { + float tmp = sourceRect.top(); + sourceRect.setTop(sourceRect.bottom()); + sourceRect.setBottom(tmp); + } + + QSGGeometry::updateTexturedRectGeometry(g, rect, texture->convertToNormalizedSourceRect(sourceRect)); +} + QT_END_NAMESPACE diff --git a/src/quick/scenegraph/util/qsgimagenode.h b/src/quick/scenegraph/util/qsgimagenode.h index 7eab42c4e6..d25e732e4b 100644 --- a/src/quick/scenegraph/util/qsgimagenode.h +++ b/src/quick/scenegraph/util/qsgimagenode.h @@ -79,6 +79,12 @@ public: virtual void setOwnsTexture(bool owns) = 0; virtual bool ownsTexture() const = 0; + + static void rebuildGeometry(QSGGeometry *g, + QSGTexture *texture, + const QRectF &rect, + QRectF sourceRect, + TextureCoordinatesTransformMode texCoordMode); }; Q_DECLARE_OPERATORS_FOR_FLAGS(QSGImageNode::TextureCoordinatesTransformMode) diff --git a/src/quick/scenegraph/util/qsgninepatchnode.cpp b/src/quick/scenegraph/util/qsgninepatchnode.cpp index 9c167ca76f..33568b5488 100644 --- a/src/quick/scenegraph/util/qsgninepatchnode.cpp +++ b/src/quick/scenegraph/util/qsgninepatchnode.cpp @@ -74,4 +74,56 @@ QT_BEGIN_NAMESPACE \internal */ +void QSGNinePatchNode::rebuildGeometry(QSGTexture *texture, QSGGeometry *geometry, const QVector4D &padding, + const QRectF &bounds, qreal dpr) +{ + if (padding.x() <= 0 && padding.y() <= 0 && padding.z() <= 0 && padding.w() <= 0) { + geometry->allocate(4, 0); + QSGGeometry::updateTexturedRectGeometry(geometry, bounds, texture->normalizedTextureSubRect()); + return; + } + + QRectF tc = texture->normalizedTextureSubRect(); + QSize ts = texture->textureSize(); + ts.setHeight(ts.height() / dpr); + ts.setWidth(ts.width() / dpr); + + qreal invtw = tc.width() / ts.width(); + qreal invth = tc.height() / ts.height(); + + struct Coord { qreal p; qreal t; }; + Coord cx[4] = { { bounds.left(), tc.left() }, + { bounds.left() + padding.x(), tc.left() + padding.x() * invtw }, + { bounds.right() - padding.z(), tc.right() - padding.z() * invtw }, + { bounds.right(), tc.right() } + }; + Coord cy[4] = { { bounds.top(), tc.top() }, + { bounds.top() + padding.y(), tc.top() + padding.y() * invth }, + { bounds.bottom() - padding.w(), tc.bottom() - padding.w() * invth }, + { bounds.bottom(), tc.bottom() } + }; + + geometry->allocate(16, 28); + QSGGeometry::TexturedPoint2D *v = geometry->vertexDataAsTexturedPoint2D(); + for (int y = 0; y < 4; ++y) { + for (int x = 0; x < 4; ++x) { + v->set(cx[x].p, cy[y].p, cx[x].t, cy[y].t); + ++v; + } + } + + quint16 *i = geometry->indexDataAsUShort(); + for (int r = 0; r < 3; ++r) { + if (r > 0) + *i++ = 4 * r; + for (int c = 0; c < 4; ++c) { + i[0] = 4 * r + c; + i[1] = 4 * r + c + 4; + i += 2; + } + if (r < 2) + *i++ = 4 * r + 3 + 4; + } +} + QT_END_NAMESPACE diff --git a/src/quick/scenegraph/util/qsgninepatchnode.h b/src/quick/scenegraph/util/qsgninepatchnode.h index 8677a432ba..8509cbd326 100644 --- a/src/quick/scenegraph/util/qsgninepatchnode.h +++ b/src/quick/scenegraph/util/qsgninepatchnode.h @@ -55,6 +55,10 @@ public: virtual void setDevicePixelRatio(qreal ratio) = 0; virtual void setPadding(qreal left, qreal top, qreal right, qreal bottom) = 0; virtual void update() = 0; + + static void rebuildGeometry(QSGTexture *texture, QSGGeometry *geometry, + const QVector4D &padding, + const QRectF &bounds, qreal dpr); }; QT_END_NAMESPACE |