summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire.ecortex@kdab.com>2014-12-23 10:04:59 +0100
committerSean Harmer <sean.harmer@kdab.com>2014-12-30 21:06:11 +0100
commita51e2b3d3b57a3f9179a1c217a23ead8ddc65c63 (patch)
tree173e595a67a63803a2e5e0a5908e296602ff396c
parent1675b5968365b927e795e239a322c1351fcc5677 (diff)
QML default phong material and generate qrc file
Also registers types contained in the generated qrc file. This allows us to provide types defined by QML files into the plugin that mix seemlessly with the exported C++ types. Change-Id: I19b4afc52130d6edf5aa67a9bce4eeeae9d8b1e5 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
-rw-r--r--examples/simple-qml/main.qml6
-rw-r--r--src/quick3d/imports/render/defaults/defaults.pri8
-rw-r--r--src/quick3d/imports/render/defaults/qml/PhongMaterial.qml121
-rw-r--r--src/quick3d/imports/render/importsrender.pro27
-rw-r--r--src/quick3d/imports/render/qt3dquick3drenderplugin.cpp24
5 files changed, 181 insertions, 5 deletions
diff --git a/examples/simple-qml/main.qml b/examples/simple-qml/main.qml
index 1c394815e..7109512bd 100644
--- a/examples/simple-qml/main.qml
+++ b/examples/simple-qml/main.qml
@@ -81,10 +81,8 @@ Entity {
}
]
-
- Material {
+ PhongMaterial {
id: material
- effect : Effect { }
}
TorusMesh {
@@ -109,8 +107,6 @@ Entity {
components: [ torusMesh, material, torusTransform ]
}
-
-
SphereMesh {
id: sphereMesh
radius: 3
diff --git a/src/quick3d/imports/render/defaults/defaults.pri b/src/quick3d/imports/render/defaults/defaults.pri
new file mode 100644
index 000000000..e4d70857a
--- /dev/null
+++ b/src/quick3d/imports/render/defaults/defaults.pri
@@ -0,0 +1,8 @@
+# When adding new QML files that should be built into the plugin,
+# add them to this variable and they will be listed into a generated
+# resource file.
+#
+# To have the plugin register them as types, add an entries to the
+# qmldir array in qt3dquick3drenderplugin.cpp
+QML_FILES = \
+ $$PWD/qml/PhongMaterial.qml
diff --git a/src/quick3d/imports/render/defaults/qml/PhongMaterial.qml b/src/quick3d/imports/render/defaults/qml/PhongMaterial.qml
new file mode 100644
index 000000000..eea69d508
--- /dev/null
+++ b/src/quick3d/imports/render/defaults/qml/PhongMaterial.qml
@@ -0,0 +1,121 @@
+/****************************************************************************
+**
+** 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$
+**
+****************************************************************************/
+
+import Qt3D 2.0
+import Qt3D.Render 2.0
+
+Material {
+ id:root
+ property color ambient: Qt.rgba( 0.05, 0.05, 0.05, 1.0 )
+ property color diffuse: Qt.rgba( 0.7, 0.7, 0.7, 1.0 )
+ property color specular: Qt.rgba( 0.95, 0.95, 0.95, 1.0 )
+ property real shininess: 150.0
+
+ parameters: [
+ Parameter { name: "ambient"; value: Qt.vector3d(root.ambient.r, root.ambient.g, root.ambient.b) },
+ Parameter { name: "diffuse"; value: Qt.vector3d(root.diffuse.r, root.diffuse.g, root.diffuse.b) },
+ Parameter { name: "specular"; value: Qt.vector3d(root.specular.r, root.specular.g, root.specular.b) },
+ Parameter { name: "shininess"; value: root.shininess }
+ ]
+
+ ShaderProgram {
+ id: gl3PhongShader
+ vertexShaderCode: loadSource("qrc:/shaders/gl3/phong.vert")
+ fragmentShaderCode: loadSource("qrc:/shaders/gl3/phong.frag")
+ }
+
+ ShaderProgram {
+ id: gl2es2PhongShader
+ vertexShaderCode: loadSource("qrc:/shaders/es2/phong.vert")
+ fragmentShaderCode: loadSource("qrc:/shaders/es2/phong.frag")
+ }
+
+ ParameterMapping { id: ambientMapping; parameterName: "ambient"; shaderVariableName: "ka"; bindingType: ParameterMapping.Uniform }
+ ParameterMapping { id: diffuseMapping; parameterName: "diffuse"; shaderVariableName: "kd"; bindingType: ParameterMapping.Uniform }
+ ParameterMapping { id: specularMapping; parameterName: "specular"; shaderVariableName: "ks"; bindingType: ParameterMapping.Uniform }
+
+ effect: Effect {
+ techniques: [
+ // GL 3 Technique
+ Technique {
+ openGLFilter {
+ api: OpenGLFilter.Desktop
+ profile: OpenGLFilter.Core
+ majorVersion: 3
+ minorVersion: 1
+ }
+ renderPasses: RenderPass {
+ bindings: [ambientMapping, diffuseMapping, specularMapping]
+ shaderProgram: gl3PhongShader
+ }
+ },
+
+ // GL 2 Technique
+ Technique {
+ openGLFilter {
+ api: OpenGLFilter.Desktop
+ profile: OpenGLFilter.None
+ majorVersion: 2
+ minorVersion: 0
+ }
+ renderPasses: RenderPass {
+ bindings: [ambientMapping, diffuseMapping, specularMapping]
+ shaderProgram: gl2es2PhongShader
+ }
+ },
+
+ // ES 2 Technique
+ Technique {
+ openGLFilter {
+ api: OpenGLFilter.ES
+ profile: OpenGLFilter.None
+ majorVersion: 2
+ minorVersion: 0
+ }
+ renderPasses: RenderPass {
+ bindings: [ambientMapping, diffuseMapping, specularMapping]
+ shaderProgram: gl2es2PhongShader
+ }
+ }
+ ]
+ }
+}
+
diff --git a/src/quick3d/imports/render/importsrender.pro b/src/quick3d/imports/render/importsrender.pro
index 6f535de2a..2bdb7c7bb 100644
--- a/src/quick3d/imports/render/importsrender.pro
+++ b/src/quick3d/imports/render/importsrender.pro
@@ -13,3 +13,30 @@ SOURCES += \
OTHER_FILES += qmldir
load(qml_plugin)
+
+include(./defaults/defaults.pri)
+
+OTHER_FILES += \
+ $$QML_FILES
+
+# Create a resource file for qml files that need to be registered by the plugin
+GENERATED_RESOURCE_FILE = $$OUT_PWD/defaults.qrc
+INCLUDED_RESOURCE_FILES = $$QML_FILES
+RESOURCE_CONTENT = \
+ "<RCC>" \
+ "<qresource prefix=\"/Qt3D/Render/\">"
+
+for(resourcefile, INCLUDED_RESOURCE_FILES) {
+ resourcefileabsolutepath = $$absolute_path($$resourcefile)
+ relativepath_in = $$relative_path($$resourcefileabsolutepath, $$_PRO_FILE_PWD_)
+ relativepath_out = $$relative_path($$resourcefileabsolutepath, $$OUT_PWD)
+ RESOURCE_CONTENT += "<file alias=\"$$relativepath_in\">$$relativepath_out</file>"
+}
+
+RESOURCE_CONTENT += \
+ "</qresource>" \
+ "</RCC>"
+
+write_file($$GENERATED_RESOURCE_FILE, RESOURCE_CONTENT)|error("Aborting.")
+
+RESOURCES += $$GENERATED_RESOURCE_FILE
diff --git a/src/quick3d/imports/render/qt3dquick3drenderplugin.cpp b/src/quick3d/imports/render/qt3dquick3drenderplugin.cpp
index 27476bde0..cc813539a 100644
--- a/src/quick3d/imports/render/qt3dquick3drenderplugin.cpp
+++ b/src/quick3d/imports/render/qt3dquick3drenderplugin.cpp
@@ -105,8 +105,20 @@
#include <Qt3DQuickRenderer/quick3dshaderdata.h>
#include <Qt3DQuickRenderer/quick3dshaderdataarray.h>
+static void initResources()
+{
+ Q_INIT_RESOURCE(defaults);
+}
+
QT_BEGIN_NAMESPACE
+static const struct {
+ const char *type;
+ int major, minor;
+} qmldir [] = {
+ { "PhongMaterial", 2, 0 }
+};
+
QVariantList QJSValueToVariantListConverter(const QJSValue &jsValue)
{
QVariantList values;
@@ -131,6 +143,9 @@ QVariantList Quick3DShaderDataArrayToVariantListConverter(Qt3D::Render::Quick::Q
void Qt3DQuick3DRenderPlugin::registerTypes(const char *uri)
{
+ // Init resources for defaults QML files
+ initResources();
+
// Converters from QJSValue
QMetaType::registerConverter<QJSValue, QVariantList>(QJSValueToVariantListConverter);
QMetaType::registerConverter<Qt3D::Render::Quick::Quick3DShaderDataArray*, QVariantList>(Quick3DShaderDataArrayToVariantListConverter);
@@ -215,6 +230,15 @@ void Qt3DQuick3DRenderPlugin::registerTypes(const char *uri)
qmlRegisterType<Qt3D::QScissorTest>(uri, 2, 0, "ScissorTest");
qmlRegisterType<Qt3D::QDithering>(uri, 2, 0, "Dithering");
qmlRegisterType<Qt3D::QAlphaCoverage>(uri, 2, 0, "AlphaCoverage");
+
+ // Register types provided as QML files compiled into the plugin
+ for (int i = 0; i < int(sizeof(qmldir) / sizeof(qmldir[0])); i++) {
+ QString path = QStringLiteral("qrc:/Qt3D/Render/defaults/qml/");
+ qmlRegisterType(QUrl(path + qmldir[i].type + QStringLiteral(".qml")),
+ uri,
+ qmldir[i].major, qmldir[i].minor,
+ qmldir[i].type);
+ }
}
QT_END_NAMESPACE