summaryrefslogtreecommitdiffstats
path: root/src/quick3d/quick3drenderer
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire.ecortex@kdab.com>2014-12-03 09:46:03 +0100
committerSean Harmer <sean.harmer@kdab.com>2014-12-12 14:17:38 +0100
commit634285f5e0c2555bd108f5f8ed979a0a18505429 (patch)
tree8a636c9ebb4e88a047449973856510786c582401 /src/quick3d/quick3drenderer
parent6bf131dc207ed34f7f5cf8c6edb5554c821cf2df (diff)
Quick3DShaderData for QJSValue handling
Quick3DShaderData subclasses QShaderData. QShaderData now provides a PropertyReaderInterface that returns a correct QVariant from the QVariant return when reading a QProperty. That way Quick3DShaderData properties (var) can be transformed to a QVariantList that the Renderer can use without introducing a QtQml dependency in core. RenderShaderData was updated to use propertyReader as well on creation and NodeUpdated events. A QJSValue -> QVariantList QMetatype converter was introduced to ease that process. Change-Id: Ifde5e7b85a1a84342846cd0ac0f047bd2c6ec4ef Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/quick3d/quick3drenderer')
-rw-r--r--src/quick3d/quick3drenderer/items/items.pri6
-rw-r--r--src/quick3d/quick3drenderer/items/quick3dparameter.cpp4
-rw-r--r--src/quick3d/quick3drenderer/items/quick3dshaderdata.cpp89
-rw-r--r--src/quick3d/quick3drenderer/items/quick3dshaderdata.h77
4 files changed, 172 insertions, 4 deletions
diff --git a/src/quick3d/quick3drenderer/items/items.pri b/src/quick3d/quick3drenderer/items/items.pri
index 8e36d9f28..b00ef0560 100644
--- a/src/quick3d/quick3drenderer/items/items.pri
+++ b/src/quick3d/quick3drenderer/items/items.pri
@@ -13,7 +13,8 @@ HEADERS += \
$$PWD/quick3dframegraphitem.h \
$$PWD/quick3dsortmethod.h \
$$PWD/quick3dparameter_p.h \
- $$PWD/quick3dparameter.h
+ $$PWD/quick3dparameter.h \
+ $$PWD/quick3dshaderdata.h
SOURCES += \
$$PWD/quick3drenderpassfilter.cpp \
@@ -29,6 +30,7 @@ SOURCES += \
$$PWD/quick3drenderpass.cpp \
$$PWD/quick3dframegraphitem.cpp \
$$PWD/quick3dsortmethod.cpp \
- $$PWD/quick3dparameter.cpp
+ $$PWD/quick3dparameter.cpp \
+ $$PWD/quick3dshaderdata.cpp
INCLUDEPATH += $$PWD
diff --git a/src/quick3d/quick3drenderer/items/quick3dparameter.cpp b/src/quick3d/quick3drenderer/items/quick3dparameter.cpp
index c6bb7ca76..229af3e45 100644
--- a/src/quick3d/quick3drenderer/items/quick3dparameter.cpp
+++ b/src/quick3d/quick3drenderer/items/quick3dparameter.cpp
@@ -55,7 +55,7 @@ namespace Quick {
namespace {
-const int QJSValueTypeId = qMetaTypeId<QJSValue>();
+const int qjsValueTypeId = qMetaTypeId<QJSValue>();
}
@@ -66,7 +66,7 @@ Quick3DParameterPrivate::Quick3DParameterPrivate(Quick3DParameter *qq)
void Quick3DParameterPrivate::setValue(const QVariant &value)
{
- if (value.userType() == QJSValueTypeId) {
+ if (value.userType() == qjsValueTypeId) {
QJSValue v = value.value<QJSValue>();
if (v.isArray()) {
QJSValueIterator it(v);
diff --git a/src/quick3d/quick3drenderer/items/quick3dshaderdata.cpp b/src/quick3d/quick3drenderer/items/quick3dshaderdata.cpp
new file mode 100644
index 000000000..5f79c0bf2
--- /dev/null
+++ b/src/quick3d/quick3drenderer/items/quick3dshaderdata.cpp
@@ -0,0 +1,89 @@
+/****************************************************************************
+**
+** 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 "quick3dshaderdata.h"
+#include <private/qshaderdata_p.h>
+
+#include <QMetaProperty>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+namespace Render {
+
+namespace Quick {
+
+namespace {
+
+const int qjsValueTypeId = qMetaTypeId<QJSValue>();
+
+}
+
+class Quick3DShaderDataPropertyReader : public PropertyReaderInterface
+{
+public:
+ QVariant readProperty(const QVariant &v) Q_DECL_OVERRIDE
+ {
+ if (v.userType() == qjsValueTypeId) {
+ QJSValue jsValue = v.value<QJSValue>();
+ if (jsValue.isArray())
+ return v.value<QVariantList>();
+ else if (jsValue.isVariant())
+ return jsValue.toVariant();
+ }
+ return v;
+ }
+};
+
+Quick3DShaderData::Quick3DShaderData(QNode *parent)
+ : QShaderData(*new QShaderDataPrivate(this, PropertyReaderInterfacePtr(new Quick3DShaderDataPropertyReader()))
+ , parent)
+{
+}
+
+} // Quick
+
+} // Render
+
+} // Qt3D
+
+QT_END_NAMESPACE
diff --git a/src/quick3d/quick3drenderer/items/quick3dshaderdata.h b/src/quick3d/quick3drenderer/items/quick3dshaderdata.h
new file mode 100644
index 000000000..690d67a84
--- /dev/null
+++ b/src/quick3d/quick3drenderer/items/quick3dshaderdata.h
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** 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$
+**
+****************************************************************************/
+
+#ifndef QT3D_RENDER_QUICK_QUICK3DSHADERDATA_H
+#define QT3D_RENDER_QUICK_QUICK3DSHADERDATA_H
+
+#include <Qt3DQuickRenderer/qt3dquickrenderer_global.h>
+#include <Qt3DRenderer/qshaderdata.h>
+
+#include <QJSValue>
+#include <QJSValueIterator>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+namespace Render {
+
+namespace Quick {
+
+class QT3DQUICKRENDERERSHARED_EXPORT Quick3DShaderData : public QShaderData
+{
+ Q_OBJECT
+public:
+ explicit Quick3DShaderData(QNode *parent = 0);
+
+private:
+ QT3D_CLONEABLE(Quick3DShaderData)
+};
+
+} // Quick
+
+} // Render
+
+} // Qt3D
+
+QT_END_NAMESPACE
+
+#endif // QT3D_RENDER_QUICK_QUICK3DSHADERDATA_H