-
Pasi Keranen authored
All JavaScript visible objects are now based on QQmlPropertyMap so that libraries and other users can add dynamic properties to the objects like they do in many cases. Also fixed textured cube example to respect devicePixelRatio. Change-Id: I71a8d8e32e2d856dc1c97f498c9a34b3858ab6a9 Reviewed-by:
Tomi Korpipää <tomi.korpipaa@digia.com> Reviewed-by:
Pasi Keränen <pasi.keranen@digia.com>
8c9c03d6
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** 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 Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/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.LGPLv3 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.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 later as published by the Free
** Software Foundation and appearing in the file LICENSE.GPL included in
** the packaging of this file. Please review the following information to
** ensure the GNU General Public License version 2.0 requirements will be
** met: http://www.gnu.org/licenses/gpl-2.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "contextattributes_p.h"
#include <QVariantMap>
#include <QDebug>
/*!
* \qmltype ContextAttributes
* \since QtCanvas3D 1.0
* \ingroup qtcanvas3d-qml-types
* \brief Attribute set for Context3D
*
* ContextAttributes is an attribute set that can be given as parameter on first call to
* Canvas3D object's \l{Canvas3D::getContext()}{getContext(string type, ContextAttributes options)}
* method call. It can also be requested from the Context3D later on to verify what exact
* attributes are in fact enabled/disabled in the created context.
*
* \sa Context3D, Canvas3D, {QML Canvas 3D QML Types}
*/
/*!
* \internal
*/
CanvasContextAttributes::CanvasContextAttributes(QObject *parent) :
CanvasAbstractObject(parent),
m_alpha(false), // Should be true according to official WebGL spec. But ignored for now.
m_depth(false),
m_stencil(false),
m_antialias(false),
m_premultipliedAlpha(false),
m_preserveDrawingBuffer(false),
m_preferLowPowerToHighPerformance(false),
m_failIfMajorPerformanceCaveat(false)
{
}
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
/*!
* \internal
*/
CanvasContextAttributes::~CanvasContextAttributes()
{
}
/*!
* \internal
*/
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());
}
}
/*!
* \internal
*/
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 ContextAttributes::alpha
* Ignored. Defaults to \c{false}.
*/
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 ContextAttributes::depth
* Specifies whether a depth attachment is to be created and attached to the default render target
* of the Context3D.
141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
* Defaults to \c{false}.
*/
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 ContextAttributes::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 ContextAttributes::antialias
* Specifies whether antialiasing buffer is created for the default render target of the Context3D.
* Defaults to \c{false}.
*/
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 ContextAttributes::premultipliedAlpha
* Ignored. Defaults to \c{false}.
*/
bool CanvasContextAttributes::premultipliedAlpha() const
{
return m_premultipliedAlpha;
}
void CanvasContextAttributes::setPremultipliedAlpha(bool value)
{
if (m_premultipliedAlpha == value)
return;
m_premultipliedAlpha = value;
211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
emit premultipliedAlphaChanged(value);
}
/*!
* \qmlproperty bool ContextAttributes::preserveDrawingBuffer
* Ignored. 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 ContextAttributes::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 ContextAttributes::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);
}
/*!
* \internal
*/
QDebug operator<<(QDebug dbg, const CanvasContextAttributes &attribs)
{
dbg.nospace() << "ContextAttributes(\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 << ")";
281282283
return dbg.maybeSpace();
}