1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2014 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 | #include "clearbuffers_p.h" |
41 | #include <Qt3DRender/private/qclearbuffers_p.h> |
42 | #include <Qt3DCore/qpropertyupdatedchange.h> |
43 | |
44 | QT_BEGIN_NAMESPACE |
45 | |
46 | using namespace Qt3DCore; |
47 | |
48 | namespace Qt3DRender { |
49 | namespace Render { |
50 | |
51 | static QVector4D vec4dFromColor(const QColor &color) |
52 | { |
53 | return QVector4D(color.redF(), color.greenF(), color.blueF(), color.alphaF()); |
54 | } |
55 | |
56 | ClearBuffers::ClearBuffers() |
57 | : FrameGraphNode(FrameGraphNode::ClearBuffers) |
58 | , m_type(QClearBuffers::None) |
59 | , m_clearDepthValue(1.f) |
60 | , m_clearStencilValue(0) |
61 | { |
62 | } |
63 | |
64 | void ClearBuffers::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) |
65 | { |
66 | FrameGraphNode::initializeFromPeer(change); |
67 | const auto typedChange = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<QClearBuffersData>>(change); |
68 | const auto &data = typedChange->data; |
69 | m_type = data.buffersType; |
70 | m_clearColorAsColor = data.clearColor; |
71 | m_clearColor = vec4dFromColor(m_clearColorAsColor); |
72 | m_clearDepthValue = data.clearDepthValue; |
73 | m_clearStencilValue = data.clearStencilValue; |
74 | m_colorBufferId = data.bufferId; |
75 | } |
76 | |
77 | void ClearBuffers::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) |
78 | { |
79 | if (e->type() == PropertyUpdated) { |
80 | QPropertyUpdatedChangePtr propertyChange = qSharedPointerCast<QPropertyUpdatedChange>(e); |
81 | if (propertyChange->propertyName() == QByteArrayLiteral("buffers" )) { |
82 | m_type = static_cast<QClearBuffers::BufferType>(propertyChange->value().toInt()); |
83 | markDirty(AbstractRenderer::FrameGraphDirty); |
84 | } else if (propertyChange->propertyName() == QByteArrayLiteral("clearColor" )) { |
85 | m_clearColorAsColor = propertyChange->value().value<QColor>(); |
86 | m_clearColor = vec4dFromColor(m_clearColorAsColor); |
87 | markDirty(AbstractRenderer::FrameGraphDirty); |
88 | } else if (propertyChange->propertyName() == QByteArrayLiteral("clearDepthValue" )) { |
89 | m_clearDepthValue = propertyChange->value().toFloat(); |
90 | markDirty(AbstractRenderer::FrameGraphDirty); |
91 | } else if (propertyChange->propertyName() == QByteArrayLiteral("clearStencilValue" )) { |
92 | m_clearStencilValue = propertyChange->value().toInt(); |
93 | markDirty(AbstractRenderer::FrameGraphDirty); |
94 | } else if (propertyChange->propertyName() == QByteArrayLiteral("colorBuffer" )) { |
95 | m_colorBufferId = propertyChange->value().value<QNodeId>(); |
96 | markDirty(AbstractRenderer::FrameGraphDirty); |
97 | } |
98 | } |
99 | FrameGraphNode::sceneChangeEvent(e); |
100 | } |
101 | |
102 | QClearBuffers::BufferType ClearBuffers::type() const |
103 | { |
104 | return m_type; |
105 | } |
106 | |
107 | QColor ClearBuffers::clearColorAsColor() const |
108 | { |
109 | return m_clearColorAsColor; |
110 | } |
111 | |
112 | QVector4D ClearBuffers::clearColor() const |
113 | { |
114 | return m_clearColor; |
115 | } |
116 | |
117 | float ClearBuffers::clearDepthValue() const |
118 | { |
119 | return m_clearDepthValue; |
120 | } |
121 | |
122 | int ClearBuffers::clearStencilValue() const |
123 | { |
124 | return m_clearStencilValue; |
125 | } |
126 | |
127 | Qt3DCore::QNodeId ClearBuffers::bufferId() const |
128 | { |
129 | return m_colorBufferId; |
130 | } |
131 | |
132 | bool ClearBuffers::clearsAllColorBuffers() const |
133 | { |
134 | return m_colorBufferId.isNull(); |
135 | } |
136 | |
137 | } // namespace Render |
138 | } // namespace Qt3DRender |
139 | |
140 | QT_END_NAMESPACE |
141 | |