summaryrefslogtreecommitdiffstats
path: root/src/render/frontend/qrendertargetoutput.cpp
blob: 83f4d1a82a1287c913d15c8a7ae67f86cdab58b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
/****************************************************************************
**
** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt3D module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:COMM$
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** $QT_END_LICENSE$
**
**
**
**
**
**
**
**
**
**
**
**
**
**
**
**
**
**
**
****************************************************************************/

#include "qrendertargetoutput.h"
#include "qrendertargetoutput_p.h"
#include "qtexture.h"

QT_BEGIN_NAMESPACE

namespace Qt3DRender {

/*!
    \class Qt3DRender::QRenderTargetOutput
    \brief The QRenderTargetOutput class allows the specification of an attachment
    of a render target (whether it is a color texture, a depth texture, etc... ).
    \since 5.7
    \inmodule Qt3DRender

    A QRenderTargetOutput specifies the attachment point and parameters for texture
    that is attached to render target. In addition to the attachment point, texture
    miplevel, layer and cubemap face can be specified. The texture attached to the
    QRenderTargetOutput must be compatible with the given parameters.
 */

/*!
    \qmltype RenderTargetOutput
    \brief The RenderTargetOutput type allows the specification of an attachment
    of a render target (whether it is a color texture, a depth texture, etc... ).
    \since 5.7
    \inqmlmodule Qt3D.Render
    \inherits Node
    \instantiates Qt3DRender::QRenderTargetOutput

    A RenderTargetOutput specifies the attachment point and parameters for texture
    that is attached to render target. In addition to the attachment point, texture
    miplevel, layer and cubemap face can be specified. The texture attached to the
    RenderTargetOutput must be compatible with the given parameters.
 */

/*!
    \enum QRenderTargetOutput::AttachmentPoint

    This enumeration specifies the values for the attachment point.

    \value Color0 Color attachment point at index 0
    \value Color1 Color attachment point at index 1
    \value Color2 Color attachment point at index 2
    \value Color3 Color attachment point at index 3
    \value Color4 Color attachment point at index 4
    \value Color5 Color attachment point at index 5
    \value Color6 Color attachment point at index 6
    \value Color7 Color attachment point at index 7
    \value Color8 Color attachment point at index 8
    \value Color9 Color attachment point at index 9
    \value Color10 Color attachment point at index 10
    \value Color11 Color attachment point at index 11
    \value Color12 Color attachment point at index 12
    \value Color13 Color attachment point at index 13
    \value Color14 Color attachment point at index 14
    \value Color15 Color attachment point at index 15
    \value Depth Depth attachment point
    \value Stencil Stencil attachment point
    \value DepthStencil DepthStencil attachment point
*/

/*!
    \qmlproperty enumeration RenderTargetOutput::attachmentPoint
    Holds the attachment point of the RenderTargetOutput.
    \list
    \li RenderTargetOutput.Color0
    \li RenderTargetOutput.Color1
    \li RenderTargetOutput.Color2
    \li RenderTargetOutput.Color3
    \li RenderTargetOutput.Color4
    \li RenderTargetOutput.Color5
    \li RenderTargetOutput.Color6
    \li RenderTargetOutput.Color7
    \li RenderTargetOutput.Color8
    \li RenderTargetOutput.Color9
    \li RenderTargetOutput.Color10
    \li RenderTargetOutput.Color11
    \li RenderTargetOutput.Color12
    \li RenderTargetOutput.Color13
    \li RenderTargetOutput.Color14
    \li RenderTargetOutput.Color15
    \li RenderTargetOutput.Depth
    \li RenderTargetOutput.Stencil
    \li RenderTargetOutput.DepthStencil
    \endlist

    \sa Qt3DRender::QRenderTargetOutput::AttachmentPoint
*/

/*!
    \qmlproperty Texture RenderTargetOutput::texture
    Holds the texture attached to the attachment point.
*/

/*!
    \qmlproperty int RenderTargetOutput::mipLevel
    Holds the miplevel of the attached texture the rendering is directed to.
*/

/*!
    \qmlproperty int RenderTargetOutput::layer
    Holds the layer of the attached texture the rendering is directed to.
*/

/*!
    \qmlproperty enumeration RenderTargetOutput::face
    Holds the face of the attached cubemap texture the rendering is directed to.
    \list
    \li Texture.CubeMapPositiveX
    \li Texture.CubeMapNegativeX
    \li Texture.CubeMapPositiveY
    \li Texture.CubeMapNegativeY
    \li Texture.CubeMapPositiveZ
    \li Texture.CubeMapNegativeZ
    \endlist
    \sa Qt3DRender::QAbstractTexture::CubeMapFace
*/

/*!
    \property QRenderTargetOutput::attachmentPoint
    Holds the attachment point of the QRenderTargetOutput.
*/

/*!
    \property QRenderTargetOutput::texture
    Holds the texture attached to the attachment point.
*/

/*!
    \property QRenderTargetOutput::mipLevel
    Holds the miplevel of the attached texture the rendering is directed to.
*/

/*!
    \property QRenderTargetOutput::layer
    Holds the layer of the attached texture the rendering is directed to.
*/

/*!
    \property QRenderTargetOutput::face
    Holds the face of the attached cubemap texture the rendering is directed to.
*/

/*! \internal */
QRenderTargetOutputPrivate::QRenderTargetOutputPrivate()
    : QNodePrivate()
    , m_texture(nullptr)
    , m_attachmentPoint(QRenderTargetOutput::Color0)
    , m_mipLevel(0)
    , m_layer(0)
    , m_face(QAbstractTexture::CubeMapNegativeX)
{
}

/*!
    The constructor creates a new QRenderTargetOutput::QRenderTargetOutput instance
    with the specified \a parent.
 */
QRenderTargetOutput::QRenderTargetOutput(QNode *parent)
    : QNode(*new QRenderTargetOutputPrivate, parent)
{
}

/*! \internal */
QRenderTargetOutput::~QRenderTargetOutput()
{
}

/*! \internal */
QRenderTargetOutput::QRenderTargetOutput(QRenderTargetOutputPrivate &dd, QNode *parent)
    : QNode(dd, parent)
{
}

void QRenderTargetOutput::setAttachmentPoint(QRenderTargetOutput::AttachmentPoint attachmentPoint)
{
    Q_D(QRenderTargetOutput);
    if (attachmentPoint != d->m_attachmentPoint) {
        d->m_attachmentPoint = attachmentPoint;
        emit attachmentPointChanged(attachmentPoint);
    }
}

QRenderTargetOutput::AttachmentPoint QRenderTargetOutput::attachmentPoint() const
{
    Q_D(const QRenderTargetOutput);
    return d->m_attachmentPoint;
}

void QRenderTargetOutput::setTexture(QAbstractTexture *texture)
{
    Q_D(QRenderTargetOutput);
    if (texture != d->m_texture) {

        if (d->m_texture)
            d->unregisterDestructionHelper(d->m_texture);

        // Handle inline declaration
        if (texture && !texture->parent())
            texture->setParent(this);

        d->m_texture = texture;

        // Ensures proper bookkeeping
        if (d->m_texture)
            d->registerDestructionHelper(d->m_texture, &QRenderTargetOutput::setTexture, d->m_texture);

        emit textureChanged(texture);
    }
}

QAbstractTexture *QRenderTargetOutput::texture() const
{
    Q_D(const QRenderTargetOutput);
    return d->m_texture;
}

void QRenderTargetOutput::setMipLevel(int level)
{
    Q_D(QRenderTargetOutput);
    if (d->m_mipLevel != level) {
        d->m_mipLevel = level;
        emit mipLevelChanged(level);
    }
}

int QRenderTargetOutput::mipLevel() const
{
    Q_D(const QRenderTargetOutput);
    return d->m_mipLevel;
}

void QRenderTargetOutput::setLayer(int layer)
{
    Q_D(QRenderTargetOutput);
    if (d->m_layer != layer) {
        d->m_layer = layer;
        emit layerChanged(layer);
    }
}

int QRenderTargetOutput::layer() const
{
    Q_D(const QRenderTargetOutput);
    return d->m_layer;
}

void QRenderTargetOutput::setFace(QAbstractTexture::CubeMapFace face)
{
    Q_D(QRenderTargetOutput);
    if (d->m_face != face) {
        d->m_face = face;
        emit faceChanged(face);
    }
}

QAbstractTexture::CubeMapFace QRenderTargetOutput::face() const
{
    Q_D(const QRenderTargetOutput);
    return d->m_face;
}

Qt3DCore::QNodeCreatedChangeBasePtr QRenderTargetOutput::createNodeCreationChange() const
{
    auto creationChange = Qt3DCore::QNodeCreatedChangePtr<QRenderTargetOutputData>::create(this);
    auto &data = creationChange->data;
    Q_D(const QRenderTargetOutput);
    data.textureId = qIdForNode(texture());
    data.attachmentPoint = d->m_attachmentPoint;
    data.mipLevel = d->m_mipLevel;
    data.layer = d->m_layer;
    data.face = d->m_face;
    return creationChange;
}

} // namespace Qt3DRender

QT_END_NAMESPACE