1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). |
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 | |
30 | #include <QtTest/QTest> |
31 | #include <Qt3DRender/qblitframebuffer.h> |
32 | #include <Qt3DRender/private/qblitframebuffer_p.h> |
33 | #include <Qt3DRender/private/blitframebuffer_p.h> |
34 | #include "qbackendnodetester.h" |
35 | #include "testrenderer.h" |
36 | |
37 | class tst_BlitFramebuffer : public Qt3DCore::QBackendNodeTester |
38 | { |
39 | Q_OBJECT |
40 | |
41 | private Q_SLOTS: |
42 | |
43 | void checkInitialState() |
44 | { |
45 | // GIVEN |
46 | Qt3DRender::Render::BlitFramebuffer backendBlitFramebuffer; |
47 | |
48 | // THEN |
49 | QCOMPARE(backendBlitFramebuffer.nodeType(), Qt3DRender::Render::FrameGraphNode::BlitFramebuffer); |
50 | QCOMPARE(backendBlitFramebuffer.isEnabled(), false); |
51 | QVERIFY(backendBlitFramebuffer.peerId().isNull()); |
52 | QVERIFY(backendBlitFramebuffer.sourceRenderTargetId().isNull()); |
53 | QVERIFY(backendBlitFramebuffer.destinationRenderTargetId().isNull()); |
54 | QCOMPARE(backendBlitFramebuffer.sourceRect(), QRect()); |
55 | QCOMPARE(backendBlitFramebuffer.destinationRect(), QRect()); |
56 | QCOMPARE(backendBlitFramebuffer.sourceAttachmentPoint(), Qt3DRender::QRenderTargetOutput::Color0); |
57 | QCOMPARE(backendBlitFramebuffer.destinationAttachmentPoint(), Qt3DRender::QRenderTargetOutput::Color0); |
58 | QCOMPARE(backendBlitFramebuffer.interpolationMethod(), Qt3DRender::QBlitFramebuffer::Linear); |
59 | } |
60 | |
61 | void checkInitializeFromPeer() |
62 | { |
63 | // GIVEN |
64 | TestRenderer renderer; |
65 | Qt3DRender::QRenderTarget *sourceTarget = new Qt3DRender::QRenderTarget; |
66 | Qt3DRender::QRenderTarget *destinationTarget = new Qt3DRender::QRenderTarget; |
67 | Qt3DRender::QBlitFramebuffer blitFramebuffer; |
68 | blitFramebuffer.setSource(sourceTarget); |
69 | blitFramebuffer.setDestination(destinationTarget); |
70 | blitFramebuffer.setSourceRect(QRect(0,0,1,1)); |
71 | blitFramebuffer.setDestinationRect(QRect(0,0,1,1)); |
72 | blitFramebuffer.setSourceAttachmentPoint(Qt3DRender::QRenderTargetOutput::Color1); |
73 | blitFramebuffer.setDestinationAttachmentPoint(Qt3DRender::QRenderTargetOutput::Color1); |
74 | blitFramebuffer.setInterpolationMethod(Qt3DRender::QBlitFramebuffer::Nearest); |
75 | |
76 | { |
77 | // WHEN |
78 | Qt3DRender::Render::BlitFramebuffer backendBlitFramebuffer; |
79 | backendBlitFramebuffer.setRenderer(&renderer); |
80 | simulateInitializationSync(frontend: &blitFramebuffer, backend: &backendBlitFramebuffer); |
81 | |
82 | // THEN |
83 | QCOMPARE(backendBlitFramebuffer.isEnabled(), true); |
84 | QCOMPARE(backendBlitFramebuffer.peerId(), blitFramebuffer.id()); |
85 | QCOMPARE(backendBlitFramebuffer.sourceRenderTargetId(), sourceTarget->id()); |
86 | QCOMPARE(backendBlitFramebuffer.destinationRenderTargetId(), destinationTarget->id()); |
87 | QCOMPARE(backendBlitFramebuffer.sourceRect(), QRect(0,0,1,1)); |
88 | QCOMPARE(backendBlitFramebuffer.destinationRect(), QRect(0,0,1,1)); |
89 | QCOMPARE(backendBlitFramebuffer.sourceAttachmentPoint(), Qt3DRender::QRenderTargetOutput::Color1); |
90 | QCOMPARE(backendBlitFramebuffer.destinationAttachmentPoint(), Qt3DRender::QRenderTargetOutput::Color1); |
91 | QCOMPARE(backendBlitFramebuffer.interpolationMethod(), Qt3DRender::QBlitFramebuffer::Nearest); |
92 | QVERIFY(renderer.dirtyBits() & Qt3DRender::Render::AbstractRenderer::FrameGraphDirty); |
93 | } |
94 | renderer.clearDirtyBits(changes: Qt3DRender::Render::AbstractRenderer::AllDirty); |
95 | { |
96 | // WHEN |
97 | Qt3DRender::Render::BlitFramebuffer backendBlitFramebuffer; |
98 | backendBlitFramebuffer.setRenderer(&renderer); |
99 | blitFramebuffer.setEnabled(false); |
100 | simulateInitializationSync(frontend: &blitFramebuffer, backend: &backendBlitFramebuffer); |
101 | |
102 | // THEN |
103 | QCOMPARE(backendBlitFramebuffer.peerId(), blitFramebuffer.id()); |
104 | QCOMPARE(backendBlitFramebuffer.isEnabled(), false); |
105 | QVERIFY(renderer.dirtyBits() & Qt3DRender::Render::AbstractRenderer::FrameGraphDirty); |
106 | } |
107 | } |
108 | |
109 | void checkSceneChangeEvents() |
110 | { |
111 | // GIVEN |
112 | Qt3DRender::Render::BlitFramebuffer backendBlitFramebuffer; |
113 | Qt3DRender::QBlitFramebuffer blitFramebuffer; |
114 | TestRenderer renderer; |
115 | backendBlitFramebuffer.setRenderer(&renderer); |
116 | simulateInitializationSync(frontend: &blitFramebuffer, backend: &backendBlitFramebuffer); |
117 | |
118 | { |
119 | // WHEN |
120 | const bool newValue = false; |
121 | blitFramebuffer.setEnabled(newValue); |
122 | backendBlitFramebuffer.syncFromFrontEnd(frontEnd: &blitFramebuffer, firstTime: false); |
123 | |
124 | // THEN |
125 | QCOMPARE(backendBlitFramebuffer.isEnabled(), newValue); |
126 | QVERIFY(renderer.dirtyBits() & Qt3DRender::Render::AbstractRenderer::FrameGraphDirty); |
127 | renderer.clearDirtyBits(changes: Qt3DRender::Render::AbstractRenderer::AllDirty); |
128 | } |
129 | { |
130 | // WHEN |
131 | Qt3DRender::QRenderTarget sourceRenderTarget; |
132 | blitFramebuffer.setSource(&sourceRenderTarget); |
133 | backendBlitFramebuffer.syncFromFrontEnd(frontEnd: &blitFramebuffer, firstTime: false); |
134 | |
135 | // THEN |
136 | QCOMPARE(backendBlitFramebuffer.sourceRenderTargetId(), sourceRenderTarget.id()); |
137 | QVERIFY(renderer.dirtyBits() & Qt3DRender::Render::AbstractRenderer::FrameGraphDirty); |
138 | renderer.clearDirtyBits(changes: Qt3DRender::Render::AbstractRenderer::AllDirty); |
139 | } |
140 | { |
141 | // WHEN |
142 | Qt3DRender::QRenderTarget destinationRenderTarget; |
143 | blitFramebuffer.setDestination(&destinationRenderTarget); |
144 | backendBlitFramebuffer.syncFromFrontEnd(frontEnd: &blitFramebuffer, firstTime: false); |
145 | |
146 | // THEN |
147 | QCOMPARE(backendBlitFramebuffer.destinationRenderTargetId(), destinationRenderTarget.id()); |
148 | QVERIFY(renderer.dirtyBits() & Qt3DRender::Render::AbstractRenderer::FrameGraphDirty); |
149 | renderer.clearDirtyBits(changes: Qt3DRender::Render::AbstractRenderer::AllDirty); |
150 | } |
151 | { |
152 | // WHEN |
153 | const auto newValue = QRect(0,0,1,1); |
154 | blitFramebuffer.setSourceRect(newValue); |
155 | backendBlitFramebuffer.syncFromFrontEnd(frontEnd: &blitFramebuffer, firstTime: false); |
156 | |
157 | // THEN |
158 | QCOMPARE(backendBlitFramebuffer.sourceRect(), newValue); |
159 | QVERIFY(renderer.dirtyBits() & Qt3DRender::Render::AbstractRenderer::FrameGraphDirty); |
160 | renderer.clearDirtyBits(changes: Qt3DRender::Render::AbstractRenderer::AllDirty); |
161 | } |
162 | { |
163 | // WHEN |
164 | const auto newValue = QRect(0,0,1,1); |
165 | blitFramebuffer.setDestinationRect(newValue); |
166 | backendBlitFramebuffer.syncFromFrontEnd(frontEnd: &blitFramebuffer, firstTime: false); |
167 | |
168 | // THEN |
169 | QCOMPARE(backendBlitFramebuffer.destinationRect(), newValue); |
170 | QVERIFY(renderer.dirtyBits() & Qt3DRender::Render::AbstractRenderer::FrameGraphDirty); |
171 | renderer.clearDirtyBits(changes: Qt3DRender::Render::AbstractRenderer::AllDirty); |
172 | } |
173 | { |
174 | // WHEN |
175 | const auto newValue = Qt3DRender::QRenderTargetOutput::Color1; |
176 | blitFramebuffer.setSourceAttachmentPoint(newValue); |
177 | backendBlitFramebuffer.syncFromFrontEnd(frontEnd: &blitFramebuffer, firstTime: false); |
178 | |
179 | // THEN |
180 | QCOMPARE(backendBlitFramebuffer.sourceAttachmentPoint(), newValue); |
181 | QVERIFY(renderer.dirtyBits() & Qt3DRender::Render::AbstractRenderer::FrameGraphDirty); |
182 | renderer.clearDirtyBits(changes: Qt3DRender::Render::AbstractRenderer::AllDirty); |
183 | } |
184 | { |
185 | // WHEN |
186 | const auto newValue = Qt3DRender::QRenderTargetOutput::Color1; |
187 | blitFramebuffer.setDestinationAttachmentPoint(newValue); |
188 | backendBlitFramebuffer.syncFromFrontEnd(frontEnd: &blitFramebuffer, firstTime: false); |
189 | |
190 | // THEN |
191 | QCOMPARE(backendBlitFramebuffer.destinationAttachmentPoint(), newValue); |
192 | QVERIFY(renderer.dirtyBits() & Qt3DRender::Render::AbstractRenderer::FrameGraphDirty); |
193 | renderer.clearDirtyBits(changes: Qt3DRender::Render::AbstractRenderer::AllDirty); |
194 | } |
195 | } |
196 | |
197 | }; |
198 | |
199 | QTEST_MAIN(tst_BlitFramebuffer) |
200 | |
201 | #include "tst_blitframebuffer.moc" |
202 | |