1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
|
// Copyright (C) 2019 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <QSignalSpy>
#include <QtQuick/qquickitem.h>
#include <QtQuick3D/private/qquick3dtexture_p.h>
#include <QtQuick3D/QQuick3DTextureData>
#include <QtQuick3D/private/qquick3dviewport_p.h>
#include <QtQuick3DRuntimeRender/private/qssgrenderimage_p.h>
class tst_QQuick3DTexture : public QObject
{
Q_OBJECT
// Work-around to get access to updateSpatialNode
class Texture : public QQuick3DTexture
{
public:
using QQuick3DTexture::updateSpatialNode;
};
private slots:
void testSetSource();
void testSetSourceItem();
void testMappingAndTilingModes();
void testSamplerFilteringModes();
void testTransformations();
void testTextureData();
};
void tst_QQuick3DTexture::testSetSource()
{
Texture texture;
std::unique_ptr<QSSGRenderImage> node;
node.reset(static_cast<QSSGRenderImage *>(texture.updateSpatialNode(nullptr)));
QVERIFY(node);
// check that we get the same node out when passing in the old one
QCOMPARE(node.get(), texture.updateSpatialNode(node.get()));
QSignalSpy spy(&texture, SIGNAL(sourceChanged()));
QCOMPARE(spy.size(), 0);
const QUrl fileWithScheme {QString::fromLatin1("file:path/to/resource")};
const QString expectedPath {QString::fromLatin1("path/to/resource")};
texture.setSource(fileWithScheme);
node.reset(static_cast<QSSGRenderImage *>(texture.updateSpatialNode(nullptr)));
QCOMPARE(expectedPath, node->m_imagePath.path());
QCOMPARE(spy.size(), 1);
// Same url again
texture.setSource(fileWithScheme);
QCOMPARE(spy.size(), 1);
}
void tst_QQuick3DTexture::testSetSourceItem()
{
Texture texture;
QQuick3DViewport view3D;
QQuickItem item;
item.setParentItem(&view3D);
qRegisterMetaType<QQuickItem *>();
QSignalSpy spy(&texture, SIGNAL(sourceItemChanged()));
QCOMPARE(spy.size(), 0);
QVERIFY(!texture.sourceItem());
texture.setSourceItem(&item);
QVERIFY(texture.sourceItem());
QCOMPARE(spy.size(), 1);
// Same item again
texture.setSourceItem(&item);
QCOMPARE(spy.size(), 1);
}
void tst_QQuick3DTexture::testMappingAndTilingModes()
{
Texture texture;
std::unique_ptr<QSSGRenderImage> node;
// This test relies on the two different enums (QQ3DT::MappingModes & QSSGRI::MappingModes)
// having the same values
for (const auto mappingMode : {QQuick3DTexture::UV, QQuick3DTexture::LightProbe, QQuick3DTexture::Environment })
{
texture.setMappingMode(mappingMode);
node.reset(static_cast<QSSGRenderImage *>(texture.updateSpatialNode(nullptr)));
QCOMPARE(int(mappingMode), int(node->m_mappingMode));
}
// This also relies on the two enums (QQ3DT::TilingMode & QSSGRenderTextureCoordOp)
// having the same values
for (const auto tilingMode : {QQuick3DTexture::ClampToEdge, QQuick3DTexture::MirroredRepeat, QQuick3DTexture::Repeat })
{
texture.setHorizontalTiling(tilingMode);
node.reset(static_cast<QSSGRenderImage *>(texture.updateSpatialNode(nullptr)));
QCOMPARE(tilingMode, int(node->m_horizontalTilingMode));
texture.setVerticalTiling(tilingMode);
node.reset(static_cast<QSSGRenderImage *>(texture.updateSpatialNode(nullptr)));
QCOMPARE(tilingMode, int(node->m_verticalTilingMode));
}
}
void tst_QQuick3DTexture::testSamplerFilteringModes()
{
Texture texture;
std::unique_ptr<QSSGRenderImage> node;
for (const auto filterMode : {QQuick3DTexture::None, QQuick3DTexture::Linear, QQuick3DTexture::Nearest}) {
texture.setMinFilter(filterMode);
node.reset(static_cast<QSSGRenderImage *>(texture.updateSpatialNode(nullptr)));
QCOMPARE(int(filterMode), int(node->m_minFilterType));
texture.setMagFilter(filterMode);
node.reset(static_cast<QSSGRenderImage *>(texture.updateSpatialNode(nullptr)));
QCOMPARE(int(filterMode), int(node->m_magFilterType));
texture.setMipFilter(filterMode);
node.reset(static_cast<QSSGRenderImage *>(texture.updateSpatialNode(nullptr)));
QCOMPARE(int(filterMode), int(node->m_mipFilterType));
}
// generate mipmaps
node.reset(static_cast<QSSGRenderImage *>(texture.updateSpatialNode(nullptr)));
QCOMPARE(node->m_generateMipmaps, false);
texture.setGenerateMipmaps(true);
node.reset(static_cast<QSSGRenderImage *>(texture.updateSpatialNode(nullptr)));
QCOMPARE(node->m_generateMipmaps, true);
}
void tst_QQuick3DTexture::testTransformations()
{
Texture texture;
std::unique_ptr<QSSGRenderImage> node;
const float scaleU = 0.7f;
texture.setScaleU(scaleU);
node.reset(static_cast<QSSGRenderImage *>(texture.updateSpatialNode(nullptr)));
QCOMPARE(scaleU, node->m_scale.x());
const float scaleV = 0.36f;
texture.setScaleV(scaleV);
node.reset(static_cast<QSSGRenderImage *>(texture.updateSpatialNode(nullptr)));
QCOMPARE(scaleV, node->m_scale.y());
const float rotationUV = 0.38f;
texture.setRotationUV(rotationUV);
node.reset(static_cast<QSSGRenderImage *>(texture.updateSpatialNode(nullptr)));
QCOMPARE(rotationUV, node->m_rotation);
const float positionU = 0.39f;
texture.setPositionU(positionU);
node.reset(static_cast<QSSGRenderImage *>(texture.updateSpatialNode(nullptr)));
QCOMPARE(positionU, node->m_position.x());
const float positionV = 0.40f;
texture.setPositionV(positionV);
node.reset(static_cast<QSSGRenderImage *>(texture.updateSpatialNode(nullptr)));
QCOMPARE(positionV, node->m_position.y());
const float pivotU = 0.41f;
texture.setPivotU(pivotU);
node.reset(static_cast<QSSGRenderImage *>(texture.updateSpatialNode(nullptr)));
QCOMPARE(pivotU, node->m_pivot.x());
const float pivotV = 0.42f;
texture.setPivotV(pivotV);
node.reset(static_cast<QSSGRenderImage *>(texture.updateSpatialNode(nullptr)));
QCOMPARE(pivotV, node->m_pivot.y());
}
void tst_QQuick3DTexture::testTextureData()
{
Texture texture;
QQuick3DTextureData textureData;
std::unique_ptr<QSSGRenderImage> node;
node.reset(static_cast<QSSGRenderImage *>(texture.updateSpatialNode(nullptr)));
QVERIFY(node);
// check that we get the same node out when passing in the old one
QCOMPARE(node.get(), texture.updateSpatialNode(node.get()));
// No textureData by default
QSignalSpy spy(&texture, SIGNAL(textureDataChanged()));
QCOMPARE(spy.size(), 0);
// Set textureData
QVERIFY(!texture.textureData());
texture.setTextureData(&textureData);
QVERIFY(texture.textureData());
QCOMPARE(spy.size(), 1);
// Same textureData again
texture.setTextureData(&textureData);
QCOMPARE(spy.size(), 1);
}
QTEST_APPLESS_MAIN(tst_QQuick3DTexture)
#include "tst_qquick3dtexture.moc"
|