| 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 <QObject> |
| 6 | #include <QMetaObject> |
| 7 | #include <Qt3DRender/qrendertargetoutput.h> |
| 8 | #include <Qt3DRender/private/qrendertargetoutput_p.h> |
| 9 | #include <Qt3DRender/qabstracttexture.h> |
| 10 | #include <Qt3DRender/qtexture.h> |
| 11 | #include <QSignalSpy> |
| 12 | #include "testarbiter.h" |
| 13 | |
| 14 | class tst_QRenderTargetOutput : public QObject |
| 15 | { |
| 16 | Q_OBJECT |
| 17 | |
| 18 | private Q_SLOTS: |
| 19 | |
| 20 | void initTestCase() |
| 21 | { |
| 22 | qRegisterMetaType<Qt3DRender::QRenderTargetOutput::AttachmentPoint>("AttachmentPoint"); |
| 23 | qRegisterMetaType<Qt3DRender::QAbstractTexture::CubeMapFace>("QAbstractTexture::CubeMapFace"); |
| 24 | } |
| 25 | |
| 26 | void checkDefaultConstruction() |
| 27 | { |
| 28 | // GIVEN |
| 29 | Qt3DRender::QRenderTargetOutput renderTargetOutput; |
| 30 | |
| 31 | // THEN |
| 32 | QCOMPARE(renderTargetOutput.attachmentPoint(), Qt3DRender::QRenderTargetOutput::Color0); |
| 33 | QVERIFY(renderTargetOutput.texture() == nullptr); |
| 34 | QCOMPARE(renderTargetOutput.mipLevel(), 0); |
| 35 | QCOMPARE(renderTargetOutput.layer(), 0); |
| 36 | QCOMPARE(renderTargetOutput.face(), Qt3DRender::QAbstractTexture::CubeMapNegativeX); |
| 37 | } |
| 38 | |
| 39 | void checkPropertyChanges() |
| 40 | { |
| 41 | // GIVEN |
| 42 | Qt3DRender::QRenderTargetOutput renderTargetOutput; |
| 43 | |
| 44 | { |
| 45 | // WHEN |
| 46 | QSignalSpy spy(&renderTargetOutput, SIGNAL(attachmentPointChanged(AttachmentPoint))); |
| 47 | const Qt3DRender::QRenderTargetOutput::AttachmentPoint newValue = Qt3DRender::QRenderTargetOutput::Color15; |
| 48 | renderTargetOutput.setAttachmentPoint(newValue); |
| 49 | |
| 50 | // THEN |
| 51 | QVERIFY(spy.isValid()); |
| 52 | QCOMPARE(renderTargetOutput.attachmentPoint(), newValue); |
| 53 | QCOMPARE(spy.size(), 1); |
| 54 | |
| 55 | // WHEN |
| 56 | spy.clear(); |
| 57 | renderTargetOutput.setAttachmentPoint(newValue); |
| 58 | |
| 59 | // THEN |
| 60 | QCOMPARE(renderTargetOutput.attachmentPoint(), newValue); |
| 61 | QCOMPARE(spy.size(), 0); |
| 62 | |
| 63 | } |
| 64 | { |
| 65 | // WHEN |
| 66 | QSignalSpy spy(&renderTargetOutput, SIGNAL(textureChanged(QAbstractTexture*))); |
| 67 | Qt3DRender::QTexture3D newValue; |
| 68 | renderTargetOutput.setTexture(&newValue); |
| 69 | |
| 70 | // THEN |
| 71 | QVERIFY(spy.isValid()); |
| 72 | QCOMPARE(renderTargetOutput.texture(), &newValue); |
| 73 | QCOMPARE(spy.size(), 1); |
| 74 | |
| 75 | // WHEN |
| 76 | spy.clear(); |
| 77 | renderTargetOutput.setTexture(&newValue); |
| 78 | |
| 79 | // THEN |
| 80 | QCOMPARE(renderTargetOutput.texture(), &newValue); |
| 81 | QCOMPARE(spy.size(), 0); |
| 82 | |
| 83 | } |
| 84 | { |
| 85 | // WHEN |
| 86 | QSignalSpy spy(&renderTargetOutput, SIGNAL(mipLevelChanged(int))); |
| 87 | const int newValue = 5; |
| 88 | renderTargetOutput.setMipLevel(newValue); |
| 89 | |
| 90 | // THEN |
| 91 | QVERIFY(spy.isValid()); |
| 92 | QCOMPARE(renderTargetOutput.mipLevel(), newValue); |
| 93 | QCOMPARE(spy.size(), 1); |
| 94 | |
| 95 | // WHEN |
| 96 | spy.clear(); |
| 97 | renderTargetOutput.setMipLevel(newValue); |
| 98 | |
| 99 | // THEN |
| 100 | QCOMPARE(renderTargetOutput.mipLevel(), newValue); |
| 101 | QCOMPARE(spy.size(), 0); |
| 102 | |
| 103 | } |
| 104 | { |
| 105 | // WHEN |
| 106 | QSignalSpy spy(&renderTargetOutput, SIGNAL(layerChanged(int))); |
| 107 | const int newValue = 300; |
| 108 | renderTargetOutput.setLayer(newValue); |
| 109 | |
| 110 | // THEN |
| 111 | QVERIFY(spy.isValid()); |
| 112 | QCOMPARE(renderTargetOutput.layer(), newValue); |
| 113 | QCOMPARE(spy.size(), 1); |
| 114 | |
| 115 | // WHEN |
| 116 | spy.clear(); |
| 117 | renderTargetOutput.setLayer(newValue); |
| 118 | |
| 119 | // THEN |
| 120 | QCOMPARE(renderTargetOutput.layer(), newValue); |
| 121 | QCOMPARE(spy.size(), 0); |
| 122 | |
| 123 | } |
| 124 | { |
| 125 | // WHEN |
| 126 | QSignalSpy spy(&renderTargetOutput, SIGNAL(faceChanged(QAbstractTexture::CubeMapFace))); |
| 127 | const Qt3DRender::QAbstractTexture::CubeMapFace newValue = Qt3DRender::QAbstractTexture::CubeMapNegativeZ; |
| 128 | renderTargetOutput.setFace(newValue); |
| 129 | |
| 130 | // THEN |
| 131 | QVERIFY(spy.isValid()); |
| 132 | QCOMPARE(renderTargetOutput.face(), newValue); |
| 133 | QCOMPARE(spy.size(), 1); |
| 134 | |
| 135 | // WHEN |
| 136 | spy.clear(); |
| 137 | renderTargetOutput.setFace(newValue); |
| 138 | |
| 139 | // THEN |
| 140 | QCOMPARE(renderTargetOutput.face(), newValue); |
| 141 | QCOMPARE(spy.size(), 0); |
| 142 | |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | void checkAttachmentPointUpdate() |
| 147 | { |
| 148 | // GIVEN |
| 149 | TestArbiter arbiter; |
| 150 | Qt3DRender::QRenderTargetOutput renderTargetOutput; |
| 151 | arbiter.setArbiterOnNode(&renderTargetOutput); |
| 152 | |
| 153 | { |
| 154 | // WHEN |
| 155 | renderTargetOutput.setAttachmentPoint(Qt3DRender::QRenderTargetOutput::Color1); |
| 156 | QCoreApplication::processEvents(); |
| 157 | |
| 158 | // THEN |
| 159 | QCOMPARE(arbiter.dirtyNodes().size(), 1); |
| 160 | QCOMPARE(arbiter.dirtyNodes().front(), &renderTargetOutput); |
| 161 | |
| 162 | arbiter.clear(); |
| 163 | } |
| 164 | |
| 165 | { |
| 166 | // WHEN |
| 167 | renderTargetOutput.setAttachmentPoint(Qt3DRender::QRenderTargetOutput::Color1); |
| 168 | QCoreApplication::processEvents(); |
| 169 | |
| 170 | // THEN |
| 171 | QCOMPARE(arbiter.dirtyNodes().size(), 0); |
| 172 | } |
| 173 | |
| 174 | } |
| 175 | |
| 176 | void checkTextureUpdate() |
| 177 | { |
| 178 | // GIVEN |
| 179 | TestArbiter arbiter; |
| 180 | Qt3DRender::QRenderTargetOutput renderTargetOutput; |
| 181 | Qt3DRender::QTexture3D texture; |
| 182 | arbiter.setArbiterOnNode(&renderTargetOutput); |
| 183 | |
| 184 | { |
| 185 | // WHEN |
| 186 | renderTargetOutput.setTexture(&texture); |
| 187 | QCoreApplication::processEvents(); |
| 188 | |
| 189 | // THEN |
| 190 | QCOMPARE(arbiter.dirtyNodes().size(), 1); |
| 191 | QCOMPARE(arbiter.dirtyNodes().front(), &renderTargetOutput); |
| 192 | |
| 193 | arbiter.clear(); |
| 194 | } |
| 195 | |
| 196 | { |
| 197 | // WHEN |
| 198 | renderTargetOutput.setTexture(&texture); |
| 199 | QCoreApplication::processEvents(); |
| 200 | |
| 201 | // THEN |
| 202 | QCOMPARE(arbiter.dirtyNodes().size(), 0); |
| 203 | } |
| 204 | |
| 205 | } |
| 206 | |
| 207 | void checkMipLevelUpdate() |
| 208 | { |
| 209 | // GIVEN |
| 210 | TestArbiter arbiter; |
| 211 | Qt3DRender::QRenderTargetOutput renderTargetOutput; |
| 212 | arbiter.setArbiterOnNode(&renderTargetOutput); |
| 213 | |
| 214 | { |
| 215 | // WHEN |
| 216 | renderTargetOutput.setMipLevel(6); |
| 217 | QCoreApplication::processEvents(); |
| 218 | |
| 219 | // THEN |
| 220 | QCOMPARE(arbiter.dirtyNodes().size(), 1); |
| 221 | QCOMPARE(arbiter.dirtyNodes().front(), &renderTargetOutput); |
| 222 | |
| 223 | arbiter.clear(); |
| 224 | } |
| 225 | |
| 226 | { |
| 227 | // WHEN |
| 228 | renderTargetOutput.setMipLevel(6); |
| 229 | QCoreApplication::processEvents(); |
| 230 | |
| 231 | // THEN |
| 232 | QCOMPARE(arbiter.dirtyNodes().size(), 0); |
| 233 | } |
| 234 | |
| 235 | } |
| 236 | |
| 237 | void checkLayerUpdate() |
| 238 | { |
| 239 | // GIVEN |
| 240 | TestArbiter arbiter; |
| 241 | Qt3DRender::QRenderTargetOutput renderTargetOutput; |
| 242 | arbiter.setArbiterOnNode(&renderTargetOutput); |
| 243 | |
| 244 | { |
| 245 | // WHEN |
| 246 | renderTargetOutput.setLayer(8); |
| 247 | QCoreApplication::processEvents(); |
| 248 | |
| 249 | // THEN |
| 250 | QCOMPARE(arbiter.dirtyNodes().size(), 1); |
| 251 | QCOMPARE(arbiter.dirtyNodes().front(), &renderTargetOutput); |
| 252 | |
| 253 | arbiter.clear(); |
| 254 | } |
| 255 | |
| 256 | { |
| 257 | // WHEN |
| 258 | renderTargetOutput.setLayer(8); |
| 259 | QCoreApplication::processEvents(); |
| 260 | |
| 261 | // THEN |
| 262 | QCOMPARE(arbiter.dirtyNodes().size(), 0); |
| 263 | } |
| 264 | |
| 265 | } |
| 266 | |
| 267 | void checkFaceUpdate() |
| 268 | { |
| 269 | // GIVEN |
| 270 | TestArbiter arbiter; |
| 271 | Qt3DRender::QRenderTargetOutput renderTargetOutput; |
| 272 | arbiter.setArbiterOnNode(&renderTargetOutput); |
| 273 | |
| 274 | { |
| 275 | // WHEN |
| 276 | renderTargetOutput.setFace(Qt3DRender::QAbstractTexture::CubeMapPositiveY); |
| 277 | QCoreApplication::processEvents(); |
| 278 | |
| 279 | // THEN |
| 280 | QCOMPARE(arbiter.dirtyNodes().size(), 1); |
| 281 | QCOMPARE(arbiter.dirtyNodes().front(), &renderTargetOutput); |
| 282 | |
| 283 | arbiter.clear(); |
| 284 | } |
| 285 | |
| 286 | { |
| 287 | // WHEN |
| 288 | renderTargetOutput.setFace(Qt3DRender::QAbstractTexture::CubeMapPositiveY); |
| 289 | QCoreApplication::processEvents(); |
| 290 | |
| 291 | // THEN |
| 292 | QCOMPARE(arbiter.dirtyNodes().size(), 0); |
| 293 | } |
| 294 | |
| 295 | } |
| 296 | |
| 297 | }; |
| 298 | |
| 299 | QTEST_MAIN(tst_QRenderTargetOutput) |
| 300 | |
| 301 | #include "tst_qrendertargetoutput.moc" |