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

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