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 "qclearbuffers.h"
41#include "qclearbuffers_p.h"
42#include <Qt3DRender/qframegraphnodecreatedchange.h>
43
44QT_BEGIN_NAMESPACE
45
46namespace Qt3DRender {
47/*!
48 \class Qt3DRender::QClearBuffers
49 \inmodule Qt3DRender
50 \since 5.7
51 \ingroup framegraph
52 \brief Class to clear buffers.
53
54 A Qt3DRender::QClearBuffers FrameGraph node enables clearing of the specific
55 render target buffers with specific values.
56 */
57
58/*!
59 \qmltype ClearBuffers
60 \inqmlmodule Qt3D.Render
61 \instantiates Qt3DRender::QClearBuffers
62 \inherits FrameGraphNode
63 \since 5.7
64 \brief Class to clear buffers.
65
66 A Qt3DRender::QClearBuffers FrameGraph node enables clearing of the specific
67 render target buffers with specific values.
68*/
69
70/*!
71 \enum QClearBuffers::BufferType
72
73 This enum type describes types of buffer to be cleared.
74 \value None No buffers will be cleared
75 \value ColorBuffer Clear color buffers
76 \value DepthBuffer Clear depth buffer
77 \value StencilBuffer Clear stencil buffer
78 \value DepthStencilBuffer Clear depth and stencil buffers
79 \value ColorDepthBuffer Clear color and depth buffers
80 \value ColorDepthStencilBuffer Clear color, depth and stencil buffers
81 \value AllBuffers Clear all buffers
82*/
83
84QClearBuffersPrivate::QClearBuffersPrivate()
85 : QFrameGraphNodePrivate()
86 , m_buffersType(QClearBuffers::None)
87 , m_clearDepthValue(1.f)
88 , m_clearStencilValue(0)
89 , m_buffer(nullptr)
90{
91}
92
93/*!
94 The constructor creates an instance with the specified \a parent.
95 */
96QClearBuffers::QClearBuffers(QNode *parent)
97 : QFrameGraphNode(*new QClearBuffersPrivate, parent)
98{
99}
100
101/*! \internal */
102QClearBuffers::~QClearBuffers()
103{
104}
105
106/*! \internal */
107QClearBuffers::QClearBuffers(QClearBuffersPrivate &dd, QNode *parent)
108 : QFrameGraphNode(dd, parent)
109{
110}
111
112
113QClearBuffers::BufferType QClearBuffers::buffers() const
114{
115 Q_D(const QClearBuffers);
116 return d->m_buffersType;
117}
118
119QColor QClearBuffers::clearColor() const
120{
121 Q_D(const QClearBuffers);
122 return d->m_clearColor;
123}
124
125float QClearBuffers::clearDepthValue() const
126{
127 Q_D(const QClearBuffers);
128 return d->m_clearDepthValue;
129}
130
131int QClearBuffers::clearStencilValue() const
132{
133 Q_D(const QClearBuffers);
134 return d->m_clearStencilValue;
135}
136
137QRenderTargetOutput *QClearBuffers::colorBuffer() const
138{
139 Q_D(const QClearBuffers);
140 return d->m_buffer;
141}
142
143/*!
144 \property Qt3DRender::QClearBuffers::buffers
145 Specifies the buffer type to be used.
146 */
147
148/*!
149 \qmlproperty enumeration Qt3D.Render::ClearBuffers::buffers
150 Specifies the buffer type to be used.
151*/
152void QClearBuffers::setBuffers(QClearBuffers::BufferType buffers)
153{
154 Q_D(QClearBuffers);
155 if (d->m_buffersType != buffers) {
156 d->m_buffersType = buffers;
157 emit buffersChanged(buffers);
158 }
159}
160
161/*!
162 \property Qt3DRender::QClearBuffers::clearColor
163 Specifies the clear color to be used.
164 */
165/*!
166 \qmlproperty color Qt3D.Render::ClearBuffers::clearColor
167 Specifies the clear color to be used.
168*/
169void QClearBuffers::setClearColor(const QColor &color)
170{
171 Q_D(QClearBuffers);
172 if (d->m_clearColor != color) {
173 d->m_clearColor = color;
174 emit clearColorChanged(color);
175 }
176}
177
178
179/*!
180 \property Qt3DRender::QClearBuffers::clearDepthValue
181 Specifies the clear depth value to be used.
182 */
183/*!
184 \qmlproperty real Qt3D.Render::ClearBuffers::clearDepthValue
185 Specifies the clear depth value to be used.
186*/
187void QClearBuffers::setClearDepthValue(float clearDepthValue)
188{
189 Q_D(QClearBuffers);
190 if (d->m_clearDepthValue != clearDepthValue) {
191 if (clearDepthValue >= 0.f && clearDepthValue <= 1.f) {
192 d->m_clearDepthValue = clearDepthValue;
193 emit clearDepthValueChanged(clearDepthValue);
194 } else qWarning() << "Invalid clear depth value";
195 }
196}
197
198
199/*!
200 \property Qt3DRender::QClearBuffers::clearStencilValue
201 Specifies the stencil value to be used.
202 */
203/*!
204 \qmlproperty int Qt3D.Render::ClearBuffers::clearStencilValue
205 Specifies the stencil value to be used.
206*/
207void QClearBuffers::setClearStencilValue(int clearStencilValue)
208{
209 Q_D(QClearBuffers);
210 if (d->m_clearStencilValue != clearStencilValue) {
211 d->m_clearStencilValue = clearStencilValue;
212 emit clearStencilValueChanged(clearStencilValue);
213 }
214}
215
216/*!
217 \property Qt3DRender::QClearBuffers::colorBuffer
218 Specifies a specific color buffer to clear. If set to NULL (default), and
219 ColorBuffer flag is set, all color buffers will be cleared.
220 */
221/*!
222 \qmlproperty RenderTargetOutput Qt3D.Render::ClearBuffers::colorBuffer
223 Specifies a specific color buffer to clear. If set to NULL (default), and
224 ColorBuffer flag is set, all color buffers will be cleared.
225*/
226void QClearBuffers::setColorBuffer(QRenderTargetOutput *buffer)
227{
228 Q_D(QClearBuffers);
229 if (d->m_buffer != buffer) {
230 d->m_buffer = buffer;
231 emit colorBufferChanged(buffer);
232 }
233}
234
235Qt3DCore::QNodeCreatedChangeBasePtr QClearBuffers::createNodeCreationChange() const
236{
237 auto creationChange = QFrameGraphNodeCreatedChangePtr<QClearBuffersData>::create(arguments: this);
238 auto &data = creationChange->data;
239 Q_D(const QClearBuffers);
240 data.buffersType = d->m_buffersType;
241 data.clearColor = d->m_clearColor;
242 data.clearDepthValue = d->m_clearDepthValue;
243 data.clearStencilValue = d->m_clearStencilValue;
244 data.bufferId = Qt3DCore::qIdForNode(node: d->m_buffer);
245 return creationChange;
246}
247
248} // namespace Qt3DRender
249
250QT_END_NAMESPACE
251

source code of qt3d/src/render/framegraph/qclearbuffers.cpp