1// Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "computecommand_p.h"
5#include <Qt3DCore/qnode.h>
6#include <Qt3DRender/private/qcomputecommand_p.h>
7#include <Qt3DRender/private/abstractrenderer_p.h>
8
9QT_BEGIN_NAMESPACE
10
11namespace Qt3DRender {
12
13namespace Render {
14
15ComputeCommand::ComputeCommand()
16 : BackendNode(ReadWrite)
17 , m_frameCount(0)
18 , m_runType(QComputeCommand::Continuous)
19 , m_hasReachedFrameCount(false)
20{
21 m_workGroups[0] = 1;
22 m_workGroups[1] = 1;
23 m_workGroups[2] = 1;
24}
25
26ComputeCommand::~ComputeCommand()
27{
28}
29
30void ComputeCommand::cleanup()
31{
32 QBackendNode::setEnabled(false);
33 m_workGroups[0] = 1;
34 m_workGroups[1] = 1;
35 m_workGroups[2] = 1;
36 m_frameCount = 0;
37 m_runType = QComputeCommand::Continuous;
38 m_hasReachedFrameCount = false;
39}
40
41void ComputeCommand::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime)
42{
43 const QComputeCommand *node = qobject_cast<const QComputeCommand *>(object: frontEnd);
44 if (!node)
45 return;
46
47 const bool wasEnabled = isEnabled();
48 BackendNode::syncFromFrontEnd(frontEnd, firstTime);
49 if (wasEnabled != isEnabled())
50 markDirty(changes: AbstractRenderer::ComputeDirty);
51
52 if (m_workGroups[0] != node->workGroupX()) {
53 m_workGroups[0] = node->workGroupX();
54 markDirty(changes: AbstractRenderer::ComputeDirty);
55 }
56 if (m_workGroups[1] != node->workGroupY()) {
57 m_workGroups[1] = node->workGroupY();
58 markDirty(changes: AbstractRenderer::ComputeDirty);
59 }
60 if (m_workGroups[2] != node->workGroupZ()) {
61 m_workGroups[2] = node->workGroupZ();
62 markDirty(changes: AbstractRenderer::ComputeDirty);
63 }
64 if (node->runType() != m_runType) {
65 m_runType = node->runType();
66 markDirty(changes: AbstractRenderer::ComputeDirty);
67 }
68 const QComputeCommandPrivate *d = static_cast<const QComputeCommandPrivate *>(Qt3DCore::QNodePrivate::get(q: node));
69 // Check frame count only if frontend is enabled
70 // If disabled that means we might have disabled the frontend because
71 // framecount reached 0
72 if (d->m_enabled && d->m_frameCount != m_frameCount) {
73 m_frameCount = d->m_frameCount;
74 m_hasReachedFrameCount = m_frameCount <= 0;
75 markDirty(changes: AbstractRenderer::ComputeDirty);
76 }
77
78 if (firstTime)
79 markDirty(changes: AbstractRenderer::ComputeDirty);
80}
81
82// Called from buildComputeRenderCommands in a job
83void ComputeCommand::updateFrameCount()
84{
85 // Disable frontend node when reaching 0
86 --m_frameCount;
87 if (m_frameCount <= 0)
88 m_hasReachedFrameCount = true;
89 // Backend will be disabled on the next sync
90}
91
92void ComputeCommand::resetHasReachedFrameCount()
93{
94 m_hasReachedFrameCount = false;
95}
96
97bool ComputeCommand::hasReachedFrameCount() const
98{
99 return m_hasReachedFrameCount;
100}
101
102} // Render
103
104} // Qt3DRender
105
106QT_END_NAMESPACE
107

source code of qt3d/src/render/backend/computecommand.cpp