1/****************************************************************************
2**
3** Copyright (C) 2016 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/qcomputecommand.h>
32#include <Qt3DRender/private/qcomputecommand_p.h>
33#include <Qt3DRender/private/computecommand_p.h>
34#include <Qt3DRender/private/nodemanagers_p.h>
35#include <Qt3DRender/private/managers_p.h>
36#include <Qt3DCore/private/qbackendnode_p.h>
37#include <Qt3DCore/private/qaspectmanager_p.h>
38#include <Qt3DCore/private/qscene_p.h>
39#include <Qt3DCore/qpropertyupdatedchange.h>
40#include <renderer_p.h>
41#include "qbackendnodetester.h"
42#include "testrenderer.h"
43#include "testpostmanarbiter.h"
44
45
46// tst_Renderer is a friend class of Renderer
47class tst_Renderer : public Qt3DRender::Render::OpenGL::Renderer
48{
49public:
50 tst_Renderer()
51 : Qt3DRender::Render::OpenGL::Renderer(Qt3DRender::QRenderAspect::Synchronous)
52 {}
53
54 ~tst_Renderer() {
55 shutdown();
56 }
57};
58
59
60class tst_ComputeCommand : public Qt3DCore::QBackendNodeTester
61{
62 Q_OBJECT
63
64private Q_SLOTS:
65
66 void checkDisablesFrontend()
67 {
68 // GIVEN
69 Qt3DRender::Render::NodeManagers nodeManager;
70 tst_Renderer renderer;
71 TestArbiter arbiter;
72
73 Qt3DCore::QAspectManager manager;
74 Qt3DCore::QScene scene;
75
76 Qt3DCore::QEntity rootEntity;
77 Qt3DCore::QNodePrivate::get(q: &rootEntity)->setScene(&scene);
78
79 Qt3DRender::QComputeCommand computeCommand;
80 Qt3DRender::Render::ComputeCommand *backendComputeCommand = nullptr;
81
82 renderer.setNodeManagers(&nodeManager);
83
84 // WHEN
85 computeCommand.setParent(&rootEntity);
86 // RootEntity is the entry point to retrieve the scene instance for lookups
87 manager.setRootEntity(root: &rootEntity, nodes: {});
88
89 // THEN
90 QVERIFY(scene.lookupNode(computeCommand.id()) != nullptr);
91
92 // WHEN
93 auto handle = nodeManager.computeJobManager()->getOrAcquireHandle(id: computeCommand.id());
94 backendComputeCommand = nodeManager.computeJobManager()->data(handle);
95
96 // WHEN
97 computeCommand.setWorkGroupX(256);
98 computeCommand.setWorkGroupY(512);
99 computeCommand.setWorkGroupZ(128);
100 computeCommand.setRunType(Qt3DRender::QComputeCommand::Manual);
101 computeCommand.trigger(frameCount: 1);
102
103 Qt3DCore::QBackendNodePrivate::get(n: backendComputeCommand)->setArbiter(&arbiter);
104 backendComputeCommand->setRenderer(&renderer);
105 simulateInitializationSync(frontend: &computeCommand, backend: backendComputeCommand);
106
107 // THEN
108 QCOMPARE(backendComputeCommand->frameCount(),1);
109 QCOMPARE(backendComputeCommand->isEnabled(), true);
110 QCOMPARE(computeCommand.isEnabled(), true);
111 QCOMPARE(backendComputeCommand->hasReachedFrameCount(), false);
112
113 // WHEN
114 backendComputeCommand->updateFrameCount();
115
116 // THEN
117 QCOMPARE(backendComputeCommand->frameCount(), 0);
118 QCOMPARE(backendComputeCommand->hasReachedFrameCount(), true);
119
120
121 // Still enabled as we have yet to notify the fronted
122 QCOMPARE(backendComputeCommand->isEnabled(), true);
123 QCOMPARE(computeCommand.isEnabled(), true);
124
125 // WHEN
126 renderer.jobsDone(manager: &manager); // so Renderer::sendDisablesToFrontend gets called
127
128 // THEN
129 QCOMPARE(computeCommand.isEnabled(), false);
130 QCOMPARE(backendComputeCommand->hasReachedFrameCount(), false);
131
132 // WHEN
133 backendComputeCommand->syncFromFrontEnd(frontEnd: &computeCommand, firstTime: false);
134
135 // THEN
136 QCOMPARE(backendComputeCommand->frameCount(), 0);
137 QCOMPARE(backendComputeCommand->isEnabled(), false);
138 }
139};
140
141QTEST_MAIN(tst_ComputeCommand)
142
143#include "tst_computecommand.moc"
144

source code of qt3d/tests/auto/render/opengl/computecommand/tst_computecommand.cpp