summaryrefslogtreecommitdiffstats
path: root/src/imports/qtcanvas3d/contextattributes.cpp
blob: b1441dcc63bf6c08081f34b547bc2bf86897e223 (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
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCanvas3D module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** 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.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "contextattributes_p.h"

#include <QVariantMap>
#include <QDebug>

QT_BEGIN_NAMESPACE
QT_CANVAS3D_BEGIN_NAMESPACE

/*!
 * \qmltype Canvas3DContextAttributes
 * \since QtCanvas3D 1.0
 * \inqmlmodule QtCanvas3D
 * \brief Attribute set for Context3D
 *
 * Canvas3DContextAttributes is an attribute set that can be given as parameter on first call to
 * Canvas3D object's \l{Canvas3D::getContext}{getContext(string type, Canvas3DContextAttributes options)}
 * method call.
 * It can also be requested from the Context3D using Context3D::getContextAttributes() later on
 * to verify what exact attributes are in fact enabled/disabled in the created context.
 *
 * \sa Context3D, Canvas3D
 */

CanvasContextAttributes::CanvasContextAttributes(QObject *parent) :
    CanvasAbstractObject(0, parent),
    m_alpha(true),
    m_depth(true),
    m_stencil(false),
    m_antialias(true),
    m_premultipliedAlpha(true),
    m_preserveDrawingBuffer(false),
    m_preferLowPowerToHighPerformance(false),
    m_failIfMajorPerformanceCaveat(false)
{
}

CanvasContextAttributes::~CanvasContextAttributes()
{
}

void CanvasContextAttributes::setFrom(const QVariantMap &options)
{
    for (QVariantMap::const_iterator iter = options.begin(); iter != options.end(); ++iter) {
        if (iter.key() == "alpha")
            setAlpha(iter.value().toBool());
        else if (iter.key() == "depth")
            setDepth(iter.value().toBool());
        else if (iter.key() == "stencil")
            setStencil(iter.value().toBool());
        else if (iter.key() == "antialias")
            setAntialias(iter.value().toBool());
        else if (iter.key() == "premultipliedAlpha")
            setPremultipliedAlpha(iter.value().toBool());
        else if (iter.key() == "preserveDrawingBuffer")
            setPreserveDrawingBuffer(iter.value().toBool());
        else if (iter.key() == "preferLowPowerToHighPerformance")
            setPreferLowPowerToHighPerformance(iter.value().toBool());
        else if (iter.key() == "failIfMajorPerformanceCaveat")
            setFailIfMajorPerformanceCaveat(iter.value().toBool());
    }
}

void CanvasContextAttributes::setFrom(const CanvasContextAttributes &source)
{
    m_alpha = source.alpha();
    m_depth = source.depth();
    m_stencil = source.stencil();
    m_antialias = source.antialias();
    m_premultipliedAlpha = source.premultipliedAlpha();
    m_preserveDrawingBuffer = source.preserveDrawingBuffer();
    m_preferLowPowerToHighPerformance = source.preferLowPowerToHighPerformance();
    m_failIfMajorPerformanceCaveat = source.failIfMajorPerformanceCaveat();
}

/*!
 * \qmlproperty bool Canvas3DContextAttributes::alpha
 * Specifies whether the default render target of the Context3D has an alpha channel for the
 * purposes of blending its contents with overlapping Qt Quick items.
 * Defaults to \c{true}.
 */
bool CanvasContextAttributes::alpha()  const
{
    return m_alpha;
}

void CanvasContextAttributes::setAlpha(bool value)
{
    if (m_alpha == value)
        return;

    m_alpha = value;
    emit alphaChanged(value);
}

/*!
 * \qmlproperty bool Canvas3DContextAttributes::depth
 * Specifies whether a depth attachment is to be created and attached to the default render target
 * of the Context3D.
 * Defaults to \c{true}.
 */
bool CanvasContextAttributes::depth() const
{
    return m_depth;
}

void CanvasContextAttributes::setDepth(bool value)
{
    if (m_depth == value)
        return;

    m_depth = value;
    emit depthChanged(value);
}

/*!
 * \qmlproperty bool Canvas3DContextAttributes::stencil
 * Specifies whether a stencil attachment is to be created and attached to the default render
 * target of the Context3D.
 * Defaults to \c{false}.
 */
bool CanvasContextAttributes::stencil() const
{
    return m_stencil;
}

void CanvasContextAttributes::setStencil(bool value)
{
    if (m_stencil == value)
        return;

    m_stencil = value;
    emit stencilChanged(value);
}

/*!
 * \qmlproperty bool Canvas3DContextAttributes::antialias
 * Specifies whether antialiasing buffer is created for the default render target of the Context3D.
 * Defaults to \c{true}.
 */
bool CanvasContextAttributes::antialias() const
{
    return m_antialias;
}

void CanvasContextAttributes::setAntialias(bool value)
{
    if (m_antialias == value)
        return;

    m_antialias = value;
    emit antialiasChanged(value);
}

/*!
 * \qmlproperty bool Canvas3DContextAttributes::premultipliedAlpha
 * Qt Quick always expects premultiplied alpha values when blending Qt Quick items together,
 * so keeping this property \c{true} is recommended. Setting it to \c{false} can cause
 * a minor performance impact, as an additional render pass is needed.
 * Defaults to \c{true}.
 */
bool CanvasContextAttributes::premultipliedAlpha() const
{
    return m_premultipliedAlpha;
}

void CanvasContextAttributes::setPremultipliedAlpha(bool value)
{
    if (m_premultipliedAlpha == value)
        return;

    m_premultipliedAlpha = value;
    emit premultipliedAlphaChanged(value);
}

/*!
 * \qmlproperty bool Canvas3DContextAttributes::preserveDrawingBuffer
 * Specifies whether or not the drawing buffer contents are preserved from frame to frame.
 * Ignored when drawing to the background or the foreground of the Qt Quick scene.
 * Defaults to \c{false}.
 */
bool CanvasContextAttributes::preserveDrawingBuffer() const
{
    return m_preserveDrawingBuffer;
}

void CanvasContextAttributes::setPreserveDrawingBuffer(bool value)
{
    if (m_preserveDrawingBuffer == value)
        return;

    m_preserveDrawingBuffer = value;
    emit preserveDrawingBufferChanged(value);
}

/*!
 * \qmlproperty bool Canvas3DContextAttributes::preferLowPowerToHighPerformance
 * Ignored. Defaults to \c{false}.
 */
bool CanvasContextAttributes::preferLowPowerToHighPerformance() const
{
    return m_preferLowPowerToHighPerformance;
}

void CanvasContextAttributes::setPreferLowPowerToHighPerformance(bool value)
{
    if (m_preferLowPowerToHighPerformance == value)
        return;

    m_preferLowPowerToHighPerformance = value;
    emit preferLowPowerToHighPerformanceChanged(value);
}

/*!
 * \qmlproperty bool Canvas3DContextAttributes::failIfMajorPerformanceCaveat
 * Ignored. Defaults to \c{false}.
 */
bool CanvasContextAttributes::failIfMajorPerformanceCaveat() const
{
    return m_failIfMajorPerformanceCaveat;
}

void CanvasContextAttributes::setFailIfMajorPerformanceCaveat(bool value)
{
    if (m_failIfMajorPerformanceCaveat == value)
        return;

    m_failIfMajorPerformanceCaveat = value;
    emit failIfMajorPerformanceCaveatChanged(value);
}

QDebug operator<<(QDebug dbg, const CanvasContextAttributes &attribs)
{
    dbg.nospace() << "Canvas3DContextAttributes(\n    alpha:"<< attribs.m_alpha  <<
                     "\n    depth:" << attribs.m_depth <<
                     "\n    m_stencil:" << attribs.m_stencil <<
                     "\n    antialias:"<< attribs.m_antialias <<
                     "\n    premultipliedAlpha:" << attribs.m_premultipliedAlpha <<
                     "\n    preserveDrawingBuffer:" << attribs.m_preserveDrawingBuffer <<
                     "\n    preferLowPowerToHighPerformance:" << attribs.m_preferLowPowerToHighPerformance <<
                     "\n    failIfMajorPerformanceCaveat:" << attribs.m_failIfMajorPerformanceCaveat << ")";
    return dbg.maybeSpace();
}

QT_CANVAS3D_END_NAMESPACE
QT_END_NAMESPACE