1/****************************************************************************
2**
3** Copyright (C) 2018 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:LGPL$
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 Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40
41
42#include <QtTest/QTest>
43#include <Qt3DRender/qwaitfence.h>
44#include <Qt3DRender/private/qwaitfence_p.h>
45#include <Qt3DRender/private/waitfence_p.h>
46#include "qbackendnodetester.h"
47#include "testrenderer.h"
48
49class tst_WaitFence : public Qt3DCore::QBackendNodeTester
50{
51 Q_OBJECT
52
53private Q_SLOTS:
54
55 void checkInitialState()
56 {
57 // GIVEN
58 Qt3DRender::Render::WaitFence backendWaitFence;
59
60 // THEN
61 QCOMPARE(backendWaitFence.isEnabled(), false);
62 QVERIFY(backendWaitFence.peerId().isNull());
63 QCOMPARE(backendWaitFence.nodeType(), Qt3DRender::Render::FrameGraphNode::WaitFence);
64 QCOMPARE(backendWaitFence.data().handleType, Qt3DRender::QWaitFence::NoHandle);
65 QCOMPARE(backendWaitFence.data().handle, QVariant());
66 QCOMPARE(backendWaitFence.data().waitOnCPU, false);
67 QCOMPARE(backendWaitFence.data().timeout, quint64(-1));
68 }
69
70 void checkInitializeFromPeer()
71 {
72 // GIVEN
73 TestRenderer renderer;
74 Qt3DRender::QWaitFence waitFence;
75 waitFence.setHandle(QVariant(883));
76 waitFence.setWaitOnCPU(true);
77 waitFence.setTimeout(8);
78 waitFence.setHandleType(Qt3DRender::QWaitFence::OpenGLFenceId);
79
80 {
81 // WHEN
82 Qt3DRender::Render::WaitFence backendWaitFence;
83 backendWaitFence.setRenderer(&renderer);
84 simulateInitializationSync(frontend: &waitFence, backend: &backendWaitFence);
85
86 // THEN
87 QCOMPARE(backendWaitFence.isEnabled(), true);
88 QCOMPARE(backendWaitFence.peerId(), waitFence.id());
89 QCOMPARE(backendWaitFence.data().handleType, Qt3DRender::QWaitFence::OpenGLFenceId);
90 QCOMPARE(backendWaitFence.data().handle, QVariant(883));
91 QCOMPARE(backendWaitFence.data().waitOnCPU, true);
92 QCOMPARE(backendWaitFence.data().timeout, quint64(8));
93 QVERIFY(renderer.dirtyBits() & Qt3DRender::Render::AbstractRenderer::FrameGraphDirty);
94 }
95 renderer.clearDirtyBits(changes: Qt3DRender::Render::AbstractRenderer::AllDirty);
96 {
97 // WHEN
98 Qt3DRender::Render::WaitFence backendWaitFence;
99 waitFence.setEnabled(false);
100 backendWaitFence.setRenderer(&renderer);
101 simulateInitializationSync(frontend: &waitFence, backend: &backendWaitFence);
102
103 // THEN
104 QCOMPARE(backendWaitFence.peerId(), waitFence.id());
105 QCOMPARE(backendWaitFence.isEnabled(), false);
106 QCOMPARE(backendWaitFence.data().handleType, Qt3DRender::QWaitFence::OpenGLFenceId);
107 QCOMPARE(backendWaitFence.data().handle, QVariant(883));
108 QCOMPARE(backendWaitFence.data().waitOnCPU, true);
109 QCOMPARE(backendWaitFence.data().timeout, quint64(8));
110 QVERIFY(renderer.dirtyBits() & Qt3DRender::Render::AbstractRenderer::FrameGraphDirty);
111 }
112 }
113
114 void checkSceneChangeEvents()
115 {
116 // GIVEN
117 Qt3DRender::QWaitFence waitFence;
118 Qt3DRender::Render::WaitFence backendWaitFence;
119 TestRenderer renderer;
120 backendWaitFence.setRenderer(&renderer);
121 simulateInitializationSync(frontend: &waitFence, backend: &backendWaitFence);
122
123 {
124 // WHEN
125 const bool newValue = false;
126 waitFence.setEnabled(newValue);
127 backendWaitFence.syncFromFrontEnd(frontEnd: &waitFence, firstTime: false);
128
129 // THEN
130 QCOMPARE(backendWaitFence.isEnabled(), newValue);
131 QVERIFY(renderer.dirtyBits() & Qt3DRender::Render::AbstractRenderer::FrameGraphDirty);
132 renderer.clearDirtyBits(changes: Qt3DRender::Render::AbstractRenderer::AllDirty);
133 }
134 {
135 // WHEN
136 const QVariant newValue(984);
137 waitFence.setHandle(newValue);
138 backendWaitFence.syncFromFrontEnd(frontEnd: &waitFence, firstTime: false);
139
140 // THEN
141 QCOMPARE(backendWaitFence.data().handle, QVariant(984));
142 QVERIFY(renderer.dirtyBits() & Qt3DRender::Render::AbstractRenderer::FrameGraphDirty);
143 renderer.clearDirtyBits(changes: Qt3DRender::Render::AbstractRenderer::AllDirty);
144 }
145 {
146 // WHEN
147 const Qt3DRender::QWaitFence::HandleType newValue = Qt3DRender::QWaitFence::OpenGLFenceId;
148 waitFence.setHandleType(newValue);
149 backendWaitFence.syncFromFrontEnd(frontEnd: &waitFence, firstTime: false);
150
151 // THEN
152 QCOMPARE(backendWaitFence.data().handleType, Qt3DRender::QWaitFence::OpenGLFenceId);
153 QVERIFY(renderer.dirtyBits() & Qt3DRender::Render::AbstractRenderer::FrameGraphDirty);
154 renderer.clearDirtyBits(changes: Qt3DRender::Render::AbstractRenderer::AllDirty);
155 }
156 {
157 // WHEN
158 const bool newValue = true;
159 waitFence.setWaitOnCPU(newValue);
160 backendWaitFence.syncFromFrontEnd(frontEnd: &waitFence, firstTime: false);
161
162 // THEN
163 QCOMPARE(backendWaitFence.data().waitOnCPU, true);
164 QVERIFY(renderer.dirtyBits() & Qt3DRender::Render::AbstractRenderer::FrameGraphDirty);
165 renderer.clearDirtyBits(changes: Qt3DRender::Render::AbstractRenderer::AllDirty);
166 }
167 {
168 // WHEN
169 const quint64 newValue = 984;
170 waitFence.setTimeout(newValue);
171 backendWaitFence.syncFromFrontEnd(frontEnd: &waitFence, firstTime: false);
172
173 // THEN
174 QCOMPARE(backendWaitFence.data().timeout, quint64(984));
175 QVERIFY(renderer.dirtyBits() & Qt3DRender::Render::AbstractRenderer::FrameGraphDirty);
176 renderer.clearDirtyBits(changes: Qt3DRender::Render::AbstractRenderer::AllDirty);
177 }
178 }
179};
180
181QTEST_MAIN(tst_WaitFence)
182
183#include "tst_waitfence.moc"
184

source code of qt3d/tests/auto/render/waitfence/tst_waitfence.cpp