| 1 | // Copyright (C) 2016 Paul Lemire <[email protected]> |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #include <QtTest/QTest> |
| 5 | #include <Qt3DRender/qabstracttexture.h> |
| 6 | #include <Qt3DRender/private/qabstracttexture_p.h> |
| 7 | #include <QObject> |
| 8 | #include <QSignalSpy> |
| 9 | #include <Qt3DRender/qabstracttextureimage.h> |
| 10 | #include <Qt3DCore/private/qnodevisitor_p.h> |
| 11 | #include "testarbiter.h" |
| 12 | |
| 13 | class FakeTexture : public Qt3DRender::QAbstractTexture |
| 14 | { |
| 15 | public: |
| 16 | int sharedTextureId() const |
| 17 | { |
| 18 | return static_cast<Qt3DRender::QAbstractTexturePrivate *>(d_ptr.get())->m_sharedTextureId; |
| 19 | } |
| 20 | }; |
| 21 | |
| 22 | class FakeTextureImage : public Qt3DRender::QAbstractTextureImage |
| 23 | { |
| 24 | protected: |
| 25 | Qt3DRender::QTextureImageDataGeneratorPtr dataGenerator() const override |
| 26 | { |
| 27 | return Qt3DRender::QTextureImageDataGeneratorPtr(); |
| 28 | } |
| 29 | }; |
| 30 | |
| 31 | class tst_QAbstractTexture : public QObject |
| 32 | { |
| 33 | Q_OBJECT |
| 34 | |
| 35 | private Q_SLOTS: |
| 36 | |
| 37 | void initTestCase() |
| 38 | { |
| 39 | qRegisterMetaType<Qt3DRender::QAbstractTexture::TextureFormat>("TextureFormat"); |
| 40 | qRegisterMetaType<Qt3DRender::QAbstractTexture::Filter>("Filter"); |
| 41 | qRegisterMetaType<Qt3DRender::QAbstractTexture::ComparisonFunction>("ComparisonFunction"); |
| 42 | qRegisterMetaType<Qt3DRender::QAbstractTexture::ComparisonMode>("ComparisonMode"); |
| 43 | } |
| 44 | |
| 45 | void checkDefaultConstruction() |
| 46 | { |
| 47 | // GIVEN |
| 48 | FakeTexture abstractTexture; |
| 49 | |
| 50 | // THEN |
| 51 | QCOMPARE(abstractTexture.target(), Qt3DRender::QAbstractTexture::Target2D); |
| 52 | QCOMPARE(abstractTexture.format(), Qt3DRender::QAbstractTexture::Automatic); |
| 53 | QCOMPARE(abstractTexture.generateMipMaps(), false); |
| 54 | QCOMPARE(abstractTexture.wrapMode()->x(), Qt3DRender::QTextureWrapMode::ClampToEdge); |
| 55 | QCOMPARE(abstractTexture.wrapMode()->y(), Qt3DRender::QTextureWrapMode::ClampToEdge); |
| 56 | QCOMPARE(abstractTexture.wrapMode()->z(), Qt3DRender::QTextureWrapMode::ClampToEdge); |
| 57 | QCOMPARE(abstractTexture.status(), Qt3DRender::QAbstractTexture::None); |
| 58 | QCOMPARE(abstractTexture.width(), 1); |
| 59 | QCOMPARE(abstractTexture.height(), 1); |
| 60 | QCOMPARE(abstractTexture.depth(), 1); |
| 61 | QCOMPARE(abstractTexture.magnificationFilter(), Qt3DRender::QAbstractTexture::Nearest); |
| 62 | QCOMPARE(abstractTexture.minificationFilter(), Qt3DRender::QAbstractTexture::Nearest); |
| 63 | QCOMPARE(abstractTexture.mipLevels(), 1); |
| 64 | QCOMPARE(abstractTexture.maximumAnisotropy(), 1.0f); |
| 65 | QCOMPARE(abstractTexture.comparisonFunction(), Qt3DRender::QAbstractTexture::CompareLessEqual); |
| 66 | QCOMPARE(abstractTexture.comparisonMode(), Qt3DRender::QAbstractTexture::CompareNone); |
| 67 | QCOMPARE(abstractTexture.layers(), 1); |
| 68 | QCOMPARE(abstractTexture.samples(), 1); |
| 69 | QCOMPARE(abstractTexture.textureImages().size(), 0); |
| 70 | QCOMPARE(abstractTexture.samples(), 1); |
| 71 | QCOMPARE(abstractTexture.sharedTextureId(), -1); |
| 72 | QCOMPARE(abstractTexture.handleType(), Qt3DRender::QAbstractTexture::NoHandle); |
| 73 | QCOMPARE(abstractTexture.handle(), QVariant()); |
| 74 | } |
| 75 | |
| 76 | void checkPropertyChanges() |
| 77 | { |
| 78 | // GIVEN |
| 79 | FakeTexture abstractTexture; |
| 80 | |
| 81 | { |
| 82 | // WHEN |
| 83 | QSignalSpy spy(&abstractTexture, SIGNAL(formatChanged(TextureFormat))); |
| 84 | const Qt3DRender::QAbstractTexture::TextureFormat newValue = Qt3DRender::QAbstractTexture::R8I; |
| 85 | abstractTexture.setFormat(newValue); |
| 86 | |
| 87 | // THEN |
| 88 | QVERIFY(spy.isValid()); |
| 89 | QCOMPARE(abstractTexture.format(), newValue); |
| 90 | QCOMPARE(spy.size(), 1); |
| 91 | |
| 92 | // WHEN |
| 93 | spy.clear(); |
| 94 | abstractTexture.setFormat(newValue); |
| 95 | |
| 96 | // THEN |
| 97 | QCOMPARE(abstractTexture.format(), newValue); |
| 98 | QCOMPARE(spy.size(), 0); |
| 99 | } |
| 100 | { |
| 101 | // WHEN |
| 102 | QSignalSpy spy(&abstractTexture, SIGNAL(generateMipMapsChanged(bool))); |
| 103 | const bool newValue = true; |
| 104 | abstractTexture.setGenerateMipMaps(newValue); |
| 105 | |
| 106 | // THEN |
| 107 | QVERIFY(spy.isValid()); |
| 108 | QCOMPARE(abstractTexture.generateMipMaps(), newValue); |
| 109 | QCOMPARE(spy.size(), 1); |
| 110 | |
| 111 | // WHEN |
| 112 | spy.clear(); |
| 113 | abstractTexture.setGenerateMipMaps(newValue); |
| 114 | |
| 115 | // THEN |
| 116 | QCOMPARE(abstractTexture.generateMipMaps(), newValue); |
| 117 | QCOMPARE(spy.size(), 0); |
| 118 | } |
| 119 | { |
| 120 | // WHEN |
| 121 | QSignalSpy spy(&abstractTexture, SIGNAL(widthChanged(int))); |
| 122 | const int newValue = 383; |
| 123 | abstractTexture.setWidth(newValue); |
| 124 | |
| 125 | // THEN |
| 126 | QVERIFY(spy.isValid()); |
| 127 | QCOMPARE(abstractTexture.width(), newValue); |
| 128 | QCOMPARE(spy.size(), 1); |
| 129 | |
| 130 | // WHEN |
| 131 | spy.clear(); |
| 132 | abstractTexture.setWidth(newValue); |
| 133 | |
| 134 | // THEN |
| 135 | QCOMPARE(abstractTexture.width(), newValue); |
| 136 | QCOMPARE(spy.size(), 0); |
| 137 | } |
| 138 | { |
| 139 | // WHEN |
| 140 | QSignalSpy spy(&abstractTexture, SIGNAL(heightChanged(int))); |
| 141 | const int newValue = 427; |
| 142 | abstractTexture.setHeight(newValue); |
| 143 | |
| 144 | // THEN |
| 145 | QVERIFY(spy.isValid()); |
| 146 | QCOMPARE(abstractTexture.height(), newValue); |
| 147 | QCOMPARE(spy.size(), 1); |
| 148 | |
| 149 | // WHEN |
| 150 | spy.clear(); |
| 151 | abstractTexture.setHeight(newValue); |
| 152 | |
| 153 | // THEN |
| 154 | QCOMPARE(abstractTexture.height(), newValue); |
| 155 | QCOMPARE(spy.size(), 0); |
| 156 | } |
| 157 | { |
| 158 | // WHEN |
| 159 | QSignalSpy spy(&abstractTexture, SIGNAL(depthChanged(int))); |
| 160 | const int newValue = 454; |
| 161 | abstractTexture.setDepth(newValue); |
| 162 | |
| 163 | // THEN |
| 164 | QVERIFY(spy.isValid()); |
| 165 | QCOMPARE(abstractTexture.depth(), newValue); |
| 166 | QCOMPARE(spy.size(), 1); |
| 167 | |
| 168 | // WHEN |
| 169 | spy.clear(); |
| 170 | abstractTexture.setDepth(newValue); |
| 171 | |
| 172 | // THEN |
| 173 | QCOMPARE(abstractTexture.depth(), newValue); |
| 174 | QCOMPARE(spy.size(), 0); |
| 175 | } |
| 176 | { |
| 177 | // WHEN |
| 178 | QSignalSpy spy(&abstractTexture, SIGNAL(magnificationFilterChanged(Qt3DRender::QAbstractTexture::Filter))); |
| 179 | const Qt3DRender::QAbstractTexture::Filter newValue = Qt3DRender::QAbstractTexture::LinearMipMapLinear; |
| 180 | abstractTexture.setMagnificationFilter(newValue); |
| 181 | |
| 182 | // THEN |
| 183 | QVERIFY(spy.isValid()); |
| 184 | QCOMPARE(abstractTexture.magnificationFilter(), newValue); |
| 185 | QCOMPARE(spy.size(), 1); |
| 186 | |
| 187 | // WHEN |
| 188 | spy.clear(); |
| 189 | abstractTexture.setMagnificationFilter(newValue); |
| 190 | |
| 191 | // THEN |
| 192 | QCOMPARE(abstractTexture.magnificationFilter(), newValue); |
| 193 | QCOMPARE(spy.size(), 0); |
| 194 | } |
| 195 | { |
| 196 | // WHEN |
| 197 | QSignalSpy spy(&abstractTexture, SIGNAL(minificationFilterChanged(Filter))); |
| 198 | const Qt3DRender::QAbstractTexture::Filter newValue = Qt3DRender::QAbstractTexture::LinearMipMapNearest; |
| 199 | abstractTexture.setMinificationFilter(newValue); |
| 200 | |
| 201 | // THEN |
| 202 | QVERIFY(spy.isValid()); |
| 203 | QCOMPARE(abstractTexture.minificationFilter(), newValue); |
| 204 | QCOMPARE(spy.size(), 1); |
| 205 | |
| 206 | // WHEN |
| 207 | spy.clear(); |
| 208 | abstractTexture.setMinificationFilter(newValue); |
| 209 | |
| 210 | // THEN |
| 211 | QCOMPARE(abstractTexture.minificationFilter(), newValue); |
| 212 | QCOMPARE(spy.size(), 0); |
| 213 | } |
| 214 | { |
| 215 | // WHEN |
| 216 | QSignalSpy spy(&abstractTexture, SIGNAL(maximumAnisotropyChanged(float))); |
| 217 | const float newValue = 100.0f; |
| 218 | abstractTexture.setMaximumAnisotropy(newValue); |
| 219 | |
| 220 | // THEN |
| 221 | QVERIFY(spy.isValid()); |
| 222 | QCOMPARE(abstractTexture.maximumAnisotropy(), newValue); |
| 223 | QCOMPARE(spy.size(), 1); |
| 224 | |
| 225 | // WHEN |
| 226 | spy.clear(); |
| 227 | abstractTexture.setMaximumAnisotropy(newValue); |
| 228 | |
| 229 | // THEN |
| 230 | QCOMPARE(abstractTexture.maximumAnisotropy(), newValue); |
| 231 | QCOMPARE(spy.size(), 0); |
| 232 | } |
| 233 | { |
| 234 | // WHEN |
| 235 | QSignalSpy spy(&abstractTexture, SIGNAL(comparisonFunctionChanged(Qt3DRender::QAbstractTexture::ComparisonFunction))); |
| 236 | const Qt3DRender::QAbstractTexture::ComparisonFunction newValue = Qt3DRender::QAbstractTexture::CompareGreaterEqual; |
| 237 | abstractTexture.setComparisonFunction(newValue); |
| 238 | |
| 239 | // THEN |
| 240 | QVERIFY(spy.isValid()); |
| 241 | QCOMPARE(abstractTexture.comparisonFunction(), newValue); |
| 242 | QCOMPARE(spy.size(), 1); |
| 243 | |
| 244 | // WHEN |
| 245 | spy.clear(); |
| 246 | abstractTexture.setComparisonFunction(newValue); |
| 247 | |
| 248 | // THEN |
| 249 | QCOMPARE(abstractTexture.comparisonFunction(), newValue); |
| 250 | QCOMPARE(spy.size(), 0); |
| 251 | } |
| 252 | { |
| 253 | // WHEN |
| 254 | QSignalSpy spy(&abstractTexture, SIGNAL(comparisonModeChanged(Qt3DRender::QAbstractTexture::ComparisonMode))); |
| 255 | const Qt3DRender::QAbstractTexture::ComparisonMode newValue = Qt3DRender::QAbstractTexture::CompareRefToTexture; |
| 256 | abstractTexture.setComparisonMode(newValue); |
| 257 | |
| 258 | // THEN |
| 259 | QVERIFY(spy.isValid()); |
| 260 | QCOMPARE(abstractTexture.comparisonMode(), newValue); |
| 261 | QCOMPARE(spy.size(), 1); |
| 262 | |
| 263 | // WHEN |
| 264 | spy.clear(); |
| 265 | abstractTexture.setComparisonMode(newValue); |
| 266 | |
| 267 | // THEN |
| 268 | QCOMPARE(abstractTexture.comparisonMode(), newValue); |
| 269 | QCOMPARE(spy.size(), 0); |
| 270 | } |
| 271 | { |
| 272 | // WHEN |
| 273 | QSignalSpy spy(&abstractTexture, SIGNAL(layersChanged(int))); |
| 274 | const int newValue = 512; |
| 275 | abstractTexture.setLayers(newValue); |
| 276 | |
| 277 | // THEN |
| 278 | QVERIFY(spy.isValid()); |
| 279 | QCOMPARE(abstractTexture.layers(), newValue); |
| 280 | QCOMPARE(spy.size(), 1); |
| 281 | |
| 282 | // WHEN |
| 283 | spy.clear(); |
| 284 | abstractTexture.setLayers(newValue); |
| 285 | |
| 286 | // THEN |
| 287 | QCOMPARE(abstractTexture.layers(), newValue); |
| 288 | QCOMPARE(spy.size(), 0); |
| 289 | } |
| 290 | { |
| 291 | // WHEN |
| 292 | QSignalSpy spy(&abstractTexture, SIGNAL(samplesChanged(int))); |
| 293 | const int newValue = 1024; |
| 294 | abstractTexture.setSamples(newValue); |
| 295 | |
| 296 | // THEN |
| 297 | QVERIFY(spy.isValid()); |
| 298 | QCOMPARE(abstractTexture.samples(), newValue); |
| 299 | QCOMPARE(spy.size(), 1); |
| 300 | |
| 301 | // WHEN |
| 302 | spy.clear(); |
| 303 | abstractTexture.setSamples(newValue); |
| 304 | |
| 305 | // THEN |
| 306 | QCOMPARE(abstractTexture.samples(), newValue); |
| 307 | QCOMPARE(spy.size(), 0); |
| 308 | } |
| 309 | { |
| 310 | // WHEN |
| 311 | QSignalSpy spy(&abstractTexture, SIGNAL(mipLevelsChanged(int))); |
| 312 | const int newValue = 1024; |
| 313 | abstractTexture.setMipLevels(newValue); |
| 314 | |
| 315 | // THEN |
| 316 | QVERIFY(spy.isValid()); |
| 317 | QCOMPARE(abstractTexture.mipLevels(), newValue); |
| 318 | QCOMPARE(spy.size(), 1); |
| 319 | |
| 320 | // WHEN |
| 321 | spy.clear(); |
| 322 | abstractTexture.setMipLevels(newValue); |
| 323 | |
| 324 | // THEN |
| 325 | QCOMPARE(abstractTexture.mipLevels(), newValue); |
| 326 | QCOMPARE(spy.size(), 0); |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | void checkFormatUpdate() |
| 331 | { |
| 332 | // GIVEN |
| 333 | TestArbiter arbiter; |
| 334 | FakeTexture abstractTexture; |
| 335 | arbiter.setArbiterOnNode(&abstractTexture); |
| 336 | |
| 337 | { |
| 338 | // WHEN |
| 339 | abstractTexture.setFormat(Qt3DRender::QAbstractTexture::RG8_UNorm); |
| 340 | |
| 341 | // THEN |
| 342 | QCOMPARE(arbiter.dirtyNodes().size(), 1); |
| 343 | QCOMPARE(arbiter.dirtyNodes().front(), &abstractTexture); |
| 344 | |
| 345 | arbiter.clear(); |
| 346 | } |
| 347 | |
| 348 | { |
| 349 | // WHEN |
| 350 | abstractTexture.setFormat(Qt3DRender::QAbstractTexture::RG8_UNorm); |
| 351 | |
| 352 | // THEN |
| 353 | QCOMPARE(arbiter.dirtyNodes().size(), 0); |
| 354 | } |
| 355 | |
| 356 | } |
| 357 | |
| 358 | void checkGenerateMipMapsUpdate() |
| 359 | { |
| 360 | // GIVEN |
| 361 | TestArbiter arbiter; |
| 362 | FakeTexture abstractTexture; |
| 363 | arbiter.setArbiterOnNode(&abstractTexture); |
| 364 | |
| 365 | { |
| 366 | // WHEN |
| 367 | abstractTexture.setGenerateMipMaps(true); |
| 368 | |
| 369 | // THEN |
| 370 | QCOMPARE(arbiter.dirtyNodes().size(), 1); |
| 371 | QCOMPARE(arbiter.dirtyNodes().front(), &abstractTexture); |
| 372 | |
| 373 | arbiter.clear(); |
| 374 | } |
| 375 | |
| 376 | { |
| 377 | // WHEN |
| 378 | abstractTexture.setGenerateMipMaps(true); |
| 379 | |
| 380 | // THEN |
| 381 | QCOMPARE(arbiter.dirtyNodes().size(), 0); |
| 382 | } |
| 383 | |
| 384 | } |
| 385 | |
| 386 | void checkWidthUpdate() |
| 387 | { |
| 388 | // GIVEN |
| 389 | TestArbiter arbiter; |
| 390 | FakeTexture abstractTexture; |
| 391 | arbiter.setArbiterOnNode(&abstractTexture); |
| 392 | |
| 393 | { |
| 394 | // WHEN |
| 395 | abstractTexture.setWidth(1024); |
| 396 | |
| 397 | // THEN |
| 398 | QCOMPARE(arbiter.dirtyNodes().size(), 1); |
| 399 | QCOMPARE(arbiter.dirtyNodes().front(), &abstractTexture); |
| 400 | |
| 401 | arbiter.clear(); |
| 402 | } |
| 403 | |
| 404 | { |
| 405 | // WHEN |
| 406 | abstractTexture.setWidth(1024); |
| 407 | |
| 408 | // THEN |
| 409 | QCOMPARE(arbiter.dirtyNodes().size(), 0); |
| 410 | } |
| 411 | |
| 412 | } |
| 413 | |
| 414 | void checkHeightUpdate() |
| 415 | { |
| 416 | // GIVEN |
| 417 | TestArbiter arbiter; |
| 418 | FakeTexture abstractTexture; |
| 419 | arbiter.setArbiterOnNode(&abstractTexture); |
| 420 | |
| 421 | { |
| 422 | // WHEN |
| 423 | abstractTexture.setHeight(256); |
| 424 | |
| 425 | // THEN |
| 426 | QCOMPARE(arbiter.dirtyNodes().size(), 1); |
| 427 | QCOMPARE(arbiter.dirtyNodes().front(), &abstractTexture); |
| 428 | |
| 429 | arbiter.clear(); |
| 430 | } |
| 431 | |
| 432 | { |
| 433 | // WHEN |
| 434 | abstractTexture.setHeight(256); |
| 435 | |
| 436 | // THEN |
| 437 | QCOMPARE(arbiter.dirtyNodes().size(), 0); |
| 438 | } |
| 439 | |
| 440 | } |
| 441 | |
| 442 | void checkDepthUpdate() |
| 443 | { |
| 444 | // GIVEN |
| 445 | TestArbiter arbiter; |
| 446 | FakeTexture abstractTexture; |
| 447 | arbiter.setArbiterOnNode(&abstractTexture); |
| 448 | |
| 449 | { |
| 450 | // WHEN |
| 451 | abstractTexture.setDepth(512); |
| 452 | |
| 453 | // THEN |
| 454 | QCOMPARE(arbiter.dirtyNodes().size(), 1); |
| 455 | QCOMPARE(arbiter.dirtyNodes().front(), &abstractTexture); |
| 456 | |
| 457 | arbiter.clear(); |
| 458 | } |
| 459 | |
| 460 | { |
| 461 | // WHEN |
| 462 | abstractTexture.setDepth(512); |
| 463 | |
| 464 | // THEN |
| 465 | QCOMPARE(arbiter.dirtyNodes().size(), 0); |
| 466 | } |
| 467 | |
| 468 | } |
| 469 | |
| 470 | void checkMagnificationFilterUpdate() |
| 471 | { |
| 472 | // GIVEN |
| 473 | TestArbiter arbiter; |
| 474 | FakeTexture abstractTexture; |
| 475 | arbiter.setArbiterOnNode(&abstractTexture); |
| 476 | |
| 477 | { |
| 478 | // WHEN |
| 479 | abstractTexture.setMagnificationFilter(Qt3DRender::QAbstractTexture::NearestMipMapLinear); |
| 480 | |
| 481 | // THEN |
| 482 | QCOMPARE(arbiter.dirtyNodes().size(), 1); |
| 483 | QCOMPARE(arbiter.dirtyNodes().front(), &abstractTexture); |
| 484 | |
| 485 | arbiter.clear(); |
| 486 | } |
| 487 | |
| 488 | { |
| 489 | // WHEN |
| 490 | abstractTexture.setMagnificationFilter(Qt3DRender::QAbstractTexture::NearestMipMapLinear); |
| 491 | |
| 492 | // THEN |
| 493 | QCOMPARE(arbiter.dirtyNodes().size(), 0); |
| 494 | } |
| 495 | |
| 496 | } |
| 497 | |
| 498 | void checkMinificationFilterUpdate() |
| 499 | { |
| 500 | // GIVEN |
| 501 | TestArbiter arbiter; |
| 502 | FakeTexture abstractTexture; |
| 503 | arbiter.setArbiterOnNode(&abstractTexture); |
| 504 | |
| 505 | { |
| 506 | // WHEN |
| 507 | abstractTexture.setMinificationFilter(Qt3DRender::QAbstractTexture::NearestMipMapLinear); |
| 508 | |
| 509 | // THEN |
| 510 | QCOMPARE(arbiter.dirtyNodes().size(), 1); |
| 511 | QCOMPARE(arbiter.dirtyNodes().front(), &abstractTexture); |
| 512 | |
| 513 | arbiter.clear(); |
| 514 | } |
| 515 | |
| 516 | { |
| 517 | // WHEN |
| 518 | abstractTexture.setMinificationFilter(Qt3DRender::QAbstractTexture::NearestMipMapLinear); |
| 519 | |
| 520 | // THEN |
| 521 | QCOMPARE(arbiter.dirtyNodes().size(), 0); |
| 522 | } |
| 523 | |
| 524 | } |
| 525 | |
| 526 | void checkMaximumAnisotropyUpdate() |
| 527 | { |
| 528 | // GIVEN |
| 529 | TestArbiter arbiter; |
| 530 | FakeTexture abstractTexture; |
| 531 | arbiter.setArbiterOnNode(&abstractTexture); |
| 532 | |
| 533 | { |
| 534 | // WHEN |
| 535 | abstractTexture.setMaximumAnisotropy(327.0f); |
| 536 | |
| 537 | // THEN |
| 538 | QCOMPARE(arbiter.dirtyNodes().size(), 1); |
| 539 | QCOMPARE(arbiter.dirtyNodes().front(), &abstractTexture); |
| 540 | |
| 541 | arbiter.clear(); |
| 542 | } |
| 543 | |
| 544 | { |
| 545 | // WHEN |
| 546 | abstractTexture.setMaximumAnisotropy(327.0f); |
| 547 | |
| 548 | // THEN |
| 549 | QCOMPARE(arbiter.dirtyNodes().size(), 0); |
| 550 | } |
| 551 | |
| 552 | } |
| 553 | |
| 554 | void checkComparisonFunctionUpdate() |
| 555 | { |
| 556 | // GIVEN |
| 557 | TestArbiter arbiter; |
| 558 | FakeTexture abstractTexture; |
| 559 | arbiter.setArbiterOnNode(&abstractTexture); |
| 560 | |
| 561 | { |
| 562 | // WHEN |
| 563 | abstractTexture.setComparisonFunction(Qt3DRender::QAbstractTexture::CompareAlways); |
| 564 | |
| 565 | // THEN |
| 566 | QCOMPARE(arbiter.dirtyNodes().size(), 1); |
| 567 | QCOMPARE(arbiter.dirtyNodes().front(), &abstractTexture); |
| 568 | |
| 569 | arbiter.clear(); |
| 570 | } |
| 571 | |
| 572 | { |
| 573 | // WHEN |
| 574 | abstractTexture.setComparisonFunction(Qt3DRender::QAbstractTexture::CompareAlways); |
| 575 | |
| 576 | // THEN |
| 577 | QCOMPARE(arbiter.dirtyNodes().size(), 0); |
| 578 | } |
| 579 | |
| 580 | } |
| 581 | |
| 582 | void checkComparisonModeUpdate() |
| 583 | { |
| 584 | // GIVEN |
| 585 | TestArbiter arbiter; |
| 586 | FakeTexture abstractTexture; |
| 587 | arbiter.setArbiterOnNode(&abstractTexture); |
| 588 | |
| 589 | { |
| 590 | // WHEN |
| 591 | abstractTexture.setComparisonMode(Qt3DRender::QAbstractTexture::CompareRefToTexture); |
| 592 | |
| 593 | // THEN |
| 594 | QCOMPARE(arbiter.dirtyNodes().size(), 1); |
| 595 | QCOMPARE(arbiter.dirtyNodes().front(), &abstractTexture); |
| 596 | |
| 597 | arbiter.clear(); |
| 598 | } |
| 599 | |
| 600 | { |
| 601 | // WHEN |
| 602 | abstractTexture.setComparisonMode(Qt3DRender::QAbstractTexture::CompareRefToTexture); |
| 603 | |
| 604 | // THEN |
| 605 | QCOMPARE(arbiter.dirtyNodes().size(), 0); |
| 606 | } |
| 607 | |
| 608 | } |
| 609 | |
| 610 | void checkLayersUpdate() |
| 611 | { |
| 612 | // GIVEN |
| 613 | TestArbiter arbiter; |
| 614 | FakeTexture abstractTexture; |
| 615 | arbiter.setArbiterOnNode(&abstractTexture); |
| 616 | |
| 617 | { |
| 618 | // WHEN |
| 619 | abstractTexture.setLayers(64); |
| 620 | |
| 621 | // THEN |
| 622 | QCOMPARE(arbiter.dirtyNodes().size(), 1); |
| 623 | QCOMPARE(arbiter.dirtyNodes().front(), &abstractTexture); |
| 624 | |
| 625 | arbiter.clear(); |
| 626 | } |
| 627 | |
| 628 | { |
| 629 | // WHEN |
| 630 | abstractTexture.setLayers(64); |
| 631 | |
| 632 | // THEN |
| 633 | QCOMPARE(arbiter.dirtyNodes().size(), 0); |
| 634 | } |
| 635 | |
| 636 | } |
| 637 | |
| 638 | void checkSamplesUpdate() |
| 639 | { |
| 640 | // GIVEN |
| 641 | TestArbiter arbiter; |
| 642 | FakeTexture abstractTexture; |
| 643 | arbiter.setArbiterOnNode(&abstractTexture); |
| 644 | |
| 645 | { |
| 646 | // WHEN |
| 647 | abstractTexture.setSamples(16); |
| 648 | |
| 649 | // THEN |
| 650 | QCOMPARE(arbiter.dirtyNodes().size(), 1); |
| 651 | QCOMPARE(arbiter.dirtyNodes().front(), &abstractTexture); |
| 652 | |
| 653 | arbiter.clear(); |
| 654 | } |
| 655 | |
| 656 | { |
| 657 | // WHEN |
| 658 | abstractTexture.setSamples(16); |
| 659 | |
| 660 | // THEN |
| 661 | QCOMPARE(arbiter.dirtyNodes().size(), 0); |
| 662 | } |
| 663 | |
| 664 | } |
| 665 | |
| 666 | void checkMipLevelsUpdate() |
| 667 | { |
| 668 | // GIVEN |
| 669 | TestArbiter arbiter; |
| 670 | FakeTexture abstractTexture; |
| 671 | arbiter.setArbiterOnNode(&abstractTexture); |
| 672 | |
| 673 | { |
| 674 | // WHEN |
| 675 | abstractTexture.setMipLevels(16); |
| 676 | |
| 677 | // THEN |
| 678 | QCOMPARE(arbiter.dirtyNodes().size(), 1); |
| 679 | QCOMPARE(arbiter.dirtyNodes().front(), &abstractTexture); |
| 680 | |
| 681 | arbiter.clear(); |
| 682 | } |
| 683 | |
| 684 | { |
| 685 | // WHEN |
| 686 | abstractTexture.setMipLevels(16); |
| 687 | |
| 688 | // THEN |
| 689 | QCOMPARE(arbiter.dirtyNodes().size(), 0); |
| 690 | } |
| 691 | } |
| 692 | |
| 693 | void checkTextureImageAdded() |
| 694 | { |
| 695 | // GIVEN |
| 696 | TestArbiter arbiter; |
| 697 | FakeTexture abstractTexture; |
| 698 | arbiter.setArbiterOnNode(&abstractTexture); |
| 699 | |
| 700 | { |
| 701 | // WHEN |
| 702 | FakeTextureImage image; |
| 703 | abstractTexture.addTextureImage(&image); |
| 704 | QCoreApplication::processEvents(); |
| 705 | |
| 706 | // THEN |
| 707 | QCOMPARE(arbiter.dirtyNodes().size(), 1); |
| 708 | QCOMPARE(arbiter.dirtyNodes().front(), &abstractTexture); |
| 709 | |
| 710 | arbiter.clear(); |
| 711 | } |
| 712 | } |
| 713 | |
| 714 | void checkTextureImageRemoved() |
| 715 | { |
| 716 | // GIVEN |
| 717 | TestArbiter arbiter; |
| 718 | FakeTexture abstractTexture; |
| 719 | FakeTextureImage image; |
| 720 | abstractTexture.addTextureImage(&image); |
| 721 | arbiter.setArbiterOnNode(&abstractTexture); |
| 722 | |
| 723 | { |
| 724 | // WHEN |
| 725 | abstractTexture.removeTextureImage(&image); |
| 726 | QCoreApplication::processEvents(); |
| 727 | |
| 728 | // THEN |
| 729 | QCOMPARE(arbiter.dirtyNodes().size(), 1); |
| 730 | QCOMPARE(arbiter.dirtyNodes().front(), &abstractTexture); |
| 731 | |
| 732 | arbiter.clear(); |
| 733 | } |
| 734 | } |
| 735 | |
| 736 | void checkSceneChangedEvent() |
| 737 | { |
| 738 | // GIVEN |
| 739 | TestArbiter arbiter; |
| 740 | FakeTexture abstractTexture; |
| 741 | arbiter.setArbiterOnNode(&abstractTexture); |
| 742 | |
| 743 | qRegisterMetaType<Qt3DRender::QAbstractTexture::Status>("Status"); |
| 744 | qRegisterMetaType<Qt3DRender::QAbstractTexture::TextureFormat>("TextureFormat"); |
| 745 | qRegisterMetaType<Qt3DRender::QAbstractTexture::HandleType>("HandleType"); |
| 746 | |
| 747 | { |
| 748 | QSignalSpy spy(&abstractTexture, SIGNAL(statusChanged(Status))); |
| 749 | |
| 750 | // THEN |
| 751 | QVERIFY(spy.isValid()); |
| 752 | |
| 753 | // WHEN |
| 754 | auto *dTexture = static_cast<Qt3DRender::QAbstractTexturePrivate *>(Qt3DCore::QNodePrivate::get(&abstractTexture)); |
| 755 | const auto newStatus = Qt3DRender::QAbstractTexture::Error; |
| 756 | dTexture->setStatus(newStatus); |
| 757 | |
| 758 | // THEN |
| 759 | QCOMPARE(spy.size(), 1); |
| 760 | QCOMPARE(arbiter.dirtyNodes().size(), 0); |
| 761 | QCOMPARE(abstractTexture.status(), newStatus); |
| 762 | |
| 763 | // WHEN |
| 764 | spy.clear(); |
| 765 | arbiter.clear(); |
| 766 | dTexture->setStatus(newStatus); |
| 767 | |
| 768 | // THEN |
| 769 | QCOMPARE(spy.size(), 0); |
| 770 | QCOMPARE(arbiter.dirtyNodes().size(), 0); |
| 771 | QCOMPARE(abstractTexture.status(), newStatus); |
| 772 | } |
| 773 | |
| 774 | { |
| 775 | QSignalSpy spy(&abstractTexture, SIGNAL(handleTypeChanged(HandleType))); |
| 776 | |
| 777 | // THEN |
| 778 | QVERIFY(spy.isValid()); |
| 779 | |
| 780 | // WHEN |
| 781 | auto *dTexture = static_cast<Qt3DRender::QAbstractTexturePrivate *>(Qt3DCore::QNodePrivate::get(&abstractTexture)); |
| 782 | const auto newType = Qt3DRender::QAbstractTexture::OpenGLTextureId; |
| 783 | dTexture->setHandleType(newType); |
| 784 | |
| 785 | // THEN |
| 786 | QCOMPARE(spy.size(), 1); |
| 787 | QCOMPARE(arbiter.dirtyNodes().size(), 0); |
| 788 | QCOMPARE(abstractTexture.handleType(), newType); |
| 789 | |
| 790 | // WHEN |
| 791 | spy.clear(); |
| 792 | arbiter.clear(); |
| 793 | dTexture->setHandleType(newType); |
| 794 | |
| 795 | // THEN |
| 796 | QCOMPARE(spy.size(), 0); |
| 797 | QCOMPARE(arbiter.dirtyNodes().size(), 0); |
| 798 | QCOMPARE(abstractTexture.handleType(), newType); |
| 799 | } |
| 800 | |
| 801 | { |
| 802 | QSignalSpy spy(&abstractTexture, SIGNAL(handleChanged(QVariant))); |
| 803 | |
| 804 | // THEN |
| 805 | QVERIFY(spy.isValid()); |
| 806 | |
| 807 | // WHEN |
| 808 | auto *dTexture = static_cast<Qt3DRender::QAbstractTexturePrivate *>(Qt3DCore::QNodePrivate::get(&abstractTexture)); |
| 809 | dTexture->setHandle(QVariant(1)); |
| 810 | |
| 811 | // THEN |
| 812 | QCOMPARE(spy.size(), 1); |
| 813 | QCOMPARE(abstractTexture.handle(), QVariant(1)); |
| 814 | |
| 815 | // WHEN |
| 816 | spy.clear(); |
| 817 | arbiter.clear(); |
| 818 | dTexture->setHandle(QVariant(1)); |
| 819 | |
| 820 | // THEN |
| 821 | QCOMPARE(spy.size(), 0); |
| 822 | QCOMPARE(arbiter.dirtyNodes().size(), 0); |
| 823 | QCOMPARE(abstractTexture.handle(), QVariant(1)); |
| 824 | } |
| 825 | } |
| 826 | |
| 827 | void checkTextureDataUpdate() |
| 828 | { |
| 829 | { |
| 830 | // GIVEN |
| 831 | TestArbiter arbiter; |
| 832 | FakeTexture abstractTexture; |
| 833 | Qt3DRender::QTextureDataUpdate update; |
| 834 | arbiter.setArbiterOnNode(&abstractTexture); |
| 835 | |
| 836 | // WHEN |
| 837 | abstractTexture.updateData(update); |
| 838 | QCoreApplication::processEvents(); |
| 839 | |
| 840 | // THEN (arbiter -> should not be stored in the initial changes but only send as a property change) |
| 841 | auto d = static_cast<Qt3DRender::QAbstractTexturePrivate*>(Qt3DRender::QAbstractTexturePrivate::get(&abstractTexture)); |
| 842 | QCOMPARE(d->m_pendingDataUpdates.size(), 1); |
| 843 | QCOMPARE(arbiter.dirtyNodes().size(), 1); |
| 844 | QCOMPARE(arbiter.dirtyNodes().front(), &abstractTexture); |
| 845 | } |
| 846 | } |
| 847 | |
| 848 | }; |
| 849 | |
| 850 | QTEST_MAIN(tst_QAbstractTexture) |
| 851 | |
| 852 | #include "tst_qabstracttexture.moc" |