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 "qrendertargetoutput.h"
41#include "qrendertargetoutput_p.h"
42#include "qtexture.h"
43
44QT_BEGIN_NAMESPACE
45
46namespace Qt3DRender {
47
48/*!
49 \class Qt3DRender::QRenderTargetOutput
50 \brief The QRenderTargetOutput class allows the specification of an attachment
51 of a render target (whether it is a color texture, a depth texture, etc... ).
52 \since 5.7
53 \inmodule Qt3DRender
54
55 A QRenderTargetOutput specifies the attachment point and parameters for texture
56 that is attached to render target. In addition to the attachment point, texture
57 miplevel, layer and cubemap face can be specified. The texture attached to the
58 QRenderTargetOutput must be compatible with the given parameters.
59 */
60
61/*!
62 \qmltype RenderTargetOutput
63 \brief The RenderTargetOutput type allows the specification of an attachment
64 of a render target (whether it is a color texture, a depth texture, etc... ).
65 \since 5.7
66 \inqmlmodule Qt3D.Render
67 \inherits Node
68 \instantiates Qt3DRender::QRenderTargetOutput
69
70 A RenderTargetOutput specifies the attachment point and parameters for texture
71 that is attached to render target. In addition to the attachment point, texture
72 miplevel, layer and cubemap face can be specified. The texture attached to the
73 RenderTargetOutput must be compatible with the given parameters.
74 */
75
76/*!
77 \enum QRenderTargetOutput::AttachmentPoint
78
79 This enumeration specifies the values for the attachment point.
80
81 \value Color0 Color attachment point at index 0
82 \value Color1 Color attachment point at index 1
83 \value Color2 Color attachment point at index 2
84 \value Color3 Color attachment point at index 3
85 \value Color4 Color attachment point at index 4
86 \value Color5 Color attachment point at index 5
87 \value Color6 Color attachment point at index 6
88 \value Color7 Color attachment point at index 7
89 \value Color8 Color attachment point at index 8
90 \value Color9 Color attachment point at index 9
91 \value Color10 Color attachment point at index 10
92 \value Color11 Color attachment point at index 11
93 \value Color12 Color attachment point at index 12
94 \value Color13 Color attachment point at index 13
95 \value Color14 Color attachment point at index 14
96 \value Color15 Color attachment point at index 15
97 \value Depth Depth attachment point
98 \value Stencil Stencil attachment point
99 \value DepthStencil DepthStencil attachment point
100*/
101
102/*!
103 \qmlproperty enumeration RenderTargetOutput::attachmentPoint
104 Holds the attachment point of the RenderTargetOutput.
105 \list
106 \li RenderTargetOutput.Color0
107 \li RenderTargetOutput.Color1
108 \li RenderTargetOutput.Color2
109 \li RenderTargetOutput.Color3
110 \li RenderTargetOutput.Color4
111 \li RenderTargetOutput.Color5
112 \li RenderTargetOutput.Color6
113 \li RenderTargetOutput.Color7
114 \li RenderTargetOutput.Color8
115 \li RenderTargetOutput.Color9
116 \li RenderTargetOutput.Color10
117 \li RenderTargetOutput.Color11
118 \li RenderTargetOutput.Color12
119 \li RenderTargetOutput.Color13
120 \li RenderTargetOutput.Color14
121 \li RenderTargetOutput.Color15
122 \li RenderTargetOutput.Depth
123 \li RenderTargetOutput.Stencil
124 \li RenderTargetOutput.DepthStencil
125 \endlist
126
127 \sa Qt3DRender::QRenderTargetOutput::AttachmentPoint
128*/
129
130/*!
131 \qmlproperty Texture RenderTargetOutput::texture
132 Holds the texture attached to the attachment point.
133*/
134
135/*!
136 \qmlproperty int RenderTargetOutput::mipLevel
137 Holds the miplevel of the attached texture the rendering is directed to.
138*/
139
140/*!
141 \qmlproperty int RenderTargetOutput::layer
142 Holds the layer of the attached texture the rendering is directed to.
143*/
144
145/*!
146 \qmlproperty enumeration RenderTargetOutput::face
147 Holds the face of the attached cubemap texture the rendering is directed to.
148 \list
149 \li Texture.CubeMapPositiveX
150 \li Texture.CubeMapNegativeX
151 \li Texture.CubeMapPositiveY
152 \li Texture.CubeMapNegativeY
153 \li Texture.CubeMapPositiveZ
154 \li Texture.CubeMapNegativeZ
155 \endlist
156 \sa Qt3DRender::QAbstractTexture::CubeMapFace
157*/
158
159/*!
160 \property QRenderTargetOutput::attachmentPoint
161 Holds the attachment point of the QRenderTargetOutput.
162*/
163
164/*!
165 \property QRenderTargetOutput::texture
166 Holds the texture attached to the attachment point.
167*/
168
169/*!
170 \property QRenderTargetOutput::mipLevel
171 Holds the miplevel of the attached texture the rendering is directed to.
172*/
173
174/*!
175 \property QRenderTargetOutput::layer
176 Holds the layer of the attached texture the rendering is directed to.
177*/
178
179/*!
180 \property QRenderTargetOutput::face
181 Holds the face of the attached cubemap texture the rendering is directed to.
182*/
183
184/*! \internal */
185QRenderTargetOutputPrivate::QRenderTargetOutputPrivate()
186 : QNodePrivate()
187 , m_texture(nullptr)
188 , m_attachmentPoint(QRenderTargetOutput::Color0)
189 , m_mipLevel(0)
190 , m_layer(0)
191 , m_face(QAbstractTexture::CubeMapNegativeX)
192{
193}
194
195/*!
196 The constructor creates a new QRenderTargetOutput::QRenderTargetOutput instance
197 with the specified \a parent.
198 */
199QRenderTargetOutput::QRenderTargetOutput(QNode *parent)
200 : QNode(*new QRenderTargetOutputPrivate, parent)
201{
202}
203
204/*! \internal */
205QRenderTargetOutput::~QRenderTargetOutput()
206{
207}
208
209/*! \internal */
210QRenderTargetOutput::QRenderTargetOutput(QRenderTargetOutputPrivate &dd, QNode *parent)
211 : QNode(dd, parent)
212{
213}
214
215void QRenderTargetOutput::setAttachmentPoint(QRenderTargetOutput::AttachmentPoint attachmentPoint)
216{
217 Q_D(QRenderTargetOutput);
218 if (attachmentPoint != d->m_attachmentPoint) {
219 d->m_attachmentPoint = attachmentPoint;
220 emit attachmentPointChanged(attachmentPoint);
221 }
222}
223
224QRenderTargetOutput::AttachmentPoint QRenderTargetOutput::attachmentPoint() const
225{
226 Q_D(const QRenderTargetOutput);
227 return d->m_attachmentPoint;
228}
229
230void QRenderTargetOutput::setTexture(QAbstractTexture *texture)
231{
232 Q_D(QRenderTargetOutput);
233 if (texture != d->m_texture) {
234
235 if (d->m_texture)
236 d->unregisterDestructionHelper(node: d->m_texture);
237
238 // Handle inline declaration
239 if (texture && !texture->parent())
240 texture->setParent(this);
241
242 d->m_texture = texture;
243
244 // Ensures proper bookkeeping
245 if (d->m_texture)
246 d->registerDestructionHelper(node: d->m_texture, func: &QRenderTargetOutput::setTexture, d->m_texture);
247
248 emit textureChanged(texture);
249 }
250}
251
252QAbstractTexture *QRenderTargetOutput::texture() const
253{
254 Q_D(const QRenderTargetOutput);
255 return d->m_texture;
256}
257
258void QRenderTargetOutput::setMipLevel(int level)
259{
260 Q_D(QRenderTargetOutput);
261 if (d->m_mipLevel != level) {
262 d->m_mipLevel = level;
263 emit mipLevelChanged(mipLevel: level);
264 }
265}
266
267int QRenderTargetOutput::mipLevel() const
268{
269 Q_D(const QRenderTargetOutput);
270 return d->m_mipLevel;
271}
272
273void QRenderTargetOutput::setLayer(int layer)
274{
275 Q_D(QRenderTargetOutput);
276 if (d->m_layer != layer) {
277 d->m_layer = layer;
278 emit layerChanged(layer);
279 }
280}
281
282int QRenderTargetOutput::layer() const
283{
284 Q_D(const QRenderTargetOutput);
285 return d->m_layer;
286}
287
288void QRenderTargetOutput::setFace(QAbstractTexture::CubeMapFace face)
289{
290 Q_D(QRenderTargetOutput);
291 if (d->m_face != face) {
292 d->m_face = face;
293 emit faceChanged(face);
294 }
295}
296
297QAbstractTexture::CubeMapFace QRenderTargetOutput::face() const
298{
299 Q_D(const QRenderTargetOutput);
300 return d->m_face;
301}
302
303Qt3DCore::QNodeCreatedChangeBasePtr QRenderTargetOutput::createNodeCreationChange() const
304{
305 auto creationChange = Qt3DCore::QNodeCreatedChangePtr<QRenderTargetOutputData>::create(arguments: this);
306 auto &data = creationChange->data;
307 Q_D(const QRenderTargetOutput);
308 data.textureId = qIdForNode(node: texture());
309 data.attachmentPoint = d->m_attachmentPoint;
310 data.mipLevel = d->m_mipLevel;
311 data.layer = d->m_layer;
312 data.face = d->m_face;
313 return creationChange;
314}
315
316} // namespace Qt3DRender
317
318QT_END_NAMESPACE
319

source code of qt3d/src/render/frontend/qrendertargetoutput.cpp