| 1 | /**************************************************************************** |
|---|---|
| 2 | ** |
| 3 | ** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). |
| 4 | ** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies). |
| 5 | ** Contact: https://www.qt.io/licensing/ |
| 6 | ** |
| 7 | ** This file is part of the Qt3D module of the Qt Toolkit. |
| 8 | ** |
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ |
| 10 | ** Commercial License Usage |
| 11 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 12 | ** accordance with the commercial license agreement provided with the |
| 13 | ** Software or, alternatively, in accordance with the terms contained in |
| 14 | ** a written agreement between you and The Qt Company. For licensing terms |
| 15 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 16 | ** information use the contact form at https://www.qt.io/contact-us. |
| 17 | ** |
| 18 | ** GNU Lesser General Public License Usage |
| 19 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 20 | ** General Public License version 3 as published by the Free Software |
| 21 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
| 22 | ** packaging of this file. Please review the following information to |
| 23 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 24 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
| 25 | ** |
| 26 | ** GNU General Public License Usage |
| 27 | ** Alternatively, this file may be used under the terms of the GNU |
| 28 | ** General Public License version 2.0 or (at your option) the GNU General |
| 29 | ** Public license version 3 or any later version approved by the KDE Free |
| 30 | ** Qt Foundation. The licenses are as published by the Free Software |
| 31 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
| 32 | ** included in the packaging of this file. Please review the following |
| 33 | ** information to ensure the GNU General Public License requirements will |
| 34 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
| 35 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
| 36 | ** |
| 37 | ** $QT_END_LICENSE$ |
| 38 | ** |
| 39 | ****************************************************************************/ |
| 40 | |
| 41 | #include "renderpass_p.h" |
| 42 | #include <Qt3DRender/private/filterkey_p.h> |
| 43 | #include <Qt3DRender/qrenderstate.h> |
| 44 | #include <Qt3DRender/qrenderpass.h> |
| 45 | #include <Qt3DRender/qparameter.h> |
| 46 | |
| 47 | #include <Qt3DRender/private/qrenderpass_p.h> |
| 48 | #include <Qt3DRender/private/renderstates_p.h> |
| 49 | |
| 50 | #include <algorithm> |
| 51 | |
| 52 | QT_BEGIN_NAMESPACE |
| 53 | |
| 54 | using namespace Qt3DCore; |
| 55 | |
| 56 | namespace Qt3DRender { |
| 57 | namespace Render { |
| 58 | |
| 59 | RenderPass::RenderPass() |
| 60 | : BackendNode() |
| 61 | { |
| 62 | } |
| 63 | |
| 64 | RenderPass::~RenderPass() |
| 65 | { |
| 66 | } |
| 67 | |
| 68 | void RenderPass::cleanup() |
| 69 | { |
| 70 | QBackendNode::setEnabled(false); |
| 71 | m_renderStates.clear(); |
| 72 | m_filterKeyList.clear(); |
| 73 | m_parameterPack.clear(); |
| 74 | m_shaderUuid = Qt3DCore::QNodeId(); |
| 75 | } |
| 76 | |
| 77 | void RenderPass::syncFromFrontEnd(const QNode *frontEnd, bool firstTime) |
| 78 | { |
| 79 | BackendNode::syncFromFrontEnd(frontEnd, firstTime); |
| 80 | const QRenderPass *node = qobject_cast<const QRenderPass *>(object: frontEnd); |
| 81 | if (!node) |
| 82 | return; |
| 83 | |
| 84 | if ((node->shaderProgram() && node->shaderProgram()->id() != m_shaderUuid) || |
| 85 | (!node->shaderProgram() && !m_shaderUuid.isNull())) { |
| 86 | m_shaderUuid = node->shaderProgram() ? node->shaderProgram()->id() : QNodeId{}; |
| 87 | } |
| 88 | |
| 89 | auto filterList = qIdsForNodes(nodes: node->filterKeys()); |
| 90 | std::sort(first: std::begin(cont&: filterList), last: std::end(cont&: filterList)); |
| 91 | if (m_filterKeyList != filterList) |
| 92 | m_filterKeyList = filterList; |
| 93 | |
| 94 | auto parameters = qIdsForNodes(nodes: node->parameters()); |
| 95 | std::sort(first: std::begin(cont&: parameters), last: std::end(cont&: parameters)); |
| 96 | if (m_parameterPack.parameters() != parameters) |
| 97 | m_parameterPack.setParameters(parameters); |
| 98 | |
| 99 | auto renderStates = qIdsForNodes(nodes: node->renderStates()); |
| 100 | std::sort(first: std::begin(cont&: renderStates), last: std::end(cont&: renderStates)); |
| 101 | if (m_renderStates != renderStates) |
| 102 | m_renderStates = renderStates; |
| 103 | |
| 104 | markDirty(changes: AbstractRenderer::AllDirty); |
| 105 | } |
| 106 | |
| 107 | Qt3DCore::QNodeId RenderPass::shaderProgram() const |
| 108 | { |
| 109 | return m_shaderUuid; |
| 110 | } |
| 111 | |
| 112 | QVector<Qt3DCore::QNodeId> RenderPass::filterKeys() const |
| 113 | { |
| 114 | return m_filterKeyList; |
| 115 | } |
| 116 | |
| 117 | QVector<Qt3DCore::QNodeId> RenderPass::parameters() const |
| 118 | { |
| 119 | return m_parameterPack.parameters(); |
| 120 | } |
| 121 | |
| 122 | QVector<QNodeId> RenderPass::renderStates() const |
| 123 | { |
| 124 | return m_renderStates; |
| 125 | } |
| 126 | |
| 127 | void RenderPass::appendFilterKey(Qt3DCore::QNodeId filterKeyId) |
| 128 | { |
| 129 | if (!m_filterKeyList.contains(t: filterKeyId)) |
| 130 | m_filterKeyList.append(t: filterKeyId); |
| 131 | } |
| 132 | |
| 133 | void RenderPass::removeFilterKey(Qt3DCore::QNodeId filterKeyId) |
| 134 | { |
| 135 | m_filterKeyList.removeOne(t: filterKeyId); |
| 136 | } |
| 137 | |
| 138 | void RenderPass::addRenderState(QNodeId renderStateId) |
| 139 | { |
| 140 | if (!m_renderStates.contains(t: renderStateId)) |
| 141 | m_renderStates.push_back(t: renderStateId); |
| 142 | } |
| 143 | |
| 144 | void RenderPass::removeRenderState(QNodeId renderStateId) |
| 145 | { |
| 146 | m_renderStates.removeOne(t: renderStateId); |
| 147 | } |
| 148 | |
| 149 | |
| 150 | } // namespace Render |
| 151 | } // namespace Qt3DRender |
| 152 | |
| 153 | QT_END_NAMESPACE |
| 154 |
