summaryrefslogtreecommitdiffstats
path: root/src/quick3d/quick3drenderer/items/quick3dmaterial.cpp
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2014-05-07 09:11:57 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-05-25 13:00:39 +0200
commit4070bf8297e5df2f6ee08ca0c1a6ef7c09538573 (patch)
treec43be77e59bd51a7d76fcc19a5af68842313cced /src/quick3d/quick3drenderer/items/quick3dmaterial.cpp
parent9fff1b6e3d8dc62b6295b861cbea931ef71422cc (diff)
Quick3DMaterial subclass of Material
Quick3DMaterial exposes a QQmlListProperty of Tags that are used to set Material parameters and texture. In the near future that may be replace by a custom QQmlCustomParser. Change-Id: I7381691a77768b6f76265ef30b68ab033504c166 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/quick3d/quick3drenderer/items/quick3dmaterial.cpp')
-rw-r--r--src/quick3d/quick3drenderer/items/quick3dmaterial.cpp126
1 files changed, 126 insertions, 0 deletions
diff --git a/src/quick3d/quick3drenderer/items/quick3dmaterial.cpp b/src/quick3d/quick3drenderer/items/quick3dmaterial.cpp
new file mode 100644
index 000000000..839c9de79
--- /dev/null
+++ b/src/quick3d/quick3drenderer/items/quick3dmaterial.cpp
@@ -0,0 +1,126 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D 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 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 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 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "quick3dmaterial.h"
+#include <QDebug>
+#include <Qt3DRenderer/texture.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+namespace Render {
+
+namespace Quick {
+
+Quick3DMaterial::Quick3DMaterial(Node *parent)
+ : Material(parent)
+{
+}
+
+QQmlListProperty<Tag> Quick3DMaterial::qmlParameters()
+{
+ return QQmlListProperty<Tag>(this, 0,
+ &Quick3DMaterial::appendTag,
+ &Quick3DMaterial::tagCount,
+ &Quick3DMaterial::tagAt,
+ &Quick3DMaterial::clearTags );
+}
+
+void Quick3DMaterial::appendTag(QQmlListProperty<Tag> *list, Tag *tag)
+{
+ Quick3DMaterial *mat = qobject_cast<Quick3DMaterial *>(list->object);
+ if (mat) {
+ tag->setParent(mat);
+ QObject::connect(tag, SIGNAL(valueChanged()), mat, SLOT(onTagValueChanged()));
+ mat->m_tagList.append(tag);
+ emit mat->parametersChanged();
+ }
+}
+
+Tag *Quick3DMaterial::tagAt(QQmlListProperty<Tag> *list, int index)
+{
+ Quick3DMaterial *mat = qobject_cast<Quick3DMaterial *>(list->object);
+ if (mat)
+ return mat->m_tagList.value(index);
+ return 0;
+}
+
+int Quick3DMaterial::tagCount(QQmlListProperty<Tag> *list)
+{
+ Quick3DMaterial *mat = qobject_cast<Quick3DMaterial *>(list->object);
+ if (mat)
+ return mat->m_tagList.size();
+ return 0;
+}
+
+void Quick3DMaterial::clearTags(QQmlListProperty<Tag> *list)
+{
+ Quick3DMaterial *mat = qobject_cast<Quick3DMaterial *>(list->object);
+ if (mat) {
+ mat->m_tagList.clear();
+ mat->cleanParameters();
+ emit mat->parametersChanged();
+ }
+}
+
+void Quick3DMaterial::onTagValueChanged()
+{
+ Tag* t = qobject_cast<Tag*>(sender());
+ Q_ASSERT(m_tagList.contains(t));
+
+ QVariant v = t->value();
+ QmlTexture* qmlTex = v.value<QmlTexture*>();
+ if (qmlTex) {
+ qDebug() << "got texture parameter" << t->name();
+ setTextureParameter(t->name(), qmlTex->texture());
+ } else {
+ setParameter(t->name(), t->value());
+ }
+}
+
+} // Quick
+
+} // Render
+
+} // Qt3D
+
+QT_END_NAMESPACE