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
30#include <QtTest/QTest>
31#include <Qt3DRender/qmemorybarrier.h>
32#include <Qt3DRender/private/qmemorybarrier_p.h>
33#include <Qt3DRender/private/memorybarrier_p.h>
34#include "qbackendnodetester.h"
35#include "testrenderer.h"
36
37class tst_MemoryBarrier : public Qt3DCore::QBackendNodeTester
38{
39 Q_OBJECT
40
41private Q_SLOTS:
42
43 void checkInitialState()
44 {
45 // GIVEN
46 Qt3DRender::Render::MemoryBarrier backendMemoryBarrier;
47
48 // THEN
49 QCOMPARE(backendMemoryBarrier.nodeType(), Qt3DRender::Render::FrameGraphNode::MemoryBarrier);
50 QCOMPARE(backendMemoryBarrier.isEnabled(), false);
51 QVERIFY(backendMemoryBarrier.peerId().isNull());
52 QCOMPARE(backendMemoryBarrier.waitOperations(), Qt3DRender::QMemoryBarrier::None);
53 }
54
55 void checkInitializeFromPeer()
56 {
57 // GIVEN
58 TestRenderer renderer;
59 Qt3DRender::QMemoryBarrier memoryBarrier;
60 memoryBarrier.setWaitOperations(Qt3DRender::QMemoryBarrier::VertexAttributeArray);
61
62 {
63 // WHEN
64 Qt3DRender::Render::MemoryBarrier backendMemoryBarrier;
65 backendMemoryBarrier.setRenderer(&renderer);
66 simulateInitializationSync(frontend: &memoryBarrier, backend: &backendMemoryBarrier);
67
68 // THEN
69 QCOMPARE(backendMemoryBarrier.isEnabled(), true);
70 QCOMPARE(backendMemoryBarrier.peerId(), memoryBarrier.id());
71 QCOMPARE(backendMemoryBarrier.waitOperations(), Qt3DRender::QMemoryBarrier::VertexAttributeArray);
72 QVERIFY(renderer.dirtyBits() & Qt3DRender::Render::AbstractRenderer::FrameGraphDirty);
73 }
74 renderer.clearDirtyBits(changes: Qt3DRender::Render::AbstractRenderer::AllDirty);
75 {
76 // WHEN
77 Qt3DRender::Render::MemoryBarrier backendMemoryBarrier;
78 backendMemoryBarrier.setRenderer(&renderer);
79 memoryBarrier.setEnabled(false);
80 simulateInitializationSync(frontend: &memoryBarrier, backend: &backendMemoryBarrier);
81
82 // THEN
83 QCOMPARE(backendMemoryBarrier.peerId(), memoryBarrier.id());
84 QCOMPARE(backendMemoryBarrier.isEnabled(), false);
85 QVERIFY(renderer.dirtyBits() & Qt3DRender::Render::AbstractRenderer::FrameGraphDirty);
86 }
87 }
88
89 void checkSceneChangeEvents()
90 {
91 // GIVEN
92 Qt3DRender::Render::MemoryBarrier backendMemoryBarrier;
93 TestRenderer renderer;
94 backendMemoryBarrier.setRenderer(&renderer);
95 Qt3DRender::QMemoryBarrier memoryBarrier;
96
97 simulateInitializationSync(frontend: &memoryBarrier, backend: &backendMemoryBarrier);
98
99 {
100 // WHEN
101 const bool newValue = false;
102 memoryBarrier.setEnabled(newValue);
103 backendMemoryBarrier.syncFromFrontEnd(frontEnd: &memoryBarrier, firstTime: false);
104
105 // THEN
106 QCOMPARE(backendMemoryBarrier.isEnabled(), newValue);
107 QVERIFY(renderer.dirtyBits() & Qt3DRender::Render::AbstractRenderer::FrameGraphDirty);
108 renderer.clearDirtyBits(changes: Qt3DRender::Render::AbstractRenderer::AllDirty);
109 }
110 {
111 // WHEN
112 const Qt3DRender::QMemoryBarrier::Operations newValue(Qt3DRender::QMemoryBarrier::AtomicCounter|Qt3DRender::QMemoryBarrier::ElementArray);
113 memoryBarrier.setWaitOperations(newValue);
114 backendMemoryBarrier.syncFromFrontEnd(frontEnd: &memoryBarrier, firstTime: false);
115
116 // THEN
117 QCOMPARE(backendMemoryBarrier.waitOperations(), newValue);
118 QVERIFY(renderer.dirtyBits() & Qt3DRender::Render::AbstractRenderer::FrameGraphDirty);
119 renderer.clearDirtyBits(changes: Qt3DRender::Render::AbstractRenderer::AllDirty);
120 }
121 }
122
123};
124
125QTEST_MAIN(tst_MemoryBarrier)
126
127#include "tst_memorybarrier.moc"
128

source code of qt3d/tests/auto/render/memorybarrier/tst_memorybarrier.cpp