1/****************************************************************************
2**
3** Copyright (C) 2016 Paul Lemire <paul.lemire350@gmail.com>
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt3D module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29// TODO Remove in Qt6
30#include <QtCore/qcompilerdetection.h>
31QT_WARNING_DISABLE_DEPRECATED
32
33#include <QtTest/QTest>
34#include <Qt3DRender/qabstracttexture.h>
35#include <Qt3DRender/private/qabstracttexture_p.h>
36#include <QObject>
37#include <QSignalSpy>
38#include <Qt3DRender/qabstracttextureimage.h>
39#include <Qt3DCore/qpropertyupdatedchange.h>
40#include <Qt3DCore/qpropertynodeaddedchange.h>
41#include <Qt3DCore/qpropertynoderemovedchange.h>
42#include <Qt3DCore/private/qnodecreatedchangegenerator_p.h>
43#include <Qt3DCore/private/qnodevisitor_p.h>
44#include <Qt3DCore/qnodecreatedchange.h>
45#include "testpostmanarbiter.h"
46
47class FakeTexture : public Qt3DRender::QAbstractTexture
48{
49public:
50 int sharedTextureId() const
51 {
52 return static_cast<Qt3DRender::QAbstractTexturePrivate *>(d_ptr.get())->m_sharedTextureId;
53 }
54
55 void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &change) override
56 {
57 Qt3DRender::QAbstractTexture::sceneChangeEvent(change);
58 }
59
60};
61
62class FakeTextureImage : public Qt3DRender::QAbstractTextureImage
63{
64protected:
65 Qt3DRender::QTextureImageDataGeneratorPtr dataGenerator() const override
66 {
67 return Qt3DRender::QTextureImageDataGeneratorPtr();
68 }
69};
70
71class tst_QAbstractTexture : public QObject
72{
73 Q_OBJECT
74
75private Q_SLOTS:
76
77 void initTestCase()
78 {
79 qRegisterMetaType<Qt3DRender::QAbstractTexture::TextureFormat>(typeName: "TextureFormat");
80 qRegisterMetaType<Qt3DRender::QAbstractTexture::Filter>(typeName: "Filter");
81 qRegisterMetaType<Qt3DRender::QAbstractTexture::ComparisonFunction>(typeName: "ComparisonFunction");
82 qRegisterMetaType<Qt3DRender::QAbstractTexture::ComparisonMode>(typeName: "ComparisonMode");
83 }
84
85 void checkDefaultConstruction()
86 {
87 // GIVEN
88 FakeTexture abstractTexture;
89
90 // THEN
91 QCOMPARE(abstractTexture.target(), Qt3DRender::QAbstractTexture::Target2D);
92 QCOMPARE(abstractTexture.format(), Qt3DRender::QAbstractTexture::Automatic);
93 QCOMPARE(abstractTexture.generateMipMaps(), false);
94 QCOMPARE(abstractTexture.wrapMode()->x(), Qt3DRender::QTextureWrapMode::ClampToEdge);
95 QCOMPARE(abstractTexture.wrapMode()->y(), Qt3DRender::QTextureWrapMode::ClampToEdge);
96 QCOMPARE(abstractTexture.wrapMode()->z(), Qt3DRender::QTextureWrapMode::ClampToEdge);
97 QCOMPARE(abstractTexture.status(), Qt3DRender::QAbstractTexture::None);
98 QCOMPARE(abstractTexture.width(), 1);
99 QCOMPARE(abstractTexture.height(), 1);
100 QCOMPARE(abstractTexture.depth(), 1);
101 QCOMPARE(abstractTexture.magnificationFilter(), Qt3DRender::QAbstractTexture::Nearest);
102 QCOMPARE(abstractTexture.minificationFilter(), Qt3DRender::QAbstractTexture::Nearest);
103 QCOMPARE(abstractTexture.maximumAnisotropy(), 1.0f);
104 QCOMPARE(abstractTexture.comparisonFunction(), Qt3DRender::QAbstractTexture::CompareLessEqual);
105 QCOMPARE(abstractTexture.comparisonMode(), Qt3DRender::QAbstractTexture::CompareNone);
106 QCOMPARE(abstractTexture.layers(), 1);
107 QCOMPARE(abstractTexture.samples(), 1);
108 QCOMPARE(abstractTexture.textureImages().size(), 0);
109 QCOMPARE(abstractTexture.samples(), 1);
110 QCOMPARE(abstractTexture.sharedTextureId(), -1);
111 QCOMPARE(abstractTexture.handleType(), Qt3DRender::QAbstractTexture::NoHandle);
112 QCOMPARE(abstractTexture.handle(), QVariant());
113 }
114
115 void checkPropertyChanges()
116 {
117 // GIVEN
118 FakeTexture abstractTexture;
119
120 {
121 // WHEN
122 QSignalSpy spy(&abstractTexture, SIGNAL(formatChanged(TextureFormat)));
123 const Qt3DRender::QAbstractTexture::TextureFormat newValue = Qt3DRender::QAbstractTexture::R8I;
124 abstractTexture.setFormat(newValue);
125
126 // THEN
127 QVERIFY(spy.isValid());
128 QCOMPARE(abstractTexture.format(), newValue);
129 QCOMPARE(spy.count(), 1);
130
131 // WHEN
132 spy.clear();
133 abstractTexture.setFormat(newValue);
134
135 // THEN
136 QCOMPARE(abstractTexture.format(), newValue);
137 QCOMPARE(spy.count(), 0);
138 }
139 {
140 // WHEN
141 QSignalSpy spy(&abstractTexture, SIGNAL(generateMipMapsChanged(bool)));
142 const bool newValue = true;
143 abstractTexture.setGenerateMipMaps(newValue);
144
145 // THEN
146 QVERIFY(spy.isValid());
147 QCOMPARE(abstractTexture.generateMipMaps(), newValue);
148 QCOMPARE(spy.count(), 1);
149
150 // WHEN
151 spy.clear();
152 abstractTexture.setGenerateMipMaps(newValue);
153
154 // THEN
155 QCOMPARE(abstractTexture.generateMipMaps(), newValue);
156 QCOMPARE(spy.count(), 0);
157 }
158 {
159 // WHEN
160 QSignalSpy spy(&abstractTexture, SIGNAL(widthChanged(int)));
161 const int newValue = 383;
162 abstractTexture.setWidth(newValue);
163
164 // THEN
165 QVERIFY(spy.isValid());
166 QCOMPARE(abstractTexture.width(), newValue);
167 QCOMPARE(spy.count(), 1);
168
169 // WHEN
170 spy.clear();
171 abstractTexture.setWidth(newValue);
172
173 // THEN
174 QCOMPARE(abstractTexture.width(), newValue);
175 QCOMPARE(spy.count(), 0);
176 }
177 {
178 // WHEN
179 QSignalSpy spy(&abstractTexture, SIGNAL(heightChanged(int)));
180 const int newValue = 427;
181 abstractTexture.setHeight(newValue);
182
183 // THEN
184 QVERIFY(spy.isValid());
185 QCOMPARE(abstractTexture.height(), newValue);
186 QCOMPARE(spy.count(), 1);
187
188 // WHEN
189 spy.clear();
190 abstractTexture.setHeight(newValue);
191
192 // THEN
193 QCOMPARE(abstractTexture.height(), newValue);
194 QCOMPARE(spy.count(), 0);
195 }
196 {
197 // WHEN
198 QSignalSpy spy(&abstractTexture, SIGNAL(depthChanged(int)));
199 const int newValue = 454;
200 abstractTexture.setDepth(newValue);
201
202 // THEN
203 QVERIFY(spy.isValid());
204 QCOMPARE(abstractTexture.depth(), newValue);
205 QCOMPARE(spy.count(), 1);
206
207 // WHEN
208 spy.clear();
209 abstractTexture.setDepth(newValue);
210
211 // THEN
212 QCOMPARE(abstractTexture.depth(), newValue);
213 QCOMPARE(spy.count(), 0);
214 }
215 {
216 // WHEN
217 QSignalSpy spy(&abstractTexture, SIGNAL(magnificationFilterChanged(Qt3DRender::QAbstractTexture::Filter)));
218 const Qt3DRender::QAbstractTexture::Filter newValue = Qt3DRender::QAbstractTexture::LinearMipMapLinear;
219 abstractTexture.setMagnificationFilter(newValue);
220
221 // THEN
222 QVERIFY(spy.isValid());
223 QCOMPARE(abstractTexture.magnificationFilter(), newValue);
224 QCOMPARE(spy.count(), 1);
225
226 // WHEN
227 spy.clear();
228 abstractTexture.setMagnificationFilter(newValue);
229
230 // THEN
231 QCOMPARE(abstractTexture.magnificationFilter(), newValue);
232 QCOMPARE(spy.count(), 0);
233 }
234 {
235 // WHEN
236 QSignalSpy spy(&abstractTexture, SIGNAL(minificationFilterChanged(Filter)));
237 const Qt3DRender::QAbstractTexture::Filter newValue = Qt3DRender::QAbstractTexture::LinearMipMapNearest;
238 abstractTexture.setMinificationFilter(newValue);
239
240 // THEN
241 QVERIFY(spy.isValid());
242 QCOMPARE(abstractTexture.minificationFilter(), newValue);
243 QCOMPARE(spy.count(), 1);
244
245 // WHEN
246 spy.clear();
247 abstractTexture.setMinificationFilter(newValue);
248
249 // THEN
250 QCOMPARE(abstractTexture.minificationFilter(), newValue);
251 QCOMPARE(spy.count(), 0);
252 }
253 {
254 // WHEN
255 QSignalSpy spy(&abstractTexture, SIGNAL(maximumAnisotropyChanged(float)));
256 const float newValue = 100.0f;
257 abstractTexture.setMaximumAnisotropy(newValue);
258
259 // THEN
260 QVERIFY(spy.isValid());
261 QCOMPARE(abstractTexture.maximumAnisotropy(), newValue);
262 QCOMPARE(spy.count(), 1);
263
264 // WHEN
265 spy.clear();
266 abstractTexture.setMaximumAnisotropy(newValue);
267
268 // THEN
269 QCOMPARE(abstractTexture.maximumAnisotropy(), newValue);
270 QCOMPARE(spy.count(), 0);
271 }
272 {
273 // WHEN
274 QSignalSpy spy(&abstractTexture, SIGNAL(comparisonFunctionChanged(Qt3DRender::QAbstractTexture::ComparisonFunction)));
275 const Qt3DRender::QAbstractTexture::ComparisonFunction newValue = Qt3DRender::QAbstractTexture::CompareGreaterEqual;
276 abstractTexture.setComparisonFunction(newValue);
277
278 // THEN
279 QVERIFY(spy.isValid());
280 QCOMPARE(abstractTexture.comparisonFunction(), newValue);
281 QCOMPARE(spy.count(), 1);
282
283 // WHEN
284 spy.clear();
285 abstractTexture.setComparisonFunction(newValue);
286
287 // THEN
288 QCOMPARE(abstractTexture.comparisonFunction(), newValue);
289 QCOMPARE(spy.count(), 0);
290 }
291 {
292 // WHEN
293 QSignalSpy spy(&abstractTexture, SIGNAL(comparisonModeChanged(Qt3DRender::QAbstractTexture::ComparisonMode)));
294 const Qt3DRender::QAbstractTexture::ComparisonMode newValue = Qt3DRender::QAbstractTexture::CompareRefToTexture;
295 abstractTexture.setComparisonMode(newValue);
296
297 // THEN
298 QVERIFY(spy.isValid());
299 QCOMPARE(abstractTexture.comparisonMode(), newValue);
300 QCOMPARE(spy.count(), 1);
301
302 // WHEN
303 spy.clear();
304 abstractTexture.setComparisonMode(newValue);
305
306 // THEN
307 QCOMPARE(abstractTexture.comparisonMode(), newValue);
308 QCOMPARE(spy.count(), 0);
309 }
310 {
311 // WHEN
312 QSignalSpy spy(&abstractTexture, SIGNAL(layersChanged(int)));
313 const int newValue = 512;
314 abstractTexture.setLayers(newValue);
315
316 // THEN
317 QVERIFY(spy.isValid());
318 QCOMPARE(abstractTexture.layers(), newValue);
319 QCOMPARE(spy.count(), 1);
320
321 // WHEN
322 spy.clear();
323 abstractTexture.setLayers(newValue);
324
325 // THEN
326 QCOMPARE(abstractTexture.layers(), newValue);
327 QCOMPARE(spy.count(), 0);
328 }
329 {
330 // WHEN
331 QSignalSpy spy(&abstractTexture, SIGNAL(samplesChanged(int)));
332 const int newValue = 1024;
333 abstractTexture.setSamples(newValue);
334
335 // THEN
336 QVERIFY(spy.isValid());
337 QCOMPARE(abstractTexture.samples(), newValue);
338 QCOMPARE(spy.count(), 1);
339
340 // WHEN
341 spy.clear();
342 abstractTexture.setSamples(newValue);
343
344 // THEN
345 QCOMPARE(abstractTexture.samples(), newValue);
346 QCOMPARE(spy.count(), 0);
347 }
348 }
349
350 void checkCreationData()
351 {
352 // GIVEN
353 FakeTexture abstractTexture;
354
355 abstractTexture.setFormat(Qt3DRender::QAbstractTexture::RG3B2);
356 abstractTexture.setGenerateMipMaps(true);
357 abstractTexture.setWidth(350);
358 abstractTexture.setHeight(383);
359 abstractTexture.setDepth(396);
360 abstractTexture.setMagnificationFilter(Qt3DRender::QAbstractTexture::NearestMipMapLinear);
361 abstractTexture.setMinificationFilter(Qt3DRender::QAbstractTexture::NearestMipMapNearest);
362 abstractTexture.setMaximumAnisotropy(12.0f);
363 abstractTexture.setComparisonFunction(Qt3DRender::QAbstractTexture::CommpareNotEqual);
364 abstractTexture.setComparisonMode(Qt3DRender::QAbstractTexture::CompareRefToTexture);
365 abstractTexture.setLayers(128);
366 abstractTexture.setSamples(256);
367 abstractTexture.setWrapMode(Qt3DRender::QTextureWrapMode(Qt3DRender::QTextureWrapMode::ClampToBorder));
368
369 FakeTextureImage image;
370 FakeTextureImage image2;
371 abstractTexture.addTextureImage(textureImage: &image);
372 abstractTexture.addTextureImage(textureImage: &image2);
373
374 // WHEN
375 QVector<Qt3DCore::QNodeCreatedChangeBasePtr> creationChanges;
376
377 {
378 Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&abstractTexture);
379 creationChanges = creationChangeGenerator.creationChanges();
380 }
381
382 // THEN
383 {
384 QCOMPARE(creationChanges.size(), 3); // Texture + Images
385
386 const auto creationChangeData = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<Qt3DRender::QAbstractTextureData>>(src: creationChanges.first());
387 const Qt3DRender::QAbstractTextureData cloneData = creationChangeData->data;
388
389 QCOMPARE(abstractTexture.target(), cloneData.target);
390 QCOMPARE(abstractTexture.format(), cloneData.format);
391 QCOMPARE(abstractTexture.generateMipMaps(), cloneData.autoMipMap);
392 QCOMPARE(abstractTexture.wrapMode()->x(), cloneData.wrapModeX);
393 QCOMPARE(abstractTexture.wrapMode()->x(), cloneData.wrapModeY);
394 QCOMPARE(abstractTexture.wrapMode()->x(), cloneData.wrapModeZ);
395 QCOMPARE(abstractTexture.width(), cloneData.width);
396 QCOMPARE(abstractTexture.height(), cloneData.height);
397 QCOMPARE(abstractTexture.depth(), cloneData.depth);
398 QCOMPARE(abstractTexture.magnificationFilter(), cloneData.magFilter);
399 QCOMPARE(abstractTexture.minificationFilter(), cloneData.minFilter);
400 QCOMPARE(abstractTexture.maximumAnisotropy(), cloneData.maximumAnisotropy);
401 QCOMPARE(abstractTexture.comparisonFunction(), cloneData.comparisonFunction);
402 QCOMPARE(abstractTexture.comparisonMode(), cloneData.comparisonMode);
403 QCOMPARE(abstractTexture.layers(), cloneData.layers);
404 QCOMPARE(abstractTexture.samples(), cloneData.samples);
405 QCOMPARE(abstractTexture.sharedTextureId(), cloneData.sharedTextureId);
406 QCOMPARE(abstractTexture.textureImages().size(), cloneData.textureImageIds.size());
407
408 for (int i = 0, m = abstractTexture.textureImages().size(); i < m; ++i)
409 QCOMPARE(abstractTexture.textureImages().at(i)->id(), cloneData.textureImageIds.at(i));
410
411 QCOMPARE(abstractTexture.id(), creationChangeData->subjectId());
412 QCOMPARE(abstractTexture.isEnabled(), true);
413 QCOMPARE(abstractTexture.isEnabled(), creationChangeData->isNodeEnabled());
414 QCOMPARE(abstractTexture.metaObject(), creationChangeData->metaObject());
415 }
416
417 // WHEN
418 abstractTexture.setEnabled(false);
419
420 {
421 Qt3DCore::QNodeCreatedChangeGenerator creationChangeGenerator(&abstractTexture);
422 creationChanges = creationChangeGenerator.creationChanges();
423 }
424
425 // THEN
426 {
427 QCOMPARE(creationChanges.size(), 3); // Texture + Images
428
429 const auto creationChangeData = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<Qt3DRender::QAbstractTextureData>>(src: creationChanges.first());
430 const Qt3DRender::QAbstractTextureData cloneData = creationChangeData->data;
431
432 QCOMPARE(abstractTexture.target(), cloneData.target);
433 QCOMPARE(abstractTexture.format(), cloneData.format);
434 QCOMPARE(abstractTexture.generateMipMaps(), cloneData.autoMipMap);
435 QCOMPARE(abstractTexture.wrapMode()->x(), cloneData.wrapModeX);
436 QCOMPARE(abstractTexture.wrapMode()->x(), cloneData.wrapModeY);
437 QCOMPARE(abstractTexture.wrapMode()->x(), cloneData.wrapModeZ);
438 QCOMPARE(abstractTexture.width(), cloneData.width);
439 QCOMPARE(abstractTexture.height(), cloneData.height);
440 QCOMPARE(abstractTexture.depth(), cloneData.depth);
441 QCOMPARE(abstractTexture.magnificationFilter(), cloneData.magFilter);
442 QCOMPARE(abstractTexture.minificationFilter(), cloneData.minFilter);
443 QCOMPARE(abstractTexture.maximumAnisotropy(), cloneData.maximumAnisotropy);
444 QCOMPARE(abstractTexture.comparisonFunction(), cloneData.comparisonFunction);
445 QCOMPARE(abstractTexture.comparisonMode(), cloneData.comparisonMode);
446 QCOMPARE(abstractTexture.layers(), cloneData.layers);
447 QCOMPARE(abstractTexture.samples(), cloneData.samples);
448 QCOMPARE(abstractTexture.sharedTextureId(), cloneData.sharedTextureId);
449 QCOMPARE(abstractTexture.textureImages().size(), cloneData.textureImageIds.size());
450
451 for (int i = 0, m = abstractTexture.textureImages().size(); i < m; ++i)
452 QCOMPARE(abstractTexture.textureImages().at(i)->id(), cloneData.textureImageIds.at(i));
453
454 QCOMPARE(abstractTexture.id(), creationChangeData->subjectId());
455 QCOMPARE(abstractTexture.isEnabled(), false);
456 QCOMPARE(abstractTexture.isEnabled(), creationChangeData->isNodeEnabled());
457 QCOMPARE(abstractTexture.metaObject(), creationChangeData->metaObject());
458 }
459 }
460
461 void checkFormatUpdate()
462 {
463 // GIVEN
464 TestArbiter arbiter;
465 FakeTexture abstractTexture;
466 arbiter.setArbiterOnNode(&abstractTexture);
467
468 {
469 // WHEN
470 abstractTexture.setFormat(Qt3DRender::QAbstractTexture::RG8_UNorm);
471
472 // THEN
473 QCOMPARE(arbiter.events.size(), 0);
474 QCOMPARE(arbiter.dirtyNodes.size(), 1);
475 QCOMPARE(arbiter.dirtyNodes.front(), &abstractTexture);
476
477 arbiter.dirtyNodes.clear();
478 }
479
480 {
481 // WHEN
482 abstractTexture.setFormat(Qt3DRender::QAbstractTexture::RG8_UNorm);
483
484 // THEN
485 QCOMPARE(arbiter.events.size(), 0);
486 QCOMPARE(arbiter.dirtyNodes.size(), 0);
487 }
488
489 }
490
491 void checkGenerateMipMapsUpdate()
492 {
493 // GIVEN
494 TestArbiter arbiter;
495 FakeTexture abstractTexture;
496 arbiter.setArbiterOnNode(&abstractTexture);
497
498 {
499 // WHEN
500 abstractTexture.setGenerateMipMaps(true);
501
502 // THEN
503 QCOMPARE(arbiter.events.size(), 0);
504 QCOMPARE(arbiter.dirtyNodes.size(), 1);
505 QCOMPARE(arbiter.dirtyNodes.front(), &abstractTexture);
506
507 arbiter.dirtyNodes.clear();
508 }
509
510 {
511 // WHEN
512 abstractTexture.setGenerateMipMaps(true);
513
514 // THEN
515 QCOMPARE(arbiter.events.size(), 0);
516 QCOMPARE(arbiter.dirtyNodes.size(), 0);
517 }
518
519 }
520
521 void checkWidthUpdate()
522 {
523 // GIVEN
524 TestArbiter arbiter;
525 FakeTexture abstractTexture;
526 arbiter.setArbiterOnNode(&abstractTexture);
527
528 {
529 // WHEN
530 abstractTexture.setWidth(1024);
531
532 // THEN
533 QCOMPARE(arbiter.events.size(), 0);
534 QCOMPARE(arbiter.dirtyNodes.size(), 1);
535 QCOMPARE(arbiter.dirtyNodes.front(), &abstractTexture);
536
537 arbiter.dirtyNodes.clear();
538 }
539
540 {
541 // WHEN
542 abstractTexture.setWidth(1024);
543
544 // THEN
545 QCOMPARE(arbiter.events.size(), 0);
546 QCOMPARE(arbiter.dirtyNodes.size(), 0);
547 }
548
549 }
550
551 void checkHeightUpdate()
552 {
553 // GIVEN
554 TestArbiter arbiter;
555 FakeTexture abstractTexture;
556 arbiter.setArbiterOnNode(&abstractTexture);
557
558 {
559 // WHEN
560 abstractTexture.setHeight(256);
561
562 // THEN
563 QCOMPARE(arbiter.events.size(), 0);
564 QCOMPARE(arbiter.dirtyNodes.size(), 1);
565 QCOMPARE(arbiter.dirtyNodes.front(), &abstractTexture);
566
567 arbiter.dirtyNodes.clear();
568 }
569
570 {
571 // WHEN
572 abstractTexture.setHeight(256);
573
574 // THEN
575 QCOMPARE(arbiter.events.size(), 0);
576 QCOMPARE(arbiter.dirtyNodes.size(), 0);
577 }
578
579 }
580
581 void checkDepthUpdate()
582 {
583 // GIVEN
584 TestArbiter arbiter;
585 FakeTexture abstractTexture;
586 arbiter.setArbiterOnNode(&abstractTexture);
587
588 {
589 // WHEN
590 abstractTexture.setDepth(512);
591
592 // THEN
593 QCOMPARE(arbiter.events.size(), 0);
594 QCOMPARE(arbiter.dirtyNodes.size(), 1);
595 QCOMPARE(arbiter.dirtyNodes.front(), &abstractTexture);
596
597 arbiter.dirtyNodes.clear();
598 }
599
600 {
601 // WHEN
602 abstractTexture.setDepth(512);
603
604 // THEN
605 QCOMPARE(arbiter.events.size(), 0);
606 QCOMPARE(arbiter.dirtyNodes.size(), 0);
607 }
608
609 }
610
611 void checkMagnificationFilterUpdate()
612 {
613 // GIVEN
614 TestArbiter arbiter;
615 FakeTexture abstractTexture;
616 arbiter.setArbiterOnNode(&abstractTexture);
617
618 {
619 // WHEN
620 abstractTexture.setMagnificationFilter(Qt3DRender::QAbstractTexture::NearestMipMapLinear);
621
622 // THEN
623 QCOMPARE(arbiter.events.size(), 0);
624 QCOMPARE(arbiter.dirtyNodes.size(), 1);
625 QCOMPARE(arbiter.dirtyNodes.front(), &abstractTexture);
626
627 arbiter.dirtyNodes.clear();
628 }
629
630 {
631 // WHEN
632 abstractTexture.setMagnificationFilter(Qt3DRender::QAbstractTexture::NearestMipMapLinear);
633
634 // THEN
635 QCOMPARE(arbiter.events.size(), 0);
636 QCOMPARE(arbiter.dirtyNodes.size(), 0);
637 }
638
639 }
640
641 void checkMinificationFilterUpdate()
642 {
643 // GIVEN
644 TestArbiter arbiter;
645 FakeTexture abstractTexture;
646 arbiter.setArbiterOnNode(&abstractTexture);
647
648 {
649 // WHEN
650 abstractTexture.setMinificationFilter(Qt3DRender::QAbstractTexture::NearestMipMapLinear);
651
652 // THEN
653 QCOMPARE(arbiter.events.size(), 0);
654 QCOMPARE(arbiter.dirtyNodes.size(), 1);
655 QCOMPARE(arbiter.dirtyNodes.front(), &abstractTexture);
656
657 arbiter.dirtyNodes.clear();
658 }
659
660 {
661 // WHEN
662 abstractTexture.setMinificationFilter(Qt3DRender::QAbstractTexture::NearestMipMapLinear);
663
664 // THEN
665 QCOMPARE(arbiter.events.size(), 0);
666 QCOMPARE(arbiter.dirtyNodes.size(), 0);
667 }
668
669 }
670
671 void checkMaximumAnisotropyUpdate()
672 {
673 // GIVEN
674 TestArbiter arbiter;
675 FakeTexture abstractTexture;
676 arbiter.setArbiterOnNode(&abstractTexture);
677
678 {
679 // WHEN
680 abstractTexture.setMaximumAnisotropy(327.0f);
681
682 // THEN
683 QCOMPARE(arbiter.events.size(), 0);
684 QCOMPARE(arbiter.dirtyNodes.size(), 1);
685 QCOMPARE(arbiter.dirtyNodes.front(), &abstractTexture);
686
687 arbiter.dirtyNodes.clear();
688 }
689
690 {
691 // WHEN
692 abstractTexture.setMaximumAnisotropy(327.0f);
693
694 // THEN
695 QCOMPARE(arbiter.events.size(), 0);
696 QCOMPARE(arbiter.dirtyNodes.size(), 0);
697 }
698
699 }
700
701 void checkComparisonFunctionUpdate()
702 {
703 // GIVEN
704 TestArbiter arbiter;
705 FakeTexture abstractTexture;
706 arbiter.setArbiterOnNode(&abstractTexture);
707
708 {
709 // WHEN
710 abstractTexture.setComparisonFunction(Qt3DRender::QAbstractTexture::CompareAlways);
711
712 // THEN
713 QCOMPARE(arbiter.events.size(), 0);
714 QCOMPARE(arbiter.dirtyNodes.size(), 1);
715 QCOMPARE(arbiter.dirtyNodes.front(), &abstractTexture);
716
717 arbiter.dirtyNodes.clear();
718 }
719
720 {
721 // WHEN
722 abstractTexture.setComparisonFunction(Qt3DRender::QAbstractTexture::CompareAlways);
723
724 // THEN
725 QCOMPARE(arbiter.events.size(), 0);
726 QCOMPARE(arbiter.dirtyNodes.size(), 0);
727 }
728
729 }
730
731 void checkComparisonModeUpdate()
732 {
733 // GIVEN
734 TestArbiter arbiter;
735 FakeTexture abstractTexture;
736 arbiter.setArbiterOnNode(&abstractTexture);
737
738 {
739 // WHEN
740 abstractTexture.setComparisonMode(Qt3DRender::QAbstractTexture::CompareRefToTexture);
741
742 // THEN
743 QCOMPARE(arbiter.events.size(), 0);
744 QCOMPARE(arbiter.dirtyNodes.size(), 1);
745 QCOMPARE(arbiter.dirtyNodes.front(), &abstractTexture);
746
747 arbiter.dirtyNodes.clear();
748 }
749
750 {
751 // WHEN
752 abstractTexture.setComparisonMode(Qt3DRender::QAbstractTexture::CompareRefToTexture);
753
754 // THEN
755 QCOMPARE(arbiter.events.size(), 0);
756 QCOMPARE(arbiter.dirtyNodes.size(), 0);
757 }
758
759 }
760
761 void checkLayersUpdate()
762 {
763 // GIVEN
764 TestArbiter arbiter;
765 FakeTexture abstractTexture;
766 arbiter.setArbiterOnNode(&abstractTexture);
767
768 {
769 // WHEN
770 abstractTexture.setLayers(64);
771
772 // THEN
773 QCOMPARE(arbiter.events.size(), 0);
774 QCOMPARE(arbiter.dirtyNodes.size(), 1);
775 QCOMPARE(arbiter.dirtyNodes.front(), &abstractTexture);
776
777 arbiter.dirtyNodes.clear();
778 }
779
780 {
781 // WHEN
782 abstractTexture.setLayers(64);
783
784 // THEN
785 QCOMPARE(arbiter.events.size(), 0);
786 QCOMPARE(arbiter.dirtyNodes.size(), 0);
787 }
788
789 }
790
791 void checkSamplesUpdate()
792 {
793 // GIVEN
794 TestArbiter arbiter;
795 FakeTexture abstractTexture;
796 arbiter.setArbiterOnNode(&abstractTexture);
797
798 {
799 // WHEN
800 abstractTexture.setSamples(16);
801
802 // THEN
803 QCOMPARE(arbiter.events.size(), 0);
804 QCOMPARE(arbiter.dirtyNodes.size(), 1);
805 QCOMPARE(arbiter.dirtyNodes.front(), &abstractTexture);
806
807 arbiter.dirtyNodes.clear();
808 }
809
810 {
811 // WHEN
812 abstractTexture.setSamples(16);
813
814 // THEN
815 QCOMPARE(arbiter.events.size(), 0);
816 QCOMPARE(arbiter.dirtyNodes.size(), 0);
817 }
818
819 }
820
821 void checkTextureImageAdded()
822 {
823 // GIVEN
824 TestArbiter arbiter;
825 FakeTexture abstractTexture;
826 arbiter.setArbiterOnNode(&abstractTexture);
827
828 {
829 // WHEN
830 FakeTextureImage image;
831 abstractTexture.addTextureImage(textureImage: &image);
832 QCoreApplication::processEvents();
833
834 // THEN
835 QCOMPARE(arbiter.events.size(), 0);
836 QCOMPARE(arbiter.dirtyNodes.size(), 1);
837 QCOMPARE(arbiter.dirtyNodes.front(), &abstractTexture);
838
839 arbiter.dirtyNodes.clear();
840 }
841 }
842
843 void checkTextureImageRemoved()
844 {
845 // GIVEN
846 TestArbiter arbiter;
847 FakeTexture abstractTexture;
848 FakeTextureImage image;
849 abstractTexture.addTextureImage(textureImage: &image);
850 arbiter.setArbiterOnNode(&abstractTexture);
851
852 {
853 // WHEN
854 abstractTexture.removeTextureImage(textureImage: &image);
855 QCoreApplication::processEvents();
856
857 // THEN
858 QCOMPARE(arbiter.events.size(), 0);
859 QCOMPARE(arbiter.dirtyNodes.size(), 1);
860 QCOMPARE(arbiter.dirtyNodes.front(), &abstractTexture);
861
862 arbiter.dirtyNodes.clear();
863 }
864 }
865
866 void checkSceneChangedEvent()
867 {
868 // GIVEN
869 TestArbiter arbiter;
870 FakeTexture abstractTexture;
871 arbiter.setArbiterOnNode(&abstractTexture);
872
873 qRegisterMetaType<Qt3DRender::QAbstractTexture::Status>(typeName: "Status");
874 qRegisterMetaType<Qt3DRender::QAbstractTexture::TextureFormat>(typeName: "TextureFormat");
875 qRegisterMetaType<Qt3DRender::QAbstractTexture::HandleType>(typeName: "HandleType");
876
877
878 {
879 QSignalSpy spy(&abstractTexture, SIGNAL(widthChanged(int)));
880
881 // THEN
882 QVERIFY(spy.isValid());
883
884 // WHEN
885 Qt3DCore::QPropertyUpdatedChangePtr valueChange(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::QNodeId()));
886 valueChange->setPropertyName("width");
887 valueChange->setValue(883);
888 abstractTexture.sceneChangeEvent(change: valueChange);
889
890 // THEN
891 QCOMPARE(spy.count(), 1);
892 QCOMPARE(arbiter.events.size(), 0);
893 QCOMPARE(abstractTexture.width(), 883);
894
895 // WHEN
896 spy.clear();
897 abstractTexture.sceneChangeEvent(change: valueChange);
898
899 // THEN
900 QCOMPARE(spy.count(), 0);
901 QCOMPARE(arbiter.events.size(), 0);
902 QCOMPARE(abstractTexture.width(), 883);
903 }
904
905 {
906 QSignalSpy spy(&abstractTexture, SIGNAL(heightChanged(int)));
907
908 // THEN
909 QVERIFY(spy.isValid());
910
911 // WHEN
912 Qt3DCore::QPropertyUpdatedChangePtr valueChange(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::QNodeId()));
913 valueChange->setPropertyName("height");
914 valueChange->setValue(1584);
915 abstractTexture.sceneChangeEvent(change: valueChange);
916
917 // THEN
918 QCOMPARE(spy.count(), 1);
919 QCOMPARE(arbiter.events.size(), 0);
920 QCOMPARE(abstractTexture.height(), 1584);
921
922 // WHEN
923 spy.clear();
924 abstractTexture.sceneChangeEvent(change: valueChange);
925
926 // THEN
927 QCOMPARE(spy.count(), 0);
928 QCOMPARE(arbiter.events.size(), 0);
929 QCOMPARE(abstractTexture.height(), 1584);
930 }
931
932 {
933 QSignalSpy spy(&abstractTexture, SIGNAL(depthChanged(int)));
934
935 // THEN
936 QVERIFY(spy.isValid());
937
938 // WHEN
939 Qt3DCore::QPropertyUpdatedChangePtr valueChange(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::QNodeId()));
940 valueChange->setPropertyName("depth");
941 valueChange->setValue(8);
942 abstractTexture.sceneChangeEvent(change: valueChange);
943
944 // THEN
945 QCOMPARE(spy.count(), 1);
946 QCOMPARE(arbiter.events.size(), 0);
947 QCOMPARE(abstractTexture.depth(), 8);
948
949 // WHEN
950 spy.clear();
951 abstractTexture.sceneChangeEvent(change: valueChange);
952
953 // THEN
954 QCOMPARE(spy.count(), 0);
955 QCOMPARE(arbiter.events.size(), 0);
956 QCOMPARE(abstractTexture.depth(), 8);
957 }
958
959 {
960 QSignalSpy spy(&abstractTexture, SIGNAL(layersChanged(int)));
961
962 // THEN
963 QVERIFY(spy.isValid());
964
965 // WHEN
966 Qt3DCore::QPropertyUpdatedChangePtr valueChange(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::QNodeId()));
967 valueChange->setPropertyName("layers");
968 valueChange->setValue(256);
969 abstractTexture.sceneChangeEvent(change: valueChange);
970
971 // THEN
972 QCOMPARE(spy.count(), 1);
973 QCOMPARE(arbiter.events.size(), 0);
974 QCOMPARE(abstractTexture.layers(), 256);
975
976 // WHEN
977 spy.clear();
978 abstractTexture.sceneChangeEvent(change: valueChange);
979
980 // THEN
981 QCOMPARE(spy.count(), 0);
982 QCOMPARE(arbiter.events.size(), 0);
983 QCOMPARE(abstractTexture.layers(), 256);
984 }
985
986 {
987 QSignalSpy spy(&abstractTexture, SIGNAL(formatChanged(TextureFormat)));
988
989 // THEN
990 QVERIFY(spy.isValid());
991
992 // WHEN
993 Qt3DCore::QPropertyUpdatedChangePtr valueChange(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::QNodeId()));
994 valueChange->setPropertyName("format");
995 const auto newFormat = Qt3DRender::QAbstractTexture::R8I;
996 valueChange->setValue(QVariant::fromValue(value: newFormat));
997 abstractTexture.sceneChangeEvent(change: valueChange);
998
999 // THEN
1000 QCOMPARE(spy.count(), 1);
1001 QCOMPARE(arbiter.events.size(), 0);
1002 QCOMPARE(abstractTexture.format(), newFormat);
1003
1004 // WHEN
1005 spy.clear();
1006 abstractTexture.sceneChangeEvent(change: valueChange);
1007
1008 // THEN
1009 QCOMPARE(spy.count(), 0);
1010 QCOMPARE(arbiter.events.size(), 0);
1011 QCOMPARE(abstractTexture.format(), newFormat);
1012 }
1013
1014 {
1015 QSignalSpy spy(&abstractTexture, SIGNAL(statusChanged(Status)));
1016
1017 // THEN
1018 QVERIFY(spy.isValid());
1019
1020 // WHEN
1021 Qt3DCore::QPropertyUpdatedChangePtr valueChange(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::QNodeId()));
1022 valueChange->setPropertyName("status");
1023 const auto newStatus = Qt3DRender::QAbstractTexture::Error;
1024 valueChange->setValue(QVariant::fromValue(value: newStatus));
1025 abstractTexture.sceneChangeEvent(change: valueChange);
1026
1027 // THEN
1028 QCOMPARE(spy.count(), 1);
1029 QCOMPARE(arbiter.events.size(), 0);
1030 QCOMPARE(abstractTexture.status(), newStatus);
1031
1032 // WHEN
1033 spy.clear();
1034 abstractTexture.sceneChangeEvent(change: valueChange);
1035
1036 // THEN
1037 QCOMPARE(spy.count(), 0);
1038 QCOMPARE(arbiter.events.size(), 0);
1039 QCOMPARE(abstractTexture.status(), newStatus);
1040 }
1041
1042 {
1043 QSignalSpy spy(&abstractTexture, SIGNAL(handleTypeChanged(HandleType)));
1044
1045 // THEN
1046 QVERIFY(spy.isValid());
1047
1048 // WHEN
1049 Qt3DCore::QPropertyUpdatedChangePtr valueChange(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::QNodeId()));
1050 valueChange->setPropertyName("handleType");
1051 const auto newType = Qt3DRender::QAbstractTexture::OpenGLTextureId;
1052 valueChange->setValue(QVariant::fromValue(value: newType));
1053 abstractTexture.sceneChangeEvent(change: valueChange);
1054
1055 // THEN
1056 QCOMPARE(spy.count(), 1);
1057 QCOMPARE(arbiter.events.size(), 0);
1058 QCOMPARE(abstractTexture.handleType(), newType);
1059
1060 // WHEN
1061 spy.clear();
1062 abstractTexture.sceneChangeEvent(change: valueChange);
1063
1064 // THEN
1065 QCOMPARE(spy.count(), 0);
1066 QCOMPARE(arbiter.events.size(), 0);
1067 QCOMPARE(abstractTexture.handleType(), newType);
1068 }
1069
1070 {
1071 QSignalSpy spy(&abstractTexture, SIGNAL(handleChanged(QVariant)));
1072
1073 // THEN
1074 QVERIFY(spy.isValid());
1075
1076 // WHEN
1077 Qt3DCore::QPropertyUpdatedChangePtr valueChange(new Qt3DCore::QPropertyUpdatedChange(Qt3DCore::QNodeId()));
1078 valueChange->setPropertyName("handle");
1079 valueChange->setValue(QVariant(1));
1080 abstractTexture.sceneChangeEvent(change: valueChange);
1081
1082 // THEN
1083 QCOMPARE(spy.count(), 1);
1084 QCOMPARE(arbiter.events.size(), 0);
1085 QCOMPARE(abstractTexture.handle(), QVariant(1));
1086
1087 // WHEN
1088 spy.clear();
1089 abstractTexture.sceneChangeEvent(change: valueChange);
1090
1091 // THEN
1092 QCOMPARE(spy.count(), 0);
1093 QCOMPARE(arbiter.events.size(), 0);
1094 QCOMPARE(abstractTexture.handle(), QVariant(1));
1095 }
1096 }
1097
1098 void checkTextureDataUpdate()
1099 {
1100 {
1101 // GIVEN
1102 TestArbiter arbiter;
1103 FakeTexture abstractTexture;
1104 Qt3DRender::QTextureDataUpdate update;
1105 arbiter.setArbiterOnNode(&abstractTexture);
1106
1107 // WHEN
1108 abstractTexture.updateData(update);
1109 QCoreApplication::processEvents();
1110
1111 // THEN (arbiter -> should not be stored in the initial changes but only send as a property change)
1112 auto d = static_cast<Qt3DRender::QAbstractTexturePrivate*>(Qt3DRender::QAbstractTexturePrivate::get(q: &abstractTexture));
1113 QCOMPARE(d->m_pendingDataUpdates.size(), 1);
1114 QCOMPARE(arbiter.dirtyNodes.size(), 1);
1115 QCOMPARE(arbiter.dirtyNodes.front(), &abstractTexture);
1116 }
1117 }
1118
1119};
1120
1121QTEST_MAIN(tst_QAbstractTexture)
1122
1123#include "tst_qabstracttexture.moc"
1124

source code of qt3d/tests/auto/render/qabstracttexture/tst_qabstracttexture.cpp