1 | // Copyright (C) 2008-2012 NVIDIA Corporation. |
2 | // Copyright (C) 2019 The Qt Company Ltd. |
3 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
4 | |
5 | #include <QtQuick3DRuntimeRender/private/qssgrenderimage_p.h> |
6 | #include <QtQuick/QSGTexture> |
7 | |
8 | QT_BEGIN_NAMESPACE |
9 | |
10 | QSSGRenderImage::QSSGRenderImage(QSSGRenderGraphObject::Type type) |
11 | : QSSGRenderGraphObject(type) |
12 | { |
13 | m_flags.setFlag(flag: Flag::Dirty); |
14 | m_flags.setFlag(flag: Flag::TransformDirty); |
15 | } |
16 | |
17 | QSSGRenderImage::~QSSGRenderImage() = default; |
18 | |
19 | bool QSSGRenderImage::clearDirty() |
20 | { |
21 | const bool wasDirty = m_flags.testFlag(flag: Flag::Dirty); |
22 | m_flags.setFlag(flag: Flag::Dirty, on: false); |
23 | if (m_flags.testFlag(flag: Flag::TransformDirty)) { |
24 | calculateTextureTransform(); |
25 | return true; |
26 | } |
27 | return wasDirty; |
28 | } |
29 | |
30 | void QSSGRenderImage::calculateTextureTransform() |
31 | { |
32 | m_flags.setFlag(flag: Flag::TransformDirty, on: false); |
33 | |
34 | m_textureTransform = QMatrix4x4(); |
35 | if (m_flipU) { |
36 | m_textureTransform *= QMatrix4x4(-1.f, 0.f, 0.f, 1.f, |
37 | 0.f, 1.f, 0.f, 0.f, |
38 | 0.f, 0.f, 1.f, 0.f, |
39 | 0.f, 0.f, 0.f, 1.f); |
40 | } |
41 | if (m_flipV) { |
42 | m_textureTransform *= QMatrix4x4(1.f, 0.f, 0.f, 0.f, |
43 | 0.f, -1.f, 0.f, 1.f, |
44 | 0.f, 0.f, 1.f, 0.f, |
45 | 0.f, 0.f, 0.f, 1.f); |
46 | } |
47 | |
48 | QMatrix4x4 pivot; |
49 | QMatrix4x4 pivot_r; |
50 | QMatrix4x4 translation; |
51 | QMatrix4x4 rotation; |
52 | QMatrix4x4 scale; |
53 | |
54 | pivot.translate(x: m_pivot.x(), y: m_pivot.y()); |
55 | pivot_r.translate(x: -m_pivot.x(), y: -m_pivot.y()); |
56 | translation.translate(x: m_position.x(), y: m_position.y()); |
57 | scale.scale(x: m_scale.x(), y: m_scale.y()); |
58 | rotation.rotate(angle: m_rotation, vector: QVector3D(0, 0, 1)); |
59 | |
60 | m_textureTransform *= translation; |
61 | m_textureTransform *= pivot; |
62 | m_textureTransform *= rotation; |
63 | m_textureTransform *= scale; |
64 | m_textureTransform *= pivot_r; |
65 | } |
66 | |
67 | bool QSSGRenderImage::isImageTransformIdentity() const |
68 | { |
69 | if (m_mappingMode != MappingModes::Normal) |
70 | return false; |
71 | return m_textureTransform.isIdentity(); |
72 | } |
73 | |
74 | QT_END_NAMESPACE |
75 | |