diff options
author | Sean Harmer <sean.harmer@kdab.com> | 2015-09-18 15:46:22 +0100 |
---|---|---|
committer | Paul Lemire <paul.lemire@kdab.com> | 2015-10-13 12:12:58 +0000 |
commit | 9ecf6ab9f8a59058a1171df47e837f5d2a1a9c1b (patch) | |
tree | 45ce990c7fdebaee75b614e9924a4edc08076d83 /src/render/materialsystem | |
parent | 6eabacd020f61da647acd9e544111e028a6af188 (diff) |
Move material system into own directory
Change-Id: Iddc3a5d41dc0aff858d8bc3c5b2f7982bd693d00
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src/render/materialsystem')
48 files changed, 6314 insertions, 0 deletions
diff --git a/src/render/materialsystem/annotation.cpp b/src/render/materialsystem/annotation.cpp new file mode 100644 index 000000000..2d725316a --- /dev/null +++ b/src/render/materialsystem/annotation.cpp @@ -0,0 +1,104 @@ +/**************************************************************************** +** +** 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:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.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 "annotation_p.h" +#include <Qt3DCore/qscenepropertychange.h> + +QT_BEGIN_NAMESPACE + +using namespace Qt3D; + +namespace Qt3DRender { +namespace Render { + +Annotation::Annotation() + : QBackendNode() +{ +} + +Annotation::~Annotation() +{ + cleanup(); +} + +void Annotation::cleanup() +{ +} + +void Annotation::updateFromPeer(Qt3D::QNode *peer) +{ + QAnnotation *criterion = static_cast<QAnnotation *>(peer); + + m_value = criterion->value(); + m_name = criterion->name(); +} + +QVariant Annotation::criterionValue() const +{ + return m_value; +} + +QString Annotation::criterionName() const +{ + return m_name; +} + +void Annotation::sceneChangeEvent(const Qt3D::QSceneChangePtr &e) +{ + QScenePropertyChangePtr propertyChange = qSharedPointerCast<QScenePropertyChange>(e); + if (propertyChange->propertyName() == QByteArrayLiteral("value")) + m_value = propertyChange->value(); + else if (propertyChange->propertyName() == QByteArrayLiteral("name")) + m_name = propertyChange->value().toString(); +} + +bool Annotation::operator ==(const Annotation &other) +{ + if (&other == this) + return true; + return ((other.criterionName() == criterionName()) && + (other.criterionValue() == criterionValue())); +} + +bool Annotation::operator !=(const Annotation &other) +{ + return !operator ==(other); +} + +} // namespace Render +} // namespace Qt3DRender + +QT_END_NAMESPACE diff --git a/src/render/materialsystem/annotation_p.h b/src/render/materialsystem/annotation_p.h new file mode 100644 index 000000000..37c320abf --- /dev/null +++ b/src/render/materialsystem/annotation_p.h @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** 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:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.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$ +** +****************************************************************************/ + +#ifndef QT3DRENDER_RENDER_RENDERANNOTATION_P_H +#define QT3DRENDER_RENDER_RENDERANNOTATION_P_H + +#include <Qt3DRenderer/qannotation.h> +#include <Qt3DCore/qbackendnode.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QAnnotation; + +namespace Render { + +class CriterionManager; + +class Annotation : public Qt3D::QBackendNode +{ +public: + Annotation(); + ~Annotation(); + void cleanup(); + void updateFromPeer(Qt3D::QNode *criterion) Q_DECL_OVERRIDE; + + QVariant criterionValue() const; + QString criterionName() const; + void sceneChangeEvent(const Qt3D::QSceneChangePtr &e) Q_DECL_OVERRIDE; + bool operator ==(const Annotation &other); + bool operator !=(const Annotation &other); + +private: + QVariant m_value; + QString m_name; +}; + +} // namespace Render + +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_RENDER_RENDERANNOTATION_P_H diff --git a/src/render/materialsystem/effect.cpp b/src/render/materialsystem/effect.cpp new file mode 100644 index 000000000..37b73ffa6 --- /dev/null +++ b/src/render/materialsystem/effect.cpp @@ -0,0 +1,125 @@ +/**************************************************************************** +** +** 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:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.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 <Qt3DRenderer/private/effect_p.h> +#include <Qt3DRenderer/private/renderer_p.h> +#include <Qt3DRenderer/qeffect.h> +#include <Qt3DRenderer/qparameter.h> + +#include <Qt3DCore/qscenepropertychange.h> + +#include <QVariant> + +QT_BEGIN_NAMESPACE + +using namespace Qt3D; + +namespace Qt3DRender { +namespace Render { + +Effect::Effect() + : QBackendNode() +{ +} + +Effect::~Effect() +{ + cleanup(); +} + +void Effect::cleanup() +{ +} + +void Effect::updateFromPeer(Qt3D::QNode *peer) +{ + QEffect *effect = static_cast<QEffect *>(peer); + + m_techniques.clear(); + m_parameterPack.clear(); + + Q_FOREACH (QTechnique *t, effect->techniques()) + appendRenderTechnique(t->id()); + + Q_FOREACH (QParameter *p, effect->parameters()) + m_parameterPack.appendParameter(p->id()); +} + +void Effect::sceneChangeEvent(const Qt3D::QSceneChangePtr &e) +{ + QScenePropertyChangePtr propertyChange = qSharedPointerCast<QScenePropertyChange>(e); + QVariant propertyValue = propertyChange->value(); + switch (e->type()) { + + case NodeAdded: + if (propertyChange->propertyName() == QByteArrayLiteral("technique")) + appendRenderTechnique(propertyValue.value<QNodeId>()); + else if (propertyChange->propertyName() == QByteArrayLiteral("parameter")) + m_parameterPack.appendParameter(propertyValue.value<QNodeId>()); + break; + + case NodeRemoved: + if (propertyChange->propertyName() == QByteArrayLiteral("technique")) + m_techniques.removeOne(propertyValue.value<QNodeId>()); + else if (propertyChange->propertyName() == QByteArrayLiteral("parameter")) + m_parameterPack.removeParameter(propertyValue.value<QNodeId>()); + break; + + default : + break; + } +} + +void Effect::appendRenderTechnique(const Qt3D::QNodeId &technique) +{ + if (!m_techniques.contains(technique)) + m_techniques.append(technique); +} + +QList<Qt3D::QNodeId> Effect::techniques() const +{ + return m_techniques; +} + +QList<Qt3D::QNodeId> Effect::parameters() const +{ + return m_parameterPack.parameters(); +} + +} // namespace Render +} // namespace Qt3DRender + +QT_END_NAMESPACE diff --git a/src/render/materialsystem/effect_p.h b/src/render/materialsystem/effect_p.h new file mode 100644 index 000000000..03e9f2d78 --- /dev/null +++ b/src/render/materialsystem/effect_p.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** 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:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.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$ +** +****************************************************************************/ + +#ifndef QT3DRENDER_RENDER_EFFECT_H +#define QT3DRENDER_RENDER_EFFECT_H + +#include <Qt3DRenderer/qt3drenderer_global.h> +#include <Qt3DRenderer/private/parameterpack_p.h> +#include <Qt3DCore/qbackendnode.h> +#include <Qt3DCore/qnodeid.h> +#include <QList> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QTechnique; + +namespace Render { + +class Effect : public Qt3D::QBackendNode +{ +public: + Effect(); + ~Effect(); + void cleanup(); + + void updateFromPeer(Qt3D::QNode *peer) Q_DECL_OVERRIDE; + void sceneChangeEvent(const Qt3D::QSceneChangePtr &e) Q_DECL_OVERRIDE; + void appendRenderTechnique(const Qt3D::QNodeId &t); + + QList<Qt3D::QNodeId> techniques() const; + QList<Qt3D::QNodeId> parameters() const; + +private: + QList<Qt3D::QNodeId> m_techniques; + ParameterPack m_parameterPack; +}; + +} // namespace Render + +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_RENDER_EFFECT_H diff --git a/src/render/materialsystem/material.cpp b/src/render/materialsystem/material.cpp new file mode 100644 index 000000000..c096c1a98 --- /dev/null +++ b/src/render/materialsystem/material.cpp @@ -0,0 +1,127 @@ +/**************************************************************************** +** +** 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:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.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 "material_p.h" +#include "graphicscontext_p.h" +#include "technique_p.h" +#include "effect_p.h" +#include "qparameter.h" +#include "qtechnique.h" +#include "qmaterial.h" +#include "qeffect.h" + +#include <Qt3DCore/qscenepropertychange.h> +#include <QOpenGLShaderProgram> + +using namespace Qt3D; + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { +namespace Render { + +Material::Material() + : QBackendNode() + , m_enabled(true) +{ +} + +Material::~Material() +{ + cleanup(); +} + +void Material::cleanup() +{ + m_parameterPack.clear(); +} + +void Material::updateFromPeer(Qt3D::QNode *node) +{ + QMaterial *mat = static_cast<QMaterial *>(node); + m_parameterPack.clear(); + m_enabled = mat->isEnabled(); + if (mat->effect() != Q_NULLPTR) + m_effectUuid = mat->effect()->id(); + Q_FOREACH (QParameter *p, mat->parameters()) + m_parameterPack.appendParameter(p->id()); +} + +void Material::sceneChangeEvent(const Qt3D::QSceneChangePtr &e) +{ + QScenePropertyChangePtr propertyChange = qSharedPointerCast<QScenePropertyChange>(e); + + switch (e->type()) { + case NodeUpdated: { + if (propertyChange->propertyName() == QByteArrayLiteral("enabled")) + m_enabled = propertyChange->value().toBool(); + break; + } + // Check for shader parameter + case NodeAdded: { + if (propertyChange->propertyName() == QByteArrayLiteral("parameter")) + m_parameterPack.appendParameter(propertyChange->value().value<QNodeId>()); + else if (propertyChange->propertyName() == QByteArrayLiteral("effect")) + m_effectUuid = propertyChange->value().value<QNodeId>(); + break; + } + case NodeRemoved: { + if (propertyChange->propertyName() == QByteArrayLiteral("parameter")) + m_parameterPack.removeParameter(propertyChange->value().value<QNodeId>()); + else if (propertyChange->propertyName() == QByteArrayLiteral("effect")) + m_effectUuid = QNodeId(); + break; + } + + default: + break; + } +} + +QList<Qt3D::QNodeId> Material::parameters() const +{ + return m_parameterPack.parameters(); +} + +Qt3D::QNodeId Material::effect() const +{ + return m_effectUuid; +} + +} // namespace Render +} // namespace Qt3DRender + +QT_END_NAMESPACE diff --git a/src/render/materialsystem/material_p.h b/src/render/materialsystem/material_p.h new file mode 100644 index 000000000..f1f5c6b38 --- /dev/null +++ b/src/render/materialsystem/material_p.h @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** 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:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.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$ +** +****************************************************************************/ + +#ifndef QT3DRENDER_RENDER_MATERIAL_H +#define QT3DRENDER_RENDER_MATERIAL_H + +#include <QVariant> + +#include <Qt3DRenderer/private/quniformvalue_p.h> +#include <Qt3DRenderer/private/parameterpack_p.h> +#include <Qt3DCore/qbackendnode.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QMaterial; +class QParameter; + +namespace Render { + +class Renderer; +class GraphicsContext; +class Technique; +class Effect; +class MaterialManager; + +class Q_AUTOTEST_EXPORT Material : public Qt3D::QBackendNode +{ +public: + Material(); + ~Material(); + void cleanup(); + + void updateFromPeer(Qt3D::QNode* mat) Q_DECL_OVERRIDE; + void sceneChangeEvent(const Qt3D::QSceneChangePtr &e) Q_DECL_OVERRIDE; + inline bool isEnabled() const { return m_enabled; } + + QList<Qt3D::QNodeId> parameters() const; + Qt3D::QNodeId effect() const; + +private: + ParameterPack m_parameterPack; + Qt3D::QNodeId m_effectUuid; + bool m_enabled; +}; + +} // namespace Render +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_RENDER_MATERIAL_H diff --git a/src/render/materialsystem/materialsystem.pri b/src/render/materialsystem/materialsystem.pri new file mode 100644 index 000000000..a52d2297f --- /dev/null +++ b/src/render/materialsystem/materialsystem.pri @@ -0,0 +1,52 @@ +INCLUDEPATH += $$PWD + +HEADERS += \ + $$PWD/annotation_p.h \ + $$PWD/effect_p.h \ + $$PWD/material_p.h \ + $$PWD/parameter_p.h \ + $$PWD/parametermapping_p.h \ + $$PWD/qannotation.h \ + $$PWD/qannotation_p.h \ + $$PWD/qeffect.h \ + $$PWD/qeffect_p.h \ + $$PWD/qmaterial.h \ + $$PWD/qmaterial_p.h \ + $$PWD/qopenglfilter.h \ + $$PWD/qparameter.h \ + $$PWD/qparameter_p.h \ + $$PWD/qparametermapping.h \ + $$PWD/qparametermapping_p.h \ + $$PWD/qrenderpass_p.h \ + $$PWD/qrenderpass.h \ + $$PWD/qshaderdata.h \ + $$PWD/qshaderdata_p.h \ + $$PWD/qshaderprogram.h \ + $$PWD/qshaderprogram_p.h \ + $$PWD/qtechnique.h \ + $$PWD/qtechnique_p.h \ + $$PWD/renderpass_p.h \ + $$PWD/shader_p.h \ + $$PWD/shaderdata_p.h \ + $$PWD/technique_p.h + +SOURCES += \ + $$PWD/annotation.cpp \ + $$PWD/effect.cpp \ + $$PWD/material.cpp \ + $$PWD/parameter.cpp \ + $$PWD/parametermapping.cpp \ + $$PWD/qannotation.cpp \ + $$PWD/qeffect.cpp \ + $$PWD/qmaterial.cpp \ + $$PWD/qopenglfilter.cpp \ + $$PWD/qparameter.cpp \ + $$PWD/qparametermapping.cpp \ + $$PWD/qrenderpass.cpp \ + $$PWD/qshaderdata.cpp \ + $$PWD/qshaderprogram.cpp \ + $$PWD/qtechnique.cpp \ + $$PWD/renderpass.cpp \ + $$PWD/shader.cpp \ + $$PWD/shaderdata.cpp \ + $$PWD/technique.cpp diff --git a/src/render/materialsystem/parameter.cpp b/src/render/materialsystem/parameter.cpp new file mode 100644 index 000000000..afc44ed58 --- /dev/null +++ b/src/render/materialsystem/parameter.cpp @@ -0,0 +1,117 @@ +/**************************************************************************** +** +** 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:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.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 "parameter_p.h" +#include <Qt3DCore/qscenepropertychange.h> +#include <Qt3DRenderer/qparameter.h> +#include <Qt3DRenderer/qtexture.h> +#include <Qt3DRenderer/qshaderdata.h> + +#include <Qt3DRenderer/private/managers_p.h> + +QT_BEGIN_NAMESPACE + +using namespace Qt3D; + +namespace Qt3DRender { +namespace Render { + +Parameter::Parameter() + : QBackendNode() + , m_shaderDataManager(Q_NULLPTR) + , m_textureManager(Q_NULLPTR) +{ +} + +void Parameter::updateFromPeer(Qt3D::QNode *mat) +{ + QParameter *param = static_cast<QParameter *>(mat); + m_name = param->name(); + m_value = toBackendValue(param->value()); +} + +void Parameter::sceneChangeEvent(const Qt3D::QSceneChangePtr &e) +{ + QScenePropertyChangePtr propertyChange = qSharedPointerCast<QScenePropertyChange>(e); + + if (e->type() == NodeUpdated) { + if (propertyChange->propertyName() == QByteArrayLiteral("name")) + m_name = propertyChange->value().toString(); + else if (propertyChange->propertyName() == QByteArrayLiteral("value")) + m_value = toBackendValue(propertyChange->value()); + } +} + +QString Parameter::name() const +{ + return m_name; +} + +QVariant Parameter::value() const +{ + return m_value; +} + +void Parameter::setShaderDataManager(ShaderDataManager *shaderDataManager) +{ + m_shaderDataManager = shaderDataManager; +} + +void Parameter::setTextureManager(TextureManager *textureManager) +{ + m_textureManager = textureManager; +} + +QVariant Parameter::toBackendValue(const QVariant &value) +{ + QNode *node = value.value<QNode *>(); + + if (node == Q_NULLPTR) { + return value; + } else if (qobject_cast<QAbstractTextureProvider*>(node)) { + return QVariant::fromValue(static_cast<Texture*>(createBackendNode(node))); + } else if (qobject_cast<QShaderData*>(node)) { + return QVariant::fromValue(static_cast<ShaderData*>(createBackendNode(node))); + } else { + qFatal("Texture and ShaderData are the only types of Node allowed as parameters"); + return QVariant(); + } +} + +} // namespace Render +} // namespace Qt3DRender + +QT_END_NAMESPACE diff --git a/src/render/materialsystem/parameter_p.h b/src/render/materialsystem/parameter_p.h new file mode 100644 index 000000000..4ea1cea37 --- /dev/null +++ b/src/render/materialsystem/parameter_p.h @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** 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:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.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$ +** +****************************************************************************/ + +#ifndef QT3DRENDER_RENDER_PARAMETER_P_H +#define QT3DRENDER_RENDER_PARAMETER_P_H + +#include <Qt3DCore/qbackendnode.h> +#include <QVariant> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +namespace Render { + +class ParameterManager; +class ShaderDataManager; +class TextureManager; + +class Parameter : public Qt3D::QBackendNode +{ +public: + Parameter(); + + void updateFromPeer(Qt3D::QNode* mat) Q_DECL_OVERRIDE; + void sceneChangeEvent(const Qt3D::QSceneChangePtr &e) Q_DECL_OVERRIDE; + + QString name() const; + QVariant value() const; + + void setShaderDataManager(ShaderDataManager *shaderDataManager); + void setTextureManager(TextureManager *textureManager); + +private: + QVariant toBackendValue(const QVariant &value); + + ShaderDataManager *m_shaderDataManager; + TextureManager *m_textureManager; + + QString m_name; + QVariant m_value; +}; + +} // namespace Render + +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_RENDER_PARAMETER_P_H diff --git a/src/render/materialsystem/parametermapping.cpp b/src/render/materialsystem/parametermapping.cpp new file mode 100644 index 000000000..a05d11b66 --- /dev/null +++ b/src/render/materialsystem/parametermapping.cpp @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2015 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:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.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 "parametermapping_p.h" + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { +namespace Render { + +ParameterMapping::ParameterMapping() + : m_bindingType(QParameterMapping::Uniform) +{ +} + +ParameterMapping::ParameterMapping(QParameterMapping *mapping) + : m_id(mapping ? mapping->id() : Qt3D::QNodeId()) + , m_parameterName(mapping ? mapping->parameterName() : QString()) + , m_shaderVariableName(mapping ? mapping->shaderVariableName() : QString()) + , m_bindingType(mapping ? mapping->bindingType() : QParameterMapping::Uniform) +{ +} + +bool ParameterMapping::isValid() const +{ + return !m_id.isNull(); +} + +Qt3D::QNodeId ParameterMapping::id() const +{ + return m_id; +} + +QString ParameterMapping::parameterName() const +{ + return m_parameterName; +} + +QString ParameterMapping::shaderVariableName() const +{ + return m_shaderVariableName; +} + +QParameterMapping::Binding ParameterMapping::bindingType() const +{ + return m_bindingType; +} + +} // namespace Render +} // namespace Qt3DRender + +QT_END_NAMESPACE diff --git a/src/render/materialsystem/parametermapping_p.h b/src/render/materialsystem/parametermapping_p.h new file mode 100644 index 000000000..ead8baf9a --- /dev/null +++ b/src/render/materialsystem/parametermapping_p.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2015 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:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.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$ +** +****************************************************************************/ + +#ifndef QT3DRENDER_RENDER_PARAMETERMAPPING_P_H +#define QT3DRENDER_RENDER_PARAMETERMAPPING_P_H + +#include <Qt3DRenderer/qparametermapping.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +namespace Render { + +class Q_AUTOTEST_EXPORT ParameterMapping +{ +public: + ParameterMapping(); + ParameterMapping(QParameterMapping *mapping); + + bool isValid() const; + + Qt3D::QNodeId id() const; + QString parameterName() const; + QString shaderVariableName() const; + QParameterMapping::Binding bindingType() const; + +private: + Qt3D::QNodeId m_id; + QString m_parameterName; + QString m_shaderVariableName; + QParameterMapping::Binding m_bindingType; +}; + +} // namespace Render + +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_RENDER_PARAMETERMAPPING_P_H diff --git a/src/render/materialsystem/qannotation.cpp b/src/render/materialsystem/qannotation.cpp new file mode 100644 index 000000000..85a46fcbe --- /dev/null +++ b/src/render/materialsystem/qannotation.cpp @@ -0,0 +1,146 @@ +/**************************************************************************** +** +** 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:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.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 "qannotation.h" +#include "qannotation_p.h" +#include <private/qnode_p.h> +#include <Qt3DCore/qscenepropertychange.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + + +/*! + \class Qt3DRender::QAnnotationPrivate + \internal +*/ +QAnnotationPrivate::QAnnotationPrivate() + : QNodePrivate() +{ +} + +/*! + \class Qt3DRender::QAnnotation + \inmodule Qt3DRenderer + \since 5.5 + \brief The QAnnotation class provides ... +*/ + +/*! + \qmltype Annotation + \instantiates Qt3DRender::QAnnotation + \inherits Node + \inqmlmodule Qt3D.Renderer + \since 5.5 + \brief For annotating ... +*/ + +/*! + Copies the annotation in \a ref into this annotation. + */ +void QAnnotation::copy(const QNode *ref) +{ + QNode::copy(ref); + const QAnnotation *criterion = static_cast<const QAnnotation*>(ref); + d_func()->m_name = criterion->d_func()->m_name; + d_func()->m_value = criterion->d_func()->m_value; +} + +/*! + The constructor creats a new annotation under \a parent. + */ +QAnnotation::QAnnotation(QNode *parent) + : QNode(*new QAnnotationPrivate, parent) +{ +} + +QAnnotation::~QAnnotation() +{ + QNode::cleanup(); +} + +void QAnnotation::setValue(const QVariant &value) +{ + Q_D(QAnnotation); + if (value != d->m_value) { + d->m_value = value; + emit valueChanged(); + } +} + +void QAnnotation::setName(const QString &name) +{ + Q_D(QAnnotation); + if (name != d->m_name) { + d->m_name = name; + emit nameChanged(); + } +} + +/*! + \property QAnnotation::value + +*/ + +/*! + \qmlproperty variant Qt3D.Renderer::Annotation::value +*/ + +QVariant QAnnotation::value() const +{ + Q_D(const QAnnotation); + return d->m_value; +} + +/*! + \property QAnnotation::name + + */ + +/*! + \qmlproperty string Qt3D.Renderer::Annotation::name + */ + +QString QAnnotation::name() const +{ + Q_D(const QAnnotation); + return d->m_name; +} + +} // namespace Qt3DRender + +QT_END_NAMESPACE diff --git a/src/render/materialsystem/qannotation.h b/src/render/materialsystem/qannotation.h new file mode 100644 index 000000000..158ebdc77 --- /dev/null +++ b/src/render/materialsystem/qannotation.h @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** 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:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.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$ +** +****************************************************************************/ + +#ifndef QT3DRENDER_QANNOTATION_H +#define QT3DRENDER_QANNOTATION_H + +#include <Qt3DRenderer/qt3drenderer_global.h> +#include <Qt3DCore/qnode.h> +#include <QVariant> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QAnnotationPrivate; + +class QT3DRENDERERSHARED_EXPORT QAnnotation : public Qt3D::QNode +{ + Q_OBJECT + Q_PROPERTY(QVariant value READ value WRITE setValue NOTIFY valueChanged) + Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) +public: + explicit QAnnotation(Qt3D::QNode *parent = 0); + ~QAnnotation(); + + void setValue(const QVariant &value); + void setName(const QString &customType); + + QVariant value() const; + QString name() const; + +Q_SIGNALS: + void nameChanged(); + void valueChanged(); + +protected: + void copy(const Qt3D::QNode *ref) Q_DECL_OVERRIDE; + +private: + Q_DECLARE_PRIVATE(QAnnotation) + QT3D_CLONEABLE(QAnnotation) +}; + +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_QANNOTATION_H diff --git a/src/render/materialsystem/qannotation_p.h b/src/render/materialsystem/qannotation_p.h new file mode 100644 index 000000000..e61ee0c35 --- /dev/null +++ b/src/render/materialsystem/qannotation_p.h @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** 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:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.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$ +** +****************************************************************************/ + +#ifndef QT3DRENDER_QANNOTATION_P_H +#define QT3DRENDER_QANNOTATION_P_H + +#include <Qt3DCore/private/qnode_p.h> +#include <Qt3DRenderer/qannotation.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QAnnotationPrivate : public Qt3D::QNodePrivate +{ +public: + QAnnotationPrivate(); + + Q_DECLARE_PUBLIC(QAnnotation) + QString m_name; + QVariant m_value; +}; + +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_QANNOTATION_P_H diff --git a/src/render/materialsystem/qeffect.cpp b/src/render/materialsystem/qeffect.cpp new file mode 100644 index 000000000..443571872 --- /dev/null +++ b/src/render/materialsystem/qeffect.cpp @@ -0,0 +1,184 @@ +/**************************************************************************** +** +** 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:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.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 "qeffect.h" +#include "qeffect_p.h" +#include "qtechnique.h" +#include "qparameter.h" + +#include <Qt3DCore/qscenepropertychange.h> + +QT_BEGIN_NAMESPACE + +using namespace Qt3D; + +namespace Qt3DRender { + +/*! + \class Qt3DRender::QEffectPrivate + \internal +*/ +QEffectPrivate::QEffectPrivate() + : QNodePrivate() +{ +} + +QEffect::QEffect(QNode *parent) + : QNode(*new QEffectPrivate, parent) +{ +} + +QEffect::~QEffect() +{ + QNode::cleanup(); +} + +void QEffect::copy(const QNode* ref) +{ + QNode::copy(ref); + const QEffect *effect = static_cast<const QEffect*>(ref); + Q_FOREACH (QParameter *p, effect->d_func()->m_parameters) + addParameter(qobject_cast<QParameter *>(QNode::clone(p))); + + Q_FOREACH (QTechnique *t, effect->d_func()->m_techniques) + addTechnique(qobject_cast<QTechnique *>(QNode::clone(t))); +} + +/*! \internal */ +QEffect::QEffect(QEffectPrivate &dd, QNode *parent) + : QNode(dd, parent) +{ +} + +void QEffect::addParameter(QParameter *parameter) +{ + Q_D(QEffect); + if (!d->m_parameters.contains(parameter)) { + d->m_parameters.append(parameter); + + // We need to add it as a child of the current node if it has been declared inline + // Or not previously added as a child of the current node so that + // 1) The backend gets notified about it's creation + // 2) When the current node is destroyed, it gets destroyed as well + if (!parameter->parent()) + parameter->setParent(this); + + if (d->m_changeArbiter != Q_NULLPTR) { + QScenePropertyChangePtr change(new QScenePropertyChange(NodeAdded, QSceneChange::Node, id())); + change->setPropertyName("parameter"); + change->setValue(QVariant::fromValue(parameter->id())); + d->notifyObservers(change); + } + } +} + +void QEffect::removeParameter(QParameter *parameter) +{ + Q_D(QEffect); + + if (d->m_changeArbiter != Q_NULLPTR) { + QScenePropertyChangePtr change(new QScenePropertyChange(NodeRemoved, QSceneChange::Node, id())); + change->setPropertyName("parameter"); + change->setValue(QVariant::fromValue(parameter->id())); + d->notifyObservers(change); + } + d->m_parameters.removeOne(parameter); +} + +QList<QParameter *> QEffect::parameters() const +{ + Q_D(const QEffect); + return d->m_parameters; +} + +/*! + * Adds a new technique \a t to the effect. This posts a CommponentAdded + * QScenePropertyChange notification to the QChangeArbiter, the value is + * the added technique and the property name is "technique". + */ +void QEffect::addTechnique(QTechnique *t) +{ + Q_ASSERT(t); + Q_D(QEffect); + if (!d->m_techniques.contains(t)) { + d->m_techniques.append(t); + + // We need to add it as a child of the current node if it has been declared inline + // Or not previously added as a child of the current node so that + // 1) The backend gets notified about it's creation + // 2) When the current node is destroyed, tit gets destroyed as well + if (!t->parent()) + t->setParent(this); + + if (d->m_changeArbiter != Q_NULLPTR) { + QScenePropertyChangePtr e(new QScenePropertyChange(NodeAdded, QSceneChange::Node, id())); + e->setPropertyName("technique"); + e->setValue(QVariant::fromValue(t->id())); + d->notifyObservers(e); + } + } +} + +/*! + * Removes a technique \a t from the effect. This posts a ComponentRemoved + * QScenePropertyChange notification to the QChangeArbiter, the value is + * the removed technique's id and the property name is "technique". + */ +void QEffect::removeTechnique(QTechnique *t) +{ + Q_D(QEffect); + if (d->m_changeArbiter != Q_NULLPTR) { + QScenePropertyChangePtr e(new QScenePropertyChange(NodeRemoved, QSceneChange::Node, id())); + e->setPropertyName("technique"); + e->setValue(QVariant::fromValue(t->id())); + d->notifyObservers(e); + } + d->m_techniques.removeOne(t); +} + +/*! + * Returns the list of techniques used by the effect. + */ +QList<QTechnique *> QEffect::techniques() const +{ + Q_D(const QEffect); + return d->m_techniques; +} + + +} // namespace Qt3DRender + +QT_END_NAMESPACE diff --git a/src/render/materialsystem/qeffect.h b/src/render/materialsystem/qeffect.h new file mode 100644 index 000000000..164a6392a --- /dev/null +++ b/src/render/materialsystem/qeffect.h @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** 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:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.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$ +** +****************************************************************************/ + +#ifndef QT3DRENDER_QEFFECT_H +#define QT3DRENDER_QEFFECT_H + +#include <Qt3DCore/qnode.h> +#include <Qt3DRenderer/qt3drenderer_global.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QParameter; +class QTechnique; +class QEffectPrivate; + +class QT3DRENDERERSHARED_EXPORT QEffect + : public Qt3D::QNode +{ + Q_OBJECT +public: + explicit QEffect(Qt3D::QNode *parent = 0); + ~QEffect(); + + void addParameter(QParameter *parameter); + void removeParameter(QParameter *parameter); + QList<QParameter *> parameters() const; + + virtual void addTechnique(QTechnique *t); + virtual void removeTechnique(QTechnique *t); + QList<QTechnique *> techniques() const; + +protected: + QEffect(QEffectPrivate &dd, Qt3D::QNode *parent = 0); + void copy(const Qt3D::QNode *ref) Q_DECL_OVERRIDE; + +private: + Q_DECLARE_PRIVATE(QEffect) + QT3D_CLONEABLE(QEffect) +}; + +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_QEFFECT_H diff --git a/src/render/materialsystem/qeffect_p.h b/src/render/materialsystem/qeffect_p.h new file mode 100644 index 000000000..7b9ca5b99 --- /dev/null +++ b/src/render/materialsystem/qeffect_p.h @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** 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:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.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$ +** +****************************************************************************/ + +#ifndef QT3DRENDER_QEFFECT_P_H +#define QT3DRENDER_QEFFECT_P_H + +#include <private/qnode_p.h> +#include <Qt3DRenderer/qt3drenderer_global.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QEffect; +class QParameter; +class QTechnique; + +class QT3DRENDERERSHARED_EXPORT QEffectPrivate : public Qt3D::QNodePrivate +{ +public : + QEffectPrivate(); + + Q_DECLARE_PUBLIC(QEffect) + QList<QParameter *> m_parameters; + QList<QTechnique *> m_techniques; +}; + +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_QEFFECT_P_H diff --git a/src/render/materialsystem/qmaterial.cpp b/src/render/materialsystem/qmaterial.cpp new file mode 100644 index 000000000..b3c833556 --- /dev/null +++ b/src/render/materialsystem/qmaterial.cpp @@ -0,0 +1,207 @@ +/**************************************************************************** +** +** 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:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.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 "qmaterial.h" +#include "qmaterial_p.h" +#include "qtexture.h" +#include "qeffect.h" +#include <Qt3DRenderer/private/renderlogging_p.h> +#include "qparameter.h" +#include <Qt3DCore/qscenepropertychange.h> + +/*! + * \class Qt3DRender::QMaterial + * \inmodule Qt3DRenderer + * + * \inherits Component + * + * \brief Provides an abstract class that should be the base of all + * Material component classes in a scene. + * + * QAbstractMaterial provide a way to specify the rendering of an Entity. + * Any aspect can define its own subclass of QAbstractMaterial so that a + * Material can be used to describe a visual element; for example, the way + * sound should reflect off an element, the temperature of a surface, + * and so on. + * + * \sa QEffect, QMesh, {Qt3D::}{QComponent} + */ + +QT_BEGIN_NAMESPACE + +using namespace Qt3D; + +namespace Qt3DRender { + +/*! + \class Qt3DRender::QMaterialPrivate + \internal +*/ +QMaterialPrivate::QMaterialPrivate() + : QComponentPrivate() + , m_effect(Q_NULLPTR) +{ +} + +void QMaterial::copy(const QNode *ref) +{ + QComponent::copy(ref); + const QMaterial *material = static_cast<const QMaterial*>(ref); + Q_FOREACH (QParameter *p, material->d_func()->m_parameters) + addParameter(qobject_cast<QParameter *>(QNode::clone(p))); + + // TO DO: We may want to copy the node id of the effect and only send a clone + // when we are the parent of the effect + if (material->d_func()->m_effect && material->d_func()->m_effect->parent() == ref) + setEffect(qobject_cast<QEffect *>(QNode::clone(material->d_func()->m_effect))); +} + +QMaterial::QMaterial(QNode *parent) + : QComponent(*new QMaterialPrivate, parent) +{ +} + +QMaterial::~QMaterial() +{ + QNode::cleanup(); +} + +/*! \internal */ +QMaterial::QMaterial(QMaterialPrivate &dd, QNode *parent) + : QComponent(dd, parent) +{ +} + +/*! + * Sets the \a effect to be used with the Material. + */ +void QMaterial::setEffect(QEffect *effect) +{ + Q_D(QMaterial); + if (effect != d->m_effect) { + + if (d->m_effect && d->m_changeArbiter) { + QScenePropertyChangePtr change(new QScenePropertyChange(NodeRemoved, QSceneChange::Node, id())); + change->setPropertyName("effect"); + change->setValue(QVariant::fromValue(d->m_effect->id())); + d->notifyObservers(change); + } + + d->m_effect = effect; + const bool blocked = blockNotifications(true); + emit effectChanged(); + blockNotifications(blocked); + // We need to add it as a child of the current node if it has been declared inline + // Or not previously added as a child of the current node so that + // 1) The backend gets notified about it's creation + // 2) When the current node is destroyed, it gets destroyed as well + if (effect && !effect->parent()) + effect->setParent(this); + + if (d->m_effect && d->m_changeArbiter) { + QScenePropertyChangePtr change(new QScenePropertyChange(NodeAdded, QSceneChange::Node, id())); + change->setPropertyName("effect"); + change->setValue(QVariant::fromValue(effect->id())); + d->notifyObservers(change); + } + } +} + +/*! + * Returns the effect used by the Material. + */ +QEffect *QMaterial::effect() const +{ + Q_D(const QMaterial); + return d->m_effect; +} + +void QMaterial::addParameter(QParameter *parameter) +{ + Q_D(QMaterial); + if (!d->m_parameters.contains(parameter)) { + d->m_parameters.append(parameter); + + // We need to add it as a child of the current node if it has been declared inline + // Or not previously added as a child of the current node so that + // 1) The backend gets notified about it's creation + // 2) When the current node is destroyed, it gets destroyed as well + if (!parameter->parent()) + parameter->setParent(this); + + if (d->m_changeArbiter != Q_NULLPTR) { + QScenePropertyChangePtr change(new QScenePropertyChange(NodeAdded, QSceneChange::Node, id())); + change->setPropertyName("parameter"); + change->setValue(QVariant::fromValue(parameter->id())); + d->notifyObservers(change); + } + } +} + +void QMaterial::removeParameter(QParameter *parameter) +{ + Q_D(QMaterial); + if (d->m_changeArbiter != Q_NULLPTR) { + QScenePropertyChangePtr change(new QScenePropertyChange(NodeRemoved, QSceneChange::Node, id())); + change->setPropertyName("parameter"); + change->setValue(QVariant::fromValue(parameter->id())); + d->notifyObservers(change); + } + d->m_parameters.removeOne(parameter); +} + +QList<QParameter *> QMaterial::parameters() const +{ + Q_D(const QMaterial); + return d->m_parameters; +} + +TextureDict QMaterial::textureValues() const +{ + Q_D(const QMaterial); + return d->m_textures; +} + +// TO DO: Check if this is really needed +void QMaterial::setTextureParameter(QString name, QAbstractTextureProvider *tex) +{ + Q_D(QMaterial); + d->m_textures[name] = tex; +} + +} // namespace Qt3DRender + +QT_END_NAMESPACE diff --git a/src/render/materialsystem/qmaterial.h b/src/render/materialsystem/qmaterial.h new file mode 100644 index 000000000..ca44901c1 --- /dev/null +++ b/src/render/materialsystem/qmaterial.h @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** 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:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.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$ +** +****************************************************************************/ + +#ifndef QT3DRENDER_QMATERIAL_H +#define QT3DRENDER_QMATERIAL_H + +#include <QVariant> + +#include <Qt3DCore/qcomponent.h> +#include <Qt3DRenderer/qt3drenderer_global.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QAbstractTextureProvider; +class QParameter; +class QMaterialPrivate; +class QEffect; +typedef QMap<QString, QAbstractTextureProvider*> TextureDict; + +class QT3DRENDERERSHARED_EXPORT QMaterial : public Qt3D::QComponent +{ + Q_OBJECT + Q_PROPERTY(Qt3DRender::QEffect *effect READ effect WRITE setEffect NOTIFY effectChanged) + +public: + explicit QMaterial(Qt3D::QNode *parent = 0); + ~QMaterial(); + + void setEffect(QEffect *effect); + QEffect *effect() const; + + void addParameter(QParameter *parameter); + void removeParameter(QParameter *parameter); + QList<QParameter *> parameters() const; + + TextureDict textureValues() const; + + void setTextureParameter(QString name, QAbstractTextureProvider* tex); + +Q_SIGNALS: + void effectChanged(); + +protected: + QMaterial(QMaterialPrivate &dd, Qt3D::QNode *parent = 0); + void copy(const Qt3D::QNode *ref) Q_DECL_OVERRIDE; + +private: + Q_DECLARE_PRIVATE(QMaterial) + QT3D_CLONEABLE(QMaterial) +}; + +} + +QT_END_NAMESPACE + +#endif // QT3DRENDER_QMATERIAL_H diff --git a/src/render/materialsystem/qmaterial_p.h b/src/render/materialsystem/qmaterial_p.h new file mode 100644 index 000000000..1ef84e05d --- /dev/null +++ b/src/render/materialsystem/qmaterial_p.h @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** 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:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.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$ +** +****************************************************************************/ + +#ifndef QT3DRENDER_QMATERIAL_P_H +#define QT3DRENDER_QMATERIAL_P_H + +#include <private/qcomponent_p.h> +#include <Qt3DRenderer/qt3drenderer_global.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QParameter; +class QEffect; + +class QT3DRENDERERSHARED_EXPORT QMaterialPrivate : public Qt3D::QComponentPrivate +{ +public: + QMaterialPrivate(); + + Q_DECLARE_PUBLIC(QMaterial) + QList<QParameter *> m_parameters; + TextureDict m_textures; + QEffect *m_effect; +}; + +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_QMATERIAL_P_H diff --git a/src/render/materialsystem/qopenglfilter.cpp b/src/render/materialsystem/qopenglfilter.cpp new file mode 100644 index 000000000..3bc20a84d --- /dev/null +++ b/src/render/materialsystem/qopenglfilter.cpp @@ -0,0 +1,319 @@ +/**************************************************************************** +** +** 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:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.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 "qopenglfilter.h" +#include "private/qobject_p.h" +#include <QOpenGLContext> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QOpenGLFilterPrivate : public QObjectPrivate +{ +public: + QOpenGLFilterPrivate() + : QObjectPrivate() + , m_api(QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL ? QOpenGLFilter::Desktop : QOpenGLFilter::ES) + , m_profile(QOpenGLFilter::None) // matches all (no profile, core, compat) + , m_minor(0) + , m_major(0) + { + } + + Q_DECLARE_PUBLIC(QOpenGLFilter) + QOpenGLFilter::Api m_api; + QOpenGLFilter::Profile m_profile; + int m_minor; + int m_major; + QStringList m_extensions; + QString m_vendor; +}; + +/*! + \class Qt3DRender::QOpenGLFilter + \inmodule Qt3DRenderer + \since 5.5 + \brief The QOpenGLFilter class provides ... +*/ + +/*! + \qmltype OpenGLFilter + \instantiates Qt3DRender::QOpenGLFilter + \inherits QtObject + \inqmlmodule Qt3D.Renderer + \since 5.5 + \brief For OpenGL ... +*/ + +/*! \fn Qt3DRender::QOpenGLFilter::QOpenGLFilter(QObject *parent) + Constructs a new QOpenGLFilter with the specified \a parent. + */ +QOpenGLFilter::QOpenGLFilter(QObject *parent) + : QObject(*new QOpenGLFilterPrivate, parent) +{ +} + +/*! \fn void Qt3DRender::QOpenGLFilter::copy(const QOpenGLFilter &ref) + Copies the \a ref instance into this one. + */ +void QOpenGLFilter::copy(const QOpenGLFilter &ref) +{ + Q_D(QOpenGLFilter); + d->m_api = ref.api(); + d->m_profile = ref.profile(); + d->m_major = ref.majorVersion(); + d->m_minor = ref.minorVersion(); + d->m_extensions = ref.extensions(); + d->m_vendor = ref.vendor(); +} + +/*! + \enum Qt3DRender::QOpenGLFilter::Api + + \value ES QSurfaceFormat::OpenGLES + \value Desktop QSurfaceFormat::OpenGL + +*/ + +/*! + \enum Qt3DRender::QOpenGLFilter::Profile + + \value None QSurfaceFormat::NoProfile + \value Core QSurfaceFormat::CoreProfile + \value Compatibility QSurfaceFormat::CompatibilityProfile + +*/ + +/*! + \property Qt3DRender::QOpenGLFilter::api + +*/ + +/*! + \qmlproperty enumeration Qt3D.Renderer::OpenGLFilter::api + + + \value ES QSurfaceFormat::OpenGLES + \value Desktop QSurfaceFormat::OpenGL +*/ + +QOpenGLFilter::Api QOpenGLFilter::api() const +{ + Q_D(const QOpenGLFilter); + return d->m_api; +} + +/*! + \property Qt3DRender::QOpenGLFilter::profile + +*/ + +/*! + \qmlproperty enumeration Qt3D.Renderer::OpenGLFilter::profile + + \value None QSurfaceFormat::NoProfile + \value Core QSurfaceFormat::CoreProfile + \value Compatibility QSurfaceFormat::CompatibilityProfile +*/ + +QOpenGLFilter::Profile QOpenGLFilter::profile() const +{ + Q_D(const QOpenGLFilter); + return d->m_profile; +} + +/*! + \property Qt3DRender::QOpenGLFilter::minorVersion + + */ + +/*! + \qmlproperty int Qt3D.Renderer::OpenGLFilter::minorVersion + +*/ + +int QOpenGLFilter::minorVersion() const +{ + Q_D(const QOpenGLFilter); + return d->m_minor; +} + +/*! + \property Qt3DRender::QOpenGLFilter::majorVersion + + */ + +/*! + \qmlproperty int Qt3D.Renderer::OpenGLFilter::majorVersion + +*/ + +int QOpenGLFilter::majorVersion() const +{ + Q_D(const QOpenGLFilter); + return d->m_major; +} + +/*! + \property Qt3DRender::QOpenGLFilter::extensions + + */ + +/*! + \qmlproperty stringlist Qt3D.Renderer::OpenGLFilter::extensions + +*/ + +QStringList QOpenGLFilter::extensions() const +{ + Q_D(const QOpenGLFilter); + return d->m_extensions; +} + +/*! + \property Qt3DRender::QOpenGLFilter::vendor + + */ + +/*! + \qmlproperty string Qt3D.Renderer::OpenGLFilter::vendor + +*/ + +QString QOpenGLFilter::vendor() const +{ + Q_D(const QOpenGLFilter); + return d->m_vendor; +} + +void QOpenGLFilter::setApi(QOpenGLFilter::Api api) +{ + Q_D(QOpenGLFilter); + if (d->m_api != api) { + d->m_api = api; + emit apiChanged(); + emit openGLFilterChanged(); + } +} + +void QOpenGLFilter::setProfile(QOpenGLFilter::Profile profile) +{ + Q_D(QOpenGLFilter); + if (d->m_profile != profile) { + d->m_profile = profile; + emit profileChanged(); + emit openGLFilterChanged(); + } +} + +void QOpenGLFilter::setMinorVersion(int minorVersion) +{ + Q_D(QOpenGLFilter); + if (minorVersion != d->m_minor) { + d->m_minor = minorVersion; + emit minorVersionChanged(); + emit openGLFilterChanged(); + } +} + +void QOpenGLFilter::setMajorVersion(int majorVersion) +{ + Q_D(QOpenGLFilter); + if (d->m_major != majorVersion) { + d->m_major = majorVersion; + emit majorVersionChanged(); + emit openGLFilterChanged(); + } +} + +void QOpenGLFilter::setExtensions(const QStringList &extensions) +{ + Q_D(QOpenGLFilter); + if (d->m_extensions != extensions) { + d->m_extensions = extensions; + emit extensionsChanged(); + emit openGLFilterChanged(); + } +} + +void QOpenGLFilter::setVendor(const QString &vendor) +{ + Q_D(QOpenGLFilter); + if (d->m_vendor != vendor) { + d->m_vendor = vendor; + emit vendorChanged(); + emit openGLFilterChanged(); + } +} + +/*! \fn bool Qt3D::operator ==(const QOpenGLFilter &reference, const QOpenGLFilter &sample) + \relates Qt3DRender::QOpenGLFilter + Returns true if \a reference and \a sample are equivalent. + */ +bool operator ==(const QOpenGLFilter &reference, const QOpenGLFilter &sample) +{ + if (sample.api() == reference.api() + && sample.profile() <= reference.profile() + && (sample.majorVersion() < reference.majorVersion() + || (sample.majorVersion() == reference.majorVersion() && sample.minorVersion() <= reference.minorVersion()))) { + Q_FOREACH (const QString &neededExt, sample.extensions()) + if (!reference.extensions().contains(neededExt)) + return false; + // If a vendor name was specified in sample, we perform comparison, + // otherwise we assume the vendor name doesn't matter + if (!sample.vendor().isEmpty()) + return (sample.vendor() == reference.vendor()); + return true; + } + return false; +} + +/*! \fn bool Qt3D::operator !=(const QOpenGLFilter &reference, const QOpenGLFilter &sample) + \relates Qt3DRender::QOpenGLFilter + Returns true if \a reference and \a sample are different. + */ +bool operator !=(const QOpenGLFilter &reference, const QOpenGLFilter &sample) +{ + return !(reference == sample); +} + +/*! \fn void Qt3DRender::QOpenGLFilter::openGLFilterChanged() + This signal is emitted when the value of any property is changed. +*/ +} // namespace Qt3DRender + +QT_END_NAMESPACE diff --git a/src/render/materialsystem/qopenglfilter.h b/src/render/materialsystem/qopenglfilter.h new file mode 100644 index 000000000..9c4b729bd --- /dev/null +++ b/src/render/materialsystem/qopenglfilter.h @@ -0,0 +1,116 @@ +/**************************************************************************** +** +** 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:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.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$ +** +****************************************************************************/ + +#ifndef QT3DRENDER_QOPENGLFILTER_H +#define QT3DRENDER_QOPENGLFILTER_H + +#include <QObject> +#include <QStringList> +#include <Qt3DRenderer/qt3drenderer_global.h> +#include <QSurfaceFormat> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QOpenGLFilterPrivate; + +class QT3DRENDERERSHARED_EXPORT QOpenGLFilter : public QObject +{ + Q_OBJECT + Q_PROPERTY(Qt3DRender::QOpenGLFilter::Api api READ api WRITE setApi NOTIFY apiChanged) + Q_PROPERTY(Qt3DRender::QOpenGLFilter::Profile profile READ profile WRITE setProfile NOTIFY profileChanged) + Q_PROPERTY(int minorVersion READ minorVersion WRITE setMinorVersion NOTIFY minorVersionChanged) + Q_PROPERTY(int majorVersion READ majorVersion WRITE setMajorVersion NOTIFY majorVersionChanged) + Q_PROPERTY(QStringList extensions READ extensions WRITE setExtensions NOTIFY extensionsChanged) + Q_PROPERTY(QString vendor READ vendor WRITE setVendor NOTIFY vendorChanged) + +public: + + enum Api + { + ES = QSurfaceFormat::OpenGLES, + Desktop = QSurfaceFormat::OpenGL + }; + Q_ENUM(Api) + + enum Profile + { + None = QSurfaceFormat::NoProfile, + Core = QSurfaceFormat::CoreProfile, + Compatibility = QSurfaceFormat::CompatibilityProfile + }; + Q_ENUM(Profile) + + explicit QOpenGLFilter(QObject *parent = 0); + + void copy(const QOpenGLFilter &ref); + + Api api() const; + Profile profile() const; + int minorVersion() const; + int majorVersion() const; + QStringList extensions() const; + QString vendor() const; + + void setApi(Api api); + void setProfile(Profile profile); + void setMinorVersion(int minorVersion); + void setMajorVersion(int majorVersion); + void setExtensions(const QStringList &extensions); + void setVendor(const QString &vendor); + +Q_SIGNALS: + void apiChanged(); + void profileChanged(); + void minorVersionChanged(); + void majorVersionChanged(); + void extensionsChanged(); + void vendorChanged(); + void openGLFilterChanged(); + +private: + Q_DECLARE_PRIVATE(QOpenGLFilter) +}; + +bool operator ==(const QOpenGLFilter &reference, const QOpenGLFilter &sample); +bool operator !=(const QOpenGLFilter &reference, const QOpenGLFilter &sample); + +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_QOPENGLFILTER_H diff --git a/src/render/materialsystem/qparameter.cpp b/src/render/materialsystem/qparameter.cpp new file mode 100644 index 000000000..96d1205df --- /dev/null +++ b/src/render/materialsystem/qparameter.cpp @@ -0,0 +1,150 @@ +/**************************************************************************** +** +** 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:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.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 "qparameter.h" +#include <Qt3DRenderer/private/renderlogging_p.h> +#include <Qt3DCore/qscenepropertychange.h> +#include <private/qparameter_p.h> +#include <Qt3DRenderer/qtexture.h> + +QT_BEGIN_NAMESPACE + +using namespace Qt3D; + +namespace Qt3DRender { + +/*! + \class Qt3DRender::QParameterPrivate + \internal +*/ +QParameterPrivate::QParameterPrivate() + : QNodePrivate() +{ +} + +void QParameterPrivate::setValue(const QVariant &v) +{ + m_value = v; +} + +void QParameter::copy(const QNode *ref) +{ + QNode::copy(ref); + const QParameter *param = static_cast<const QParameter*>(ref); + d_func()->m_name = param->d_func()->m_name; + d_func()->m_value = param->d_func()->m_value; +} + +/*! \internal */ +QParameter::QParameter(QParameterPrivate &dd, QNode *parent) + : QNode(dd, parent) +{ +} + +QParameter::QParameter(QNode *parent) + : QNode(*new QParameterPrivate, parent) +{ +} + +QParameter::~QParameter() +{ + QNode::cleanup(); +} + +QParameter::QParameter(const QString &name, const QVariant &value, QNode *parent) + : QNode(*new QParameterPrivate, parent) +{ + Q_D(QParameter); + d->m_name = name; + setValue(value); +} + +QParameter::QParameter(const QString &name, QAbstractTextureProvider *texture, QNode *parent) + : QNode(*new QParameterPrivate, parent) +{ + Q_D(QParameter); + d->m_name = name; + setValue(QVariant::fromValue(texture)); +} + + +void QParameter::setName(const QString &name) +{ + Q_D(QParameter); + if (d->m_name != name) { + d->m_name = name; + emit nameChanged(); + } +} + +QString QParameter::name() const +{ + Q_D(const QParameter); + return d->m_name; +} + +void QParameter::setValue(const QVariant &dv) +{ + Q_D(QParameter); + if (d->m_value != dv) { + d->setValue(dv); + emit valueChanged(); + + // In case texture are declared inline + QNode *txt = dv.value<QNode *>(); + if (txt != Q_NULLPTR && !txt->parent()) + txt->setParent(this); + + QScenePropertyChangePtr change(new QScenePropertyChange(NodeUpdated, QSceneChange::Node, id())); + change->setPropertyName(d->m_name.toUtf8().data()); + if (txt != Q_NULLPTR) + change->setValue(QVariant::fromValue(QNode::clone(txt))); + else + change->setValue(d->m_value); + + d->notifyObservers(change); + } +} + +QVariant QParameter::value() const +{ + Q_D(const QParameter); + return d->m_value; +} + +} // namespace Qt3DRender + +QT_END_NAMESPACE diff --git a/src/render/materialsystem/qparameter.h b/src/render/materialsystem/qparameter.h new file mode 100644 index 000000000..03883f5f1 --- /dev/null +++ b/src/render/materialsystem/qparameter.h @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** 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:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.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$ +** +****************************************************************************/ + +#ifndef QT3DRENDER_QPARAMETER_H +#define QT3DRENDER_QPARAMETER_H + +#include <QVariant> +#include <Qt3DCore/qnode.h> +#include <Qt3DRenderer/qt3drenderer_global.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QParameterPrivate; +class QAbstractTextureProvider; + +class QT3DRENDERERSHARED_EXPORT QParameter : public Qt3D::QNode +{ + Q_OBJECT + Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) + Q_PROPERTY(QVariant value READ value WRITE setValue NOTIFY valueChanged) + +public: + explicit QParameter(Qt3D::QNode *parent = 0); + ~QParameter(); + QParameter(const QString& name, const QVariant& value, Qt3D::QNode* parent = 0); + QParameter(const QString &name, QAbstractTextureProvider *texture, Qt3D::QNode *parent = 0); + + void setName(const QString &name); + QString name() const; + + /** + * @brief setDefaultValue - for non-texture uniform parameters + * @param dv + */ + void setValue(const QVariant& dv); + QVariant value() const; + +Q_SIGNALS: + void valueChanged(); + void nameChanged(); + +protected: + QParameter(QParameterPrivate &dd, Qt3D::QNode *parent = 0); + void copy(const Qt3D::QNode *ref) Q_DECL_OVERRIDE; + +private: + Q_DECLARE_PRIVATE(QParameter) + QT3D_CLONEABLE(QParameter) +}; + +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_PARAMETER_H diff --git a/src/render/materialsystem/qparameter_p.h b/src/render/materialsystem/qparameter_p.h new file mode 100644 index 000000000..0d3603d66 --- /dev/null +++ b/src/render/materialsystem/qparameter_p.h @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** 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:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.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$ +** +****************************************************************************/ + +#ifndef QT3DRENDER_QPARAMETER_P_H +#define QT3DRENDER_QPARAMETER_P_H + +#include <private/qnode_p.h> +#include <private/qt3drenderer_global_p.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QParameter; + +class QT3DRENDERERSHARED_PRIVATE_EXPORT QParameterPrivate : public Qt3D::QNodePrivate +{ +public: + QParameterPrivate(); + + Q_DECLARE_PUBLIC(QParameter) + + virtual void setValue(const QVariant &v); + + QString m_name; + QVariant m_value; + QString m_meshName; +}; + +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_QPARAMETER_P_H diff --git a/src/render/materialsystem/qparametermapping.cpp b/src/render/materialsystem/qparametermapping.cpp new file mode 100644 index 000000000..3890bf8b2 --- /dev/null +++ b/src/render/materialsystem/qparametermapping.cpp @@ -0,0 +1,203 @@ +/**************************************************************************** +** +** 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:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.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 "qparametermapping.h" +#include <private/qparametermapping_p.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +/*! + \class Qt3DRender::QParameterMappingPrivate + \internal +*/ +QParameterMappingPrivate::QParameterMappingPrivate() + : QNodePrivate() + , m_bindingType(QParameterMapping::Uniform) +{ +} +/*! + \class Qt3DRender::QParameterMapping + \inmodule Qt3DRenderer + \since 5.5 + \brief The QParameterMapping class provides ... +*/ + +/*! + \qmltype ParameterMapping + \instantiates Qt3DRender::QParameterMapping + \inherits Node + \inqmlmodule Qt3D.Renderer + \since 5.5 + \brief For ... +*/ + +/*! \fn void Qt3DRender::QParameterMapping::copy(const QNode *ref) + Copies the \a ref instance into this one. + */ +void QParameterMapping::copy(const QNode *ref) +{ + QNode::copy(ref); + const QParameterMapping *mapper = static_cast<const QParameterMapping*>(ref); + d_func()->m_parameterName = mapper->d_func()->m_parameterName; + d_func()->m_shaderVariableName = mapper->d_func()->m_shaderVariableName; + d_func()->m_bindingType = mapper->d_func()->m_bindingType; +} + +/*! \fn Qt3DRender::QParameterMapping::QParameterMapping(QNode *parent) + Constructs a new QParameterMapping with the specified \a parent. + */ +QParameterMapping::QParameterMapping(QNode *parent) + : QNode(*new QParameterMappingPrivate, parent) +{ +} + +/*! + \enum Qt3DRender::QParameterMapping::Binding + + \value Uniform + \value Attribute + \value StandardUniform + \value FragmentOutput + +*/ + +/*! \internal */ +QParameterMapping::QParameterMapping(QParameterMappingPrivate &dd, QNode *parent) + : QNode(dd, parent) +{ +} + +/*! + This constructor takes a \a parameterName, a \a shaderParameterName, + a \a bindingType, and a \a parent. + */ +QParameterMapping::QParameterMapping(const QString ¶meterName, const QString &shaderParameterName, QParameterMapping::Binding bindingType, QNode *parent) + : QNode(*new QParameterMappingPrivate, parent) +{ + Q_D(QParameterMapping); + d->m_parameterName = parameterName; + d->m_shaderVariableName = shaderParameterName; + d->m_bindingType = bindingType; +} + +QParameterMapping::~QParameterMapping() +{ + QNode::cleanup(); +} + +/*! + \property Qt3DRender::QParameterMapping::parameterName + +*/ + +/*! + \qmlproperty string Qt3D.Renderer::ParameterMapping::parameterName + +*/ + +void QParameterMapping::setParameterName(const QString &name) +{ + Q_D(QParameterMapping); + if (d->m_parameterName != name) { + d->m_parameterName = name; + emit parameterNameChanged(); + } +} + +/*! + \property Qt3DRender::QParameterMapping::shaderVariableName + +*/ + +/*! + \qmlproperty string Qt3D.Renderer::ParameterMapping::shaderVariableName + +*/ + +void QParameterMapping::setShaderVariableName(const QString &name) +{ + Q_D(QParameterMapping); + if (d->m_shaderVariableName != name) { + d->m_shaderVariableName = name; + emit shaderVariableNameChanged(); + } +} + +/*! + \property Qt3DRender::QParameterMapping::bindingType + +*/ + +/*! + \qmlproperty BindingType Qt3D.Renderer::ParameterMapping::bindingType + + \value Uniform + \value Attribute + \value StandardUniform + \value FragmentOutput +*/ +void QParameterMapping::setBindingType(QParameterMapping::Binding type) +{ + Q_D(QParameterMapping); + if (d->m_bindingType != type) { + d->m_bindingType = type; + emit bindingTypeChanged(); + } +} + +QString QParameterMapping::parameterName() const +{ + Q_D(const QParameterMapping); + return d->m_parameterName; +} + +QString QParameterMapping::shaderVariableName() const +{ + Q_D(const QParameterMapping); + return d->m_shaderVariableName; +} + +QParameterMapping::Binding QParameterMapping::bindingType() const +{ + Q_D(const QParameterMapping); + return d->m_bindingType; +} + +} // namespace Qt3DRender + +QT_END_NAMESPACE diff --git a/src/render/materialsystem/qparametermapping.h b/src/render/materialsystem/qparametermapping.h new file mode 100644 index 000000000..f4e209abd --- /dev/null +++ b/src/render/materialsystem/qparametermapping.h @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** 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:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.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$ +** +****************************************************************************/ + +#ifndef QT3DRENDER_QPARAMETERMAPPING_H +#define QT3DRENDER_QPARAMETERMAPPING_H + +#include <Qt3DCore/qnode.h> +#include <Qt3DRenderer/qt3drenderer_global.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QParameterMappingPrivate; + +class QT3DRENDERERSHARED_EXPORT QParameterMapping : public Qt3D::QNode +{ + Q_OBJECT + Q_PROPERTY(QString parameterName READ parameterName WRITE setParameterName NOTIFY parameterNameChanged) + Q_PROPERTY(QString shaderVariableName READ shaderVariableName WRITE setShaderVariableName NOTIFY shaderVariableNameChanged) + Q_PROPERTY(Binding bindingType READ bindingType WRITE setBindingType NOTIFY bindingTypeChanged) +public: + enum Binding + { + Uniform = 0, + Attribute, + StandardUniform, + FragmentOutput + }; + Q_ENUM(Binding) + + explicit QParameterMapping(Qt3D::QNode *parent = 0); + QParameterMapping(const QString ¶meterName, const QString &shaderParameterName, QParameterMapping::Binding bindingType, Qt3D::QNode *parent = 0); + ~QParameterMapping(); + + void setParameterName(const QString &name); + void setShaderVariableName(const QString &name); + void setBindingType(Binding type); + + QString parameterName() const; + QString shaderVariableName() const; + Binding bindingType() const; + +Q_SIGNALS: + void parameterNameChanged(); + void shaderVariableNameChanged(); + void bindingTypeChanged(); + +protected: + QParameterMapping(QParameterMappingPrivate &dd, Qt3D::QNode *parent = 0); + void copy(const Qt3D::QNode *ref) Q_DECL_OVERRIDE; + +private: + Q_DECLARE_PRIVATE(QParameterMapping) + QT3D_CLONEABLE(QParameterMapping) +}; + +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_QPARAMETERBINDER_H diff --git a/src/render/materialsystem/qparametermapping_p.h b/src/render/materialsystem/qparametermapping_p.h new file mode 100644 index 000000000..0fe32cb0f --- /dev/null +++ b/src/render/materialsystem/qparametermapping_p.h @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** 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:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.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$ +** +****************************************************************************/ + +#ifndef QT3DRENDER_QPARAMETERMAPPING_P_H +#define QT3DRENDER_QPARAMETERMAPPING_P_H + +#include <private/qnode_p.h> +#include <Qt3DRenderer/QParameterMapping> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QParameterMappingPrivate : public Qt3D::QNodePrivate +{ +public: + QParameterMappingPrivate(); + + Q_DECLARE_PUBLIC(QParameterMapping) + + QString m_parameterName; + QString m_shaderVariableName; + QParameterMapping::Binding m_bindingType; +}; + +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_QPARAMETERMAPPING_P_H diff --git a/src/render/materialsystem/qrenderpass.cpp b/src/render/materialsystem/qrenderpass.cpp new file mode 100644 index 000000000..efb315177 --- /dev/null +++ b/src/render/materialsystem/qrenderpass.cpp @@ -0,0 +1,319 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.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 "qrenderpass.h" +#include "qrenderpass_p.h" +#include "qparameter.h" +#include "qannotation.h" +#include "qparametermapping.h" +#include "qscenepropertychange.h" +#include "qrenderstate.h" +#include "private/qnode_p.h" + +QT_BEGIN_NAMESPACE + +using namespace Qt3D; + +namespace Qt3DRender { + +/*! + \class Qt3DRender::QRenderPassPrivate + \internal +*/ +QRenderPassPrivate::QRenderPassPrivate() + : QNodePrivate() + , m_shader(Q_NULLPTR) +{ +} + +void QRenderPass::copy(const QNode *ref) +{ + QNode::copy(ref); + const QRenderPass *other = static_cast<const QRenderPass*>(ref); + d_func()->m_shader = qobject_cast<QShaderProgram *>(QNode::clone(other->d_func()->m_shader)); + + Q_FOREACH (QAnnotation *crit, other->d_func()->m_annotationList) + addAnnotation(qobject_cast<QAnnotation *>(QNode::clone(crit))); + Q_FOREACH (QParameterMapping *binding, other->d_func()->m_bindings) + addBinding(qobject_cast<QParameterMapping *>(QNode::clone(binding))); + Q_FOREACH (QRenderState *renderState, other->d_func()->m_renderStates) + addRenderState(qobject_cast<QRenderState *>(QNode::clone(renderState))); +} + +QRenderPass::QRenderPass(QNode *parent) + : QNode(*new QRenderPassPrivate, parent) +{ +} + +QRenderPass::~QRenderPass() +{ + QNode::cleanup(); +} + +/*! \internal */ +QRenderPass::QRenderPass(QRenderPassPrivate &dd, QNode *parent) + : QNode(dd, parent) +{ +} + +ParameterList QRenderPass::attributes() const +{ + Q_D(const QRenderPass); + return d->m_attributes; +} + +ParameterList QRenderPass::uniforms() const +{ + Q_D(const QRenderPass); + return d->m_uniforms; +} + +/*! + * Sets the pass's \a shaderProgram. This posts a ComponentUpdated + * QScenePropertyChange to the QChangeArbiter. The value is set to + * the \a ShaderProgram and the property name to "shaderProgram". + */ +void QRenderPass::setShaderProgram(QShaderProgram *shaderProgram) +{ + Q_D(QRenderPass); + if (d->m_shader != shaderProgram) { + + if (d->m_shader != Q_NULLPTR && d->m_changeArbiter != Q_NULLPTR) { + QScenePropertyChangePtr e(new QScenePropertyChange(NodeRemoved, QSceneChange::Node, id())); + e->setPropertyName("shaderProgram"); + e->setValue(QVariant::fromValue(d->m_shader->id())); + d->notifyObservers(e); + } + + d->m_shader = shaderProgram; + emit shaderProgramChanged(); + + // We need to add it as a child of the current node if it has been declared inline + // Or not previously added as a child of the current node so that + // 1) The backend gets notified about it's creation + // 2) When the current node is destroyed, it gets destroyed as well + if (!shaderProgram->parent()) + shaderProgram->setParent(this); + + if (d->m_changeArbiter != Q_NULLPTR) { + QScenePropertyChangePtr e(new QScenePropertyChange(NodeAdded, QSceneChange::Node, id())); + e->setPropertyName("shaderProgram"); + e->setValue(QVariant::fromValue(shaderProgram->id())); + d->notifyObservers(e); + } + } +} + +QShaderProgram *QRenderPass::shaderProgram() const +{ + Q_D(const QRenderPass); + return d->m_shader; +} + +void QRenderPass::addAnnotation(QAnnotation *annotation) +{ + Q_D(QRenderPass); + if (!d->m_annotationList.contains(annotation)) { + d->m_annotationList.append(annotation); + + // We need to add it as a child of the current node if it has been declared inline + // Or not previously added as a child of the current node so that + // 1) The backend gets notified about it's creation + // 2) When the current node is destroyed, it gets destroyed as well + if (!annotation->parent()) + annotation->setParent(this); + + if (d->m_changeArbiter != Q_NULLPTR) { + QScenePropertyChangePtr change(new QScenePropertyChange(NodeAdded, QSceneChange::Node, id())); + change->setPropertyName("annotation"); + change->setValue(QVariant::fromValue(annotation->id())); + d->notifyObservers(change); + } + } +} + +void QRenderPass::removeAnnotation(QAnnotation *annotation) +{ + Q_D(QRenderPass); + if (d->m_changeArbiter != Q_NULLPTR) { + QScenePropertyChangePtr change(new QScenePropertyChange(NodeRemoved, QSceneChange::Node, id())); + change->setPropertyName("annotation"); + change->setValue(QVariant::fromValue(annotation->id())); + d->notifyObservers(change); + } + d->m_annotationList.removeOne(annotation); +} + +QList<QAnnotation *> QRenderPass::annotations() const +{ + Q_D(const QRenderPass); + return d->m_annotationList; +} + +void QRenderPass::addBinding(QParameterMapping *binding) +{ + Q_D(QRenderPass); + if (!d->m_bindings.contains(binding)) { + d->m_bindings.append(binding); + + if (!binding->parent()) + binding->setParent(this); + + if (d->m_changeArbiter != Q_NULLPTR) { + QScenePropertyChangePtr change(new QScenePropertyChange(NodeAdded, QSceneChange::Node, id())); + change->setPropertyName("binding"); + change->setValue(QVariant::fromValue(QNode::clone(binding))); + d->notifyObservers(change); + } + } +} + +void QRenderPass::removeBinding(QParameterMapping *binding) +{ + Q_D(QRenderPass); + if (d->m_changeArbiter != Q_NULLPTR) { + QScenePropertyChangePtr change(new QScenePropertyChange(NodeRemoved, QSceneChange::Node, id())); + change->setPropertyName("binding"); + change->setValue(QVariant::fromValue(binding->id())); + d->notifyObservers(change); + } + d->m_bindings.removeOne(binding); +} + +QList<QParameterMapping *> QRenderPass::bindings() const +{ + Q_D(const QRenderPass); + return d->m_bindings; +} + +/*! + * Adds a Qt3D::QRenderState \a state to the rendering pass. That implies that + * when the pass is executed at render time, the globally set render state will + * be modifed by the states defined locally by the Qt3DRender::QRenderPass. + * + * \note not defining any Qt3D::QRenderState in a pass will result in the pass using + * the globally set render state for a given FrameGraph branch execution path. + */ +void QRenderPass::addRenderState(QRenderState *state) +{ + Q_D(QRenderPass); + + if (!d->m_renderStates.contains(state)) { + d->m_renderStates.append(state); + + if (!state->parent()) + state->setParent(this); + + if (d->m_changeArbiter != Q_NULLPTR) { + QScenePropertyChangePtr change(new QScenePropertyChange(NodeAdded, QSceneChange::Node, id())); + change->setPropertyName("renderState"); + change->setValue(QVariant::fromValue(QNodePtr(QNode::clone(state)))); + d->notifyObservers(change); + } + } +} + +/*! + * Removes \a state from the Qt3DRender::QRenderPass local render state. + */ +void QRenderPass::removeRenderState(QRenderState *state) +{ + Q_D(QRenderPass); + if (d->m_changeArbiter != Q_NULLPTR) { + QScenePropertyChangePtr change(new QScenePropertyChange(NodeRemoved, QSceneChange::Node, id())); + change->setPropertyName("renderState"); + change->setValue(QVariant::fromValue(state->id())); + d->notifyObservers(change); + } + d->m_renderStates.removeOne(state); +} + +/*! + * Returns the list of Qt3D::QRenderState state objects making up the render + * state of the Qt3DRender::QRenderPass. + */ +QList<QRenderState *> QRenderPass::renderStates() const +{ + Q_D(const QRenderPass); + return d->m_renderStates; +} + +void QRenderPass::addParameter(QParameter *parameter) +{ + Q_D(QRenderPass); + if (!d->m_parameters.contains(parameter)) { + d->m_parameters.append(parameter); + + // We need to add it as a child of the current node if it has been declared inline + // Or not previously added as a child of the current node so that + // 1) The backend gets notified about it's creation + // 2) When the current node is destroyed, the child parameters get destroyed as well + if (!parameter->parent()) + parameter->setParent(this); + + if (d->m_changeArbiter != Q_NULLPTR) { + QScenePropertyChangePtr change(new QScenePropertyChange(NodeAdded, QSceneChange::Node, id())); + change->setPropertyName("parameter"); + change->setValue(QVariant::fromValue(parameter->id())); + d->notifyObservers(change); + } + } +} + +void QRenderPass::removeParameter(QParameter *parameter) +{ + Q_D(QRenderPass); + + if (d->m_changeArbiter != Q_NULLPTR) { + QScenePropertyChangePtr change(new QScenePropertyChange(NodeRemoved, QSceneChange::Node, id())); + change->setPropertyName("parameter"); + change->setValue(QVariant::fromValue(parameter->id())); + d->notifyObservers(change); + } + d->m_parameters.removeOne(parameter); +} + + +QList<QParameter *> QRenderPass::parameters() const +{ + Q_D(const QRenderPass); + return d->m_parameters; +} + +} // namespace Qt3DRender + +QT_END_NAMESPACE diff --git a/src/render/materialsystem/qrenderpass.h b/src/render/materialsystem/qrenderpass.h new file mode 100644 index 000000000..ed733ba12 --- /dev/null +++ b/src/render/materialsystem/qrenderpass.h @@ -0,0 +1,110 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.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$ +** +****************************************************************************/ + +#ifndef QT3DRENDER_QRENDERPASS_H +#define QT3DRENDER_QRENDERPASS_H + +#include <Qt3DRenderer/qt3drenderer_global.h> + +#include <Qt3DRenderer/qshaderprogram.h> +#include <Qt3DRenderer/qrenderstate.h> +#include <Qt3DRenderer/qannotation.h> + +#include <QHash> +#include <QList> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QParameter; +class QRenderState; +class QParameterMapping; +typedef QList<QParameter*> ParameterList; + +class QRenderPassPrivate; + +class QT3DRENDERERSHARED_EXPORT QRenderPass : public Qt3D::QNode +{ + Q_OBJECT + Q_PROPERTY(Qt3DRender::QShaderProgram *shaderProgram READ shaderProgram WRITE setShaderProgram NOTIFY shaderProgramChanged) + +public: + explicit QRenderPass(Qt3D::QNode *parent = 0); + ~QRenderPass(); + + QString glslNameForParameter(QString paramName) const; + + ParameterList attributes() const; + ParameterList uniforms() const; + + void setShaderProgram(QShaderProgram *shaderProgram); + QShaderProgram *shaderProgram() const; + + void addAnnotation(QAnnotation *criterion); + void removeAnnotation(QAnnotation *criterion); + QList<QAnnotation *> annotations() const; + + void addBinding(QParameterMapping *binding); + void removeBinding(QParameterMapping *binding); + QList<QParameterMapping *> bindings() const; + + void addRenderState(QRenderState *state); + void removeRenderState(QRenderState *state); + QList<QRenderState *> renderStates() const; + + void addParameter(QParameter *p); + void removeParameter(QParameter *p); + QList<QParameter *> parameters() const; + +Q_SIGNALS: + void shaderProgramChanged(); + +protected: + QRenderPass(QRenderPassPrivate &dd, Qt3D::QNode *parent = 0); + void copy(const Qt3D::QNode *ref) Q_DECL_OVERRIDE; + +private: + Q_DECLARE_PRIVATE(QRenderPass) + QT3D_CLONEABLE(QRenderPass) +}; + +} + +QT_END_NAMESPACE + +#endif // QT3DRENDER_QRENDERPASS_H diff --git a/src/render/materialsystem/qrenderpass_p.h b/src/render/materialsystem/qrenderpass_p.h new file mode 100644 index 000000000..ace1a54b1 --- /dev/null +++ b/src/render/materialsystem/qrenderpass_p.h @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.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$ +** +****************************************************************************/ + +#ifndef QT3DRENDER_QRENDERPASS_P_H +#define QT3DRENDER_QRENDERPASS_P_H + +#include <private/qnode_p.h> +#include <Qt3DRenderer/qrenderpass.h> +#include <Qt3DRenderer/qt3drenderer_global.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QParameter; +class QParameterMapping; +class QRenderState; +class QAnnotation; +typedef QList<QParameter*> ParameterList; + +namespace Render +{ +class RenderStateSet; +} + +class QT3DRENDERERSHARED_EXPORT QRenderPassPrivate : public Qt3D::QNodePrivate +{ +public: + QRenderPassPrivate(); + + Q_DECLARE_PUBLIC(QRenderPass) + ParameterList m_attributes; + ParameterList m_uniforms; + + // map Parameter names to GLSL names + QHash<QString, QString> m_parameterNameDict; + QList<QAnnotation *> m_annotationList; + QList<QParameterMapping *> m_bindings; + QList<QRenderState *> m_renderStates; + QList<QParameter *> m_parameters; + QShaderProgram *m_shader; +}; + +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QRENDERPASS_P_H diff --git a/src/render/materialsystem/qshaderdata.cpp b/src/render/materialsystem/qshaderdata.cpp new file mode 100644 index 000000000..848b54bf8 --- /dev/null +++ b/src/render/materialsystem/qshaderdata.cpp @@ -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:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.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 "qshaderdata.h" +#include "qshaderdata_p.h" + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +/*! + \class Qt3DRender::QShaderDataPrivate + \internal +*/ +QShaderDataPrivate::QShaderDataPrivate() + : QComponentPrivate() + , m_propertyReader(PropertyReaderInterfacePtr(new QShaderDataPropertyReader())) +{ +} + +/*! + \class Qt3DRender::QShaderDataPrivate + \internal +*/ +QShaderDataPrivate::QShaderDataPrivate(PropertyReaderInterfacePtr reader) + : QComponentPrivate() + , m_propertyReader(reader) +{ +} + +/*! + * \class Qt3DRender::QShaderData + * \inmodule Qt3DRenderer + * + * \brief Provides a way of specifying values of a Uniform Block or a shader + * structure. + * + * \note When subclassing and adding properties to Qt3DRender::QShaderData, please note + * that if you need to nest an inner Qt3DRender::QShaderData, the data type of the + * property should be Qt3DRender::QShaderData* instead of the name of your subclass. + * + * \since 5.5 + */ + +QShaderData::QShaderData(QNode *parent) + : QComponent(*new QShaderDataPrivate, parent) +{ +} + +QShaderData::~QShaderData() +{ + QNode::cleanup(); +} + +PropertyReaderInterfacePtr QShaderData::propertyReader() const +{ + Q_D(const QShaderData); + return d->m_propertyReader; +} + +/*! \internal */ +QShaderData::QShaderData(QShaderDataPrivate &dd, QNode *parent) + : QComponent(dd, parent) +{ +} + +void QShaderData::copy(const QNode *ref) +{ + QNode::copy(ref); + const QShaderData *shaderData = static_cast<const QShaderData *>(ref); + // We need to copy the properties + // At the moment we assume that the properties are copyable + // this may change in a later refactoring + + const QMetaObject *metaObject = shaderData->metaObject(); + const int propertyOffset = QShaderData::staticMetaObject.propertyOffset(); + const int propertyCount = metaObject->propertyCount(); + + // Copy properties of shaderData + for (int i = propertyOffset; i < propertyCount; ++i) { + const QMetaProperty property = metaObject->property(i); + setProperty(property.name(), propertyReader()->readProperty(shaderData->property(property.name()))); + } +} + +} // namespace Qt3DRender + +QT_END_NAMESPACE diff --git a/src/render/materialsystem/qshaderdata.h b/src/render/materialsystem/qshaderdata.h new file mode 100644 index 000000000..4353581af --- /dev/null +++ b/src/render/materialsystem/qshaderdata.h @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** 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:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.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$ +** +****************************************************************************/ + +#ifndef QT3DRENDER_QSHADERDATA_H +#define QT3DRENDER_QSHADERDATA_H + +#include <Qt3DCore/qcomponent.h> +#include <Qt3DRenderer/qt3drenderer_global.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QShaderDataPrivate; + +class QT3DRENDERERSHARED_EXPORT PropertyReaderInterface +{ +public: + virtual ~PropertyReaderInterface() {} + virtual QVariant readProperty(const QVariant &v) = 0; +}; + +typedef QSharedPointer<PropertyReaderInterface> PropertyReaderInterfacePtr; + +class QT3DRENDERERSHARED_EXPORT QShaderData : public Qt3D::QComponent +{ + Q_OBJECT +public: + explicit QShaderData(Qt3D::QNode *parent = 0); + ~QShaderData(); + + enum TransformType { + ModelToEye = 0, + ModelToWorld + }; + Q_ENUM(TransformType) + + PropertyReaderInterfacePtr propertyReader() const; + +protected: + QShaderData(QShaderDataPrivate &dd, Qt3D::QNode *parent = 0); + void copy(const Qt3D::QNode *ref) Q_DECL_OVERRIDE; + + +private: + Q_DECLARE_PRIVATE(QShaderData) + QT3D_CLONEABLE(QShaderData) +}; + +} // namespace Qt3DRender + +QT_END_NAMESPACE + +Q_DECLARE_METATYPE(Qt3DRender::QShaderData*) +Q_DECLARE_METATYPE(QList<Qt3DRender::QShaderData*>) + +#endif // QT3DRENDER_QSHADERDATA_H diff --git a/src/render/materialsystem/qshaderdata_p.h b/src/render/materialsystem/qshaderdata_p.h new file mode 100644 index 000000000..eaf6847f7 --- /dev/null +++ b/src/render/materialsystem/qshaderdata_p.h @@ -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:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.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$ +** +****************************************************************************/ + +#ifndef QT3DRENDER_QSHADERDATA_P_H +#define QT3DRENDER_QSHADERDATA_P_H + +#include <private/qcomponent_p.h> +#include <Qt3DRenderer/qshaderdata.h> +#include <Qt3DRenderer/private/qt3drenderer_global_p.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +namespace { + +const int qListShaderDataTypeId = qMetaTypeId<QList<QShaderData*> >(); +const int qShaderDataTypeId = qMetaTypeId<QShaderData*>(); + +} + +class QShaderDataPropertyReader: public PropertyReaderInterface +{ + QVariant readProperty(const QVariant &v) Q_DECL_OVERRIDE + { + QShaderData *shaderData = Q_NULLPTR; + + if (v.userType() == qShaderDataTypeId && (shaderData = v.value<QShaderData *>()) != Q_NULLPTR) { + return QVariant::fromValue(shaderData->id()); + } else if (v.userType() == qListShaderDataTypeId) { + QVariantList vlist; + Q_FOREACH (QShaderData *data, v.value<QList<QShaderData *> >()) { + if (data) + vlist.append(QVariant::fromValue(data->id())); + } + return vlist; + } + return v; + } +}; + +class QT3DRENDERERSHARED_PRIVATE_EXPORT QShaderDataPrivate : public Qt3D::QComponentPrivate +{ +public: + QShaderDataPrivate(); + QShaderDataPrivate(PropertyReaderInterfacePtr reader); + PropertyReaderInterfacePtr m_propertyReader; + + Q_DECLARE_PUBLIC(QShaderData) +}; + +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_QSHADERDATA_P_H diff --git a/src/render/materialsystem/qshaderprogram.cpp b/src/render/materialsystem/qshaderprogram.cpp new file mode 100644 index 000000000..6c44ee0ce --- /dev/null +++ b/src/render/materialsystem/qshaderprogram.cpp @@ -0,0 +1,245 @@ +/**************************************************************************** +** +** 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:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.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 "qshaderprogram.h" +#include "qshaderprogram_p.h" +#include <Qt3DCore/qscenepropertychange.h> +#include <Qt3DCore/private/qurlhelper_p.h> +#include <QDebug> +#include <QFile> +#include <QUrl> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +/*! + \class Qt3DRender::QShaderProgramPrivate + \internal +*/ +QShaderProgramPrivate::QShaderProgramPrivate() + : QNodePrivate() +{ +} + +void QShaderProgram::copy(const QNode *ref) +{ + QNode::copy(ref); + const QShaderProgram *prog = static_cast<const QShaderProgram*>(ref); + + d_func()->m_vertexShaderCode = prog->d_func()->m_vertexShaderCode; + d_func()->m_tessControlShaderCode = prog->d_func()->m_tessControlShaderCode; + d_func()->m_tessEvalShaderCode = prog->d_func()->m_tessEvalShaderCode; + d_func()->m_geometryShaderCode = prog->d_func()->m_geometryShaderCode; + d_func()->m_fragmentShaderCode = prog->d_func()->m_fragmentShaderCode; + d_func()->m_computeShaderCode = prog->d_func()->m_computeShaderCode; +} + +QShaderProgram::QShaderProgram(QNode *parent) + : QNode(*new QShaderProgramPrivate, parent) +{ +} + +QShaderProgram::~QShaderProgram() +{ + QNode::cleanup(); +} + +/*! \internal */ +QShaderProgram::QShaderProgram(QShaderProgramPrivate &dd, QNode *parent) + : QNode(dd, parent) +{ +} + +/*! + * Sets the vertexShader from raw data in \a vertexShader. + */ +void QShaderProgram::setVertexShaderCode(const QByteArray &vertexShaderCode) +{ + Q_D(QShaderProgram); + if (vertexShaderCode != d->m_vertexShaderCode) { + d->m_vertexShaderCode = vertexShaderCode; + emit vertexShaderCodeChanged(); + } +} + +QByteArray QShaderProgram::vertexShaderCode() const +{ + Q_D(const QShaderProgram); + return d->m_vertexShaderCode; +} + +void QShaderProgram::setTessellationControlShaderCode(const QByteArray &tessellationControlShaderCode) +{ + Q_D(QShaderProgram); + if (tessellationControlShaderCode != d->m_tessControlShaderCode) { + d->m_tessControlShaderCode = tessellationControlShaderCode; + emit tessellationControlShaderCodeChanged(); + } +} + +QByteArray QShaderProgram::tessellationControlShaderCode() const +{ + Q_D(const QShaderProgram); + return d->m_tessControlShaderCode; +} + +void QShaderProgram::setTessellationEvaluationShaderCode(const QByteArray &tessellationEvaluationShaderCode) +{ + Q_D(QShaderProgram); + if (tessellationEvaluationShaderCode != d->m_tessEvalShaderCode) { + d->m_tessEvalShaderCode = tessellationEvaluationShaderCode; + emit tessellationEvaluationShaderCodeChanged(); + } +} + +QByteArray QShaderProgram::tessellationEvaluationShaderCode() const +{ + Q_D(const QShaderProgram); + return d->m_tessEvalShaderCode; +} + +void QShaderProgram::setGeometryShaderCode(const QByteArray &geometryShaderCode) +{ + Q_D(QShaderProgram); + if (geometryShaderCode != d->m_geometryShaderCode) { + d->m_geometryShaderCode = geometryShaderCode; + emit geometryShaderCodeChanged(); + } +} + +QByteArray QShaderProgram::geometryShaderCode() const +{ + Q_D(const QShaderProgram); + return d->m_geometryShaderCode; +} + +/*! + * Sets the fragmentShader from raw data in \a fragmentShader. + */ +void QShaderProgram::setFragmentShaderCode(const QByteArray &fragmentShaderCode) +{ + Q_D(QShaderProgram); + if (fragmentShaderCode != d->m_fragmentShaderCode) { + d->m_fragmentShaderCode = fragmentShaderCode; + emit fragmentShaderCodeChanged(); + } +} + +QByteArray QShaderProgram::fragmentShaderCode() const +{ + Q_D(const QShaderProgram); + return d->m_fragmentShaderCode; +} + +void QShaderProgram::setComputeShaderCode(const QByteArray &computeShaderCode) +{ + Q_D(QShaderProgram); + if (computeShaderCode != d->m_computeShaderCode) { + d->m_computeShaderCode = computeShaderCode; + emit computeShaderCodeChanged(); + } +} + +QByteArray QShaderProgram::computeShaderCode() const +{ + Q_D(const QShaderProgram); + return d->m_computeShaderCode; +} + +void QShaderProgram::setShaderCode(ShaderType type, const QByteArray &shaderCode) +{ + switch (type) { + case Vertex: + setVertexShaderCode(shaderCode); + break; + case TessellationControl: + setTessellationControlShaderCode(shaderCode); + break; + case TessellationEvaluation: + setTessellationEvaluationShaderCode(shaderCode); + break; + case Geometry: + setGeometryShaderCode(shaderCode); + break; + case Fragment: + setFragmentShaderCode(shaderCode); + break; + case Compute: + setComputeShaderCode(shaderCode); + break; + default: + Q_UNREACHABLE(); + } +} + +QByteArray QShaderProgram::shaderCode(ShaderType type) const +{ + Q_D(const QShaderProgram); + switch (type) { + case Vertex: + return d->m_vertexShaderCode; + case TessellationControl: + return d->m_tessControlShaderCode; + case TessellationEvaluation: + return d->m_tessEvalShaderCode; + case Geometry: + return d->m_geometryShaderCode; + case Fragment: + return d->m_fragmentShaderCode; + case Compute: + return d->m_computeShaderCode; + default: + Q_UNREACHABLE(); + } +} + +QByteArray QShaderProgram::loadSource(const QUrl &sourceUrl) +{ + // TO DO: Handle remote path + QString filePath = Qt3D::QUrlHelper::urlToLocalFileOrQrc(sourceUrl); + + QFile f(filePath); + if (!f.exists()) + qWarning() << "Couldn't read shader source file:" << sourceUrl; + else + f.open(QIODevice::ReadOnly | QIODevice::Text); + return f.readAll(); +} + +} // of namespace Qt3DRender + +QT_END_NAMESPACE diff --git a/src/render/materialsystem/qshaderprogram.h b/src/render/materialsystem/qshaderprogram.h new file mode 100644 index 000000000..6695316ee --- /dev/null +++ b/src/render/materialsystem/qshaderprogram.h @@ -0,0 +1,118 @@ +/**************************************************************************** +** +** 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:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.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$ +** +****************************************************************************/ + +#ifndef QT3DRENDER_QSHADERPROGRAM_H +#define QT3DRENDER_QSHADERPROGRAM_H + +#include <Qt3DCore/qnode.h> +#include <Qt3DRenderer/qt3drenderer_global.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QShaderProgramPrivate; + +class QT3DRENDERERSHARED_EXPORT QShaderProgram : public Qt3D::QNode +{ + Q_OBJECT + Q_PROPERTY(QByteArray vertexShaderCode READ vertexShaderCode WRITE setVertexShaderCode NOTIFY vertexShaderCodeChanged) + Q_PROPERTY(QByteArray tessellationControlShaderCode READ tessellationControlShaderCode WRITE setTessellationControlShaderCode NOTIFY tessellationControlShaderCodeChanged) + Q_PROPERTY(QByteArray tessellationEvaluationShaderCode READ tessellationEvaluationShaderCode WRITE setTessellationEvaluationShaderCode NOTIFY tessellationEvaluationShaderCodeChanged) + Q_PROPERTY(QByteArray geometryShaderCode READ geometryShaderCode WRITE setGeometryShaderCode NOTIFY geometryShaderCodeChanged) + Q_PROPERTY(QByteArray fragmentShaderCode READ fragmentShaderCode WRITE setFragmentShaderCode NOTIFY fragmentShaderCodeChanged) + Q_PROPERTY(QByteArray computeShaderCode READ computeShaderCode WRITE setComputeShaderCode NOTIFY computeShaderCodeChanged) + +public: + explicit QShaderProgram(Qt3D::QNode *parent = 0); + ~QShaderProgram(); + + enum ShaderType { + Vertex = 0, + Fragment, + TessellationControl, + TessellationEvaluation, + Geometry, + Compute + }; + Q_ENUM(ShaderType) + + // Source code in-line + void setVertexShaderCode(const QByteArray &vertexShaderCode); + QByteArray vertexShaderCode() const; + + void setTessellationControlShaderCode(const QByteArray &tessellationControlShaderCode); + QByteArray tessellationControlShaderCode() const; + + void setTessellationEvaluationShaderCode(const QByteArray &tessellationEvaluationShaderCode); + QByteArray tessellationEvaluationShaderCode() const; + + void setGeometryShaderCode(const QByteArray &geometryShaderCode); + QByteArray geometryShaderCode() const; + + void setFragmentShaderCode(const QByteArray &fragmentShaderCode); + QByteArray fragmentShaderCode() const; + + void setComputeShaderCode(const QByteArray &computeShaderCode); + QByteArray computeShaderCode() const; + + void setShaderCode(ShaderType type, const QByteArray &shaderCode); + QByteArray shaderCode(ShaderType type) const; + + Q_INVOKABLE static QByteArray loadSource(const QUrl &sourceUrl); + +Q_SIGNALS: + void vertexShaderCodeChanged(); + void tessellationControlShaderCodeChanged(); + void tessellationEvaluationShaderCodeChanged(); + void geometryShaderCodeChanged(); + void fragmentShaderCodeChanged(); + void computeShaderCodeChanged(); + +protected: + QShaderProgram(QShaderProgramPrivate &dd, Qt3D::QNode *parent = 0); + void copy(const Qt3D::QNode *ref) Q_DECL_OVERRIDE; + +private: + Q_DECLARE_PRIVATE(QShaderProgram) + QT3D_CLONEABLE(QShaderProgram) +}; + +} + +QT_END_NAMESPACE + +#endif // QT3DRENDER_QSHADERPROGRAM_H diff --git a/src/render/materialsystem/qshaderprogram_p.h b/src/render/materialsystem/qshaderprogram_p.h new file mode 100644 index 000000000..2fd50f3b0 --- /dev/null +++ b/src/render/materialsystem/qshaderprogram_p.h @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** 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:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.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$ +** +****************************************************************************/ + +#ifndef QT3DRENDER_QSHADERPROGRAM_P_H +#define QT3DRENDER_QSHADERPROGRAM_P_H + +#include <private/qnode_p.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QShaderProgram; + +class QShaderProgramPrivate : public Qt3D::QNodePrivate +{ +public: + QShaderProgramPrivate(); + + Q_DECLARE_PUBLIC(QShaderProgram) + QString m_vertexSourceFile; + QString m_tessControlSourceFile; + QString m_tessEvalSourceFile; + QString m_geometrySourceFile; + QString m_fragmentSourceFile; + QString m_computeSourceFile; + QByteArray m_vertexShaderCode; + QByteArray m_tessControlShaderCode; + QByteArray m_tessEvalShaderCode; + QByteArray m_geometryShaderCode; + QByteArray m_fragmentShaderCode; + QByteArray m_computeShaderCode; +}; + +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_QSHADERPROGRAM_P_H diff --git a/src/render/materialsystem/qtechnique.cpp b/src/render/materialsystem/qtechnique.cpp new file mode 100644 index 000000000..52578e267 --- /dev/null +++ b/src/render/materialsystem/qtechnique.cpp @@ -0,0 +1,253 @@ +/**************************************************************************** +** +** 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:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.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 "qtechnique.h" +#include "qtechnique_p.h" +#include "qparameter.h" +#include "qopenglfilter.h" +#include <Qt3DCore/qscenepropertychange.h> +#include <QDebug> + +QT_BEGIN_NAMESPACE + +using namespace Qt3D; + +namespace Qt3DRender { + +/*! + \class Qt3DRender::QTechniquePrivate + \internal +*/ +QTechniquePrivate::QTechniquePrivate() + : QNodePrivate() +{ +} + +QTechniquePrivate::~QTechniquePrivate() +{ +} + +QTechnique::QTechnique(QNode *parent) + : QNode(*new QTechniquePrivate, parent) +{ + Q_D(QTechnique); + QObject::connect(&d->m_openGLFilter, SIGNAL(openGLFilterChanged()), this, SLOT(_q_openGLFilterChanged())); +} + +QTechnique::~QTechnique() +{ + QNode::cleanup(); +} + +/*! \internal */ +QTechnique::QTechnique(QTechniquePrivate &dd, QNode *parent) + : QNode(dd, parent) +{ + Q_D(QTechnique); + QObject::connect(&d->m_openGLFilter, SIGNAL(openGLFilterChanged()), this, SLOT(_q_openGLFilterChanged())); +} + +void QTechnique::copy(const QNode *ref) +{ + QNode::copy(ref); + const QTechnique *tech = static_cast<const QTechnique*>(ref); + d_func()->m_openGLFilter.copy(tech->d_func()->m_openGLFilter); + + Q_FOREACH (QAnnotation *annotation, tech->d_func()->m_annotationList) + addAnnotation(qobject_cast<QAnnotation *>(QNode::clone(annotation))); + Q_FOREACH (QRenderPass *pass, tech->d_func()->m_renderPasses) + addPass(qobject_cast<QRenderPass *>(QNode::clone(pass))); + Q_FOREACH (QParameter *p, tech->d_func()->m_parameters) + addParameter(qobject_cast<QParameter *>(QNode::clone(p))); +} + +void QTechniquePrivate::_q_openGLFilterChanged() +{ + if (m_changeArbiter != Q_NULLPTR) { + QScenePropertyChangePtr change(new QScenePropertyChange(NodeUpdated, QSceneChange::Node, m_id)); + change->setPropertyName("openGLFilter"); + QOpenGLFilter *clone = new QOpenGLFilter(); + clone->copy(m_openGLFilter); + change->setValue(QVariant::fromValue(clone)); + notifyObservers(change); + } +} + +void QTechnique::addAnnotation(QAnnotation *criterion) +{ + Q_D(QTechnique); + if (!d->m_annotationList.contains(criterion)) { + d->m_annotationList.append(criterion); + + // We need to add it as a child of the current node if it has been declared inline + // Or not previously added as a child of the current node so that + // 1) The backend gets notified about it's creation + // 2) When the current node is destroyed, it gets destroyed as well + if (!criterion->parent()) + criterion->setParent(this); + + if (d->m_changeArbiter != Q_NULLPTR) { + QScenePropertyChangePtr change(new QScenePropertyChange(NodeAdded, QSceneChange::Node, id())); + change->setPropertyName("annotation"); + change->setValue(QVariant::fromValue(criterion->id())); + d->notifyObservers(change); + } + } +} + +void QTechnique::removeAnnotation(QAnnotation *criterion) +{ + Q_D(QTechnique); + if (d->m_changeArbiter != Q_NULLPTR) { + QScenePropertyChangePtr change(new QScenePropertyChange(NodeRemoved, QSceneChange::Node, id())); + change->setPropertyName("annotation"); + change->setValue(QVariant::fromValue(criterion->id())); + d->notifyObservers(change); + } + d->m_annotationList.removeOne(criterion); +} + +QList<QAnnotation *> QTechnique::annotations() const +{ + Q_D(const QTechnique); + return d->m_annotationList; +} + +void QTechnique::addParameter(QParameter *parameter) +{ + Q_D(QTechnique); + if (!d->m_parameters.contains(parameter)) { + d->m_parameters.append(parameter); + + // We need to add it as a child of the current node if it has been declared inline + // Or not previously added as a child of the current node so that + // 1) The backend gets notified about it's creation + // 2) When the current node is destroyed, the child parameters get destroyed as well + if (!parameter->parent()) + parameter->setParent(this); + + if (d->m_changeArbiter != Q_NULLPTR) { + QScenePropertyChangePtr change(new QScenePropertyChange(NodeAdded, QSceneChange::Node, id())); + change->setPropertyName("parameter"); + change->setValue(QVariant::fromValue(parameter->id())); + d->notifyObservers(change); + } + } +} + +void QTechnique::removeParameter(QParameter *parameter) +{ + Q_D(QTechnique); + + if (d->m_changeArbiter != Q_NULLPTR) { + QScenePropertyChangePtr change(new QScenePropertyChange(NodeRemoved, QSceneChange::Node, id())); + change->setPropertyName("parameter"); + change->setValue(QVariant::fromValue(parameter->id())); + d->notifyObservers(change); + } + d->m_parameters.removeOne(parameter); +} + +/*! + * Appends a \a pass to the technique. This posts a ComponentAdded + * QScenePropertyChange notification to the QChangeArbiter with the + * value being the \a pass and the property name being "pass". + */ +void QTechnique::addPass(QRenderPass *pass) +{ + Q_D(QTechnique); + if (!d->m_renderPasses.contains(pass)) { + d->m_renderPasses.append(pass); + + // We need to add it as a child of the current node if it has been declared inline + // Or not previously added as a child of the current node so that + // 1) The backend gets notified about it's creation + // 2) When the current node is destroyed, it gets destroyed as well + if (!pass->parent()) + pass->setParent(this); + + if (d->m_changeArbiter != Q_NULLPTR) { + QScenePropertyChangePtr e(new QScenePropertyChange(NodeAdded, QSceneChange::Node, id())); + e->setPropertyName("pass"); + e->setValue(QVariant::fromValue(pass->id())); + d->notifyObservers(e); + } + } +} + +/*! + * Removes a \a pass from the technique. This posts a ComponentRemoved + * QScenePropertyChange notification to the QChangeArbiter with the value + * being the id of \a pass and the property name being "pass". + */ +void QTechnique::removePass(QRenderPass *pass) +{ + Q_D(QTechnique); + if (d->m_changeArbiter) { + QScenePropertyChangePtr e(new QScenePropertyChange(NodeRemoved, QSceneChange::Node, id())); + e->setPropertyName("pass"); + e->setValue(QVariant::fromValue(pass->id())); + d->notifyObservers(e); + } + d->m_renderPasses.removeOne(pass); +} + +/*! + * Returns the list of render passes contained in the technique. + */ +QList<QRenderPass *> QTechnique::renderPasses() const +{ + Q_D(const QTechnique); + return d->m_renderPasses; +} + +QList<QParameter *> QTechnique::parameters() const +{ + Q_D(const QTechnique); + return d->m_parameters; +} + +QOpenGLFilter *QTechnique::openGLFilter() +{ + Q_D(QTechnique); + return &d->m_openGLFilter; +} + +} // of namespace Qt3DRender + +QT_END_NAMESPACE + +#include "moc_qtechnique.cpp" diff --git a/src/render/materialsystem/qtechnique.h b/src/render/materialsystem/qtechnique.h new file mode 100644 index 000000000..d45892991 --- /dev/null +++ b/src/render/materialsystem/qtechnique.h @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** 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:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.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$ +** +****************************************************************************/ + +#ifndef QT3DRENDER_QTECHNIQUE_H +#define QT3DRENDER_QTECHNIQUE_H + +#include <Qt3DRenderer/qt3drenderer_global.h> +#include <Qt3DCore/qnode.h> +#include <Qt3DRenderer/qrenderpass.h> +#include <Qt3DRenderer/qannotation.h> +#include <QList> +#include <QSharedPointer> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QParameter; +class QTechniquePrivate; +class QOpenGLFilter; + +class QT3DRENDERERSHARED_EXPORT QTechnique : public Qt3D::QNode +{ + Q_OBJECT + Q_PROPERTY(Qt3DRender::QOpenGLFilter *openGLFilter READ openGLFilter) + +public: + explicit QTechnique(Qt3D::QNode *parent = 0); + ~QTechnique(); + + void addAnnotation(QAnnotation *criterion); + void removeAnnotation(QAnnotation *criterion); + QList<QAnnotation *> annotations() const; + + void addParameter(QParameter *p); + void removeParameter(QParameter *p); + QList<QParameter *> parameters() const; + + void addPass(QRenderPass *pass); + void removePass(QRenderPass *pass); + QList<QRenderPass *> renderPasses() const; + + QOpenGLFilter *openGLFilter(); + +protected: + QTechnique(QTechniquePrivate &dd, Qt3D::QNode *parent = 0); + void copy(const Qt3D::QNode *ref) Q_DECL_OVERRIDE; + +private: + Q_DECLARE_PRIVATE(QTechnique) + QT3D_CLONEABLE(QTechnique) + Q_PRIVATE_SLOT(d_func(), void _q_openGLFilterChanged()) +}; + +} + +QT_END_NAMESPACE + +#endif // QT3DRENDER_QTECHNIQUE_H diff --git a/src/render/materialsystem/qtechnique_p.h b/src/render/materialsystem/qtechnique_p.h new file mode 100644 index 000000000..87fa18647 --- /dev/null +++ b/src/render/materialsystem/qtechnique_p.h @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** 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:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.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$ +** +****************************************************************************/ + +#ifndef QT3DRENDER_QTECHNIQUE_P_H +#define QT3DRENDER_QTECHNIQUE_P_H + +#include <private/qnode_p.h> +#include <Qt3DRenderer/qopenglfilter.h> +#include <Qt3DRenderer/qt3drenderer_global.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QTechnique; +class QAnnotation; +class QParameter; +class QRenderPass; + +class QT3DRENDERERSHARED_EXPORT QTechniquePrivate : public Qt3D::QNodePrivate +{ +public: + QTechniquePrivate(); + ~QTechniquePrivate(); + + Q_DECLARE_PUBLIC(QTechnique) + QList<QAnnotation *> m_annotationList; + QList<QParameter *> m_parameters; + QList<QRenderPass*> m_renderPasses; + QOpenGLFilter m_openGLFilter; + +private: + void _q_openGLFilterChanged(); +}; + +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_QTECHNIQUE_P_H diff --git a/src/render/materialsystem/renderpass.cpp b/src/render/materialsystem/renderpass.cpp new file mode 100644 index 000000000..b64b8682d --- /dev/null +++ b/src/render/materialsystem/renderpass.cpp @@ -0,0 +1,194 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.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 "renderpass_p.h" +#include <Qt3DRenderer/private/annotation_p.h> +#include <Qt3DRenderer/qparametermapping.h> +#include <Qt3DRenderer/qrenderstate.h> +#include <Qt3DRenderer/qrenderpass.h> +#include <Qt3DRenderer/qparameter.h> + +#include <Qt3DRenderer/private/renderstates_p.h> +#include <Qt3DRenderer/private/renderstateset_p.h> + +#include <Qt3DCore/qscenepropertychange.h> + +QT_BEGIN_NAMESPACE + +using namespace Qt3D; + +namespace Qt3DRender { +namespace Render { + +RenderPass::RenderPass() + : QBackendNode() +{ +} + +RenderPass::~RenderPass() +{ + cleanup(); +} + +void RenderPass::cleanup() +{ +} + +void RenderPass::updateFromPeer(Qt3D::QNode *peer) +{ + QRenderPass *pass = static_cast<QRenderPass *>(peer); + + m_parameterPack.clear(); + + if (pass->shaderProgram() != Q_NULLPTR) + m_shaderUuid = pass->shaderProgram()->id(); + // The RenderPass clones frontend bindings in case the frontend ever removes them + // TO DO: We probably need a QParameterMapper manager + Q_FOREACH (QParameterMapping *binding, pass->bindings()) + appendBinding(ParameterMapping(binding)); + Q_FOREACH (QAnnotation *c, pass->annotations()) + appendAnnotation(c->id()); + Q_FOREACH (QRenderState *renderState, pass->renderStates()) + appendRenderState(renderState->id(), RenderState::getOrCreateBackendState(renderState)); + Q_FOREACH (QParameter *p, pass->parameters()) + m_parameterPack.appendParameter(p->id()); +} + +void RenderPass::sceneChangeEvent(const Qt3D::QSceneChangePtr &e) +{ + QScenePropertyChangePtr propertyChange = qSharedPointerCast<QScenePropertyChange>(e); + switch (e->type()) { + + case NodeAdded: { + if (propertyChange->propertyName() == QByteArrayLiteral("annotation")) { + appendAnnotation(propertyChange->value().value<QNodeId>()); + } else if (propertyChange->propertyName() == QByteArrayLiteral("shaderProgram")) { + m_shaderUuid = propertyChange->value().value<QNodeId>(); + } else if (propertyChange->propertyName() == QByteArrayLiteral("binding")) { + appendBinding(ParameterMapping(propertyChange->value().value<QParameterMapping *>())); + } else if (propertyChange->propertyName() == QByteArrayLiteral("renderState")) { + QNodePtr nodePtr = propertyChange->value().value<QNodePtr>(); + QRenderState *renderState = static_cast<QRenderState *>(nodePtr.data()); + appendRenderState(renderState->id(), RenderState::getOrCreateBackendState(renderState)); + } else if (propertyChange->propertyName() == QByteArrayLiteral("parameter")) { + m_parameterPack.appendParameter(propertyChange->value().value<QNodeId>()); + } + break; + } + + case NodeRemoved: { + if (propertyChange->propertyName() == QByteArrayLiteral("annotation")) { + removeAnnotation(propertyChange->value().value<QNodeId>()); + } else if (propertyChange->propertyName() == QByteArrayLiteral("shaderProgram")) { + m_shaderUuid = QNodeId(); + } else if (propertyChange->propertyName() == QByteArrayLiteral("binding")) { + removeBinding(propertyChange->value().value<QNodeId>()); + } else if (propertyChange->propertyName() == QByteArrayLiteral("renderState")) { + removeRenderState(propertyChange->value().value<QNodeId>()); + } else if (propertyChange->propertyName() == QByteArrayLiteral("parameter")) { + m_parameterPack.removeParameter(propertyChange->value().value<QNodeId>()); + } + break; + } + + default: + break; + } +} + +Qt3D::QNodeId RenderPass::shaderProgram() const +{ + return m_shaderUuid; +} + +QList<ParameterMapping> RenderPass::bindings() const +{ + return m_bindings.values(); +} + +QList<Qt3D::QNodeId> RenderPass::annotations() const +{ + return m_annotationList; +} + +QList<RenderState *> RenderPass::renderStates() const +{ + return m_renderStates.values(); +} + +QList<Qt3D::QNodeId> RenderPass::parameters() const +{ + return m_parameterPack.parameters(); +} + +void RenderPass::appendAnnotation(const Qt3D::QNodeId &annotationId) +{ + if (!m_annotationList.contains(annotationId)) + m_annotationList.append(annotationId); +} + +void RenderPass::removeAnnotation(const Qt3D::QNodeId &annotationId) +{ + m_annotationList.removeOne(annotationId); +} + +void RenderPass::appendBinding(const ParameterMapping &binding) +{ + if (!m_bindings.contains(binding.id())) + m_bindings[binding.id()] = binding; +} + +void RenderPass::removeBinding(const Qt3D::QNodeId &bindingId) +{ + m_bindings.remove(bindingId); +} + +void RenderPass::appendRenderState(const Qt3D::QNodeId &id, RenderState *renderState) +{ + if (!m_renderStates.contains(id)) + m_renderStates[id] = renderState; +} + +void RenderPass::removeRenderState(const Qt3D::QNodeId &renderStateId) +{ + m_renderStates.remove(renderStateId); +} + +} // namespace Render +} // namespace Qt3DRender + +QT_END_NAMESPACE diff --git a/src/render/materialsystem/renderpass_p.h b/src/render/materialsystem/renderpass_p.h new file mode 100644 index 000000000..ee9050055 --- /dev/null +++ b/src/render/materialsystem/renderpass_p.h @@ -0,0 +1,103 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.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$ +** +****************************************************************************/ + +#ifndef QT3DRENDER_RENDER_RENDERPASS_H +#define QT3DRENDER_RENDER_RENDERPASS_H + +#include <Qt3DRenderer/qt3drenderer_global.h> +#include <Qt3DRenderer/private/parametermapping_p.h> +#include <Qt3DRenderer/private/parameterpack_p.h> +#include <Qt3DCore/private/qabstractaspect_p.h> +#include <Qt3DCore/qbackendnode.h> +#include <Qt3DCore/qnodeid.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QRenderPass; +class QAbstractShader; +class QParameterMapping; +class QAnnotation; +class QRenderState; + +namespace Render { + +class RenderPassManager; +class RenderState; + +class Q_AUTOTEST_EXPORT RenderPass : public Qt3D::QBackendNode +{ +public: + RenderPass(); + ~RenderPass(); + + void cleanup(); + + void updateFromPeer(Qt3D::QNode *peer) Q_DECL_OVERRIDE; + void sceneChangeEvent(const Qt3D::QSceneChangePtr &e) Q_DECL_OVERRIDE; + + Qt3D::QNodeId shaderProgram() const; + QList<ParameterMapping> bindings() const; + QList<Qt3D::QNodeId> annotations() const; + QList<RenderState *> renderStates() const; + QList<Qt3D::QNodeId> parameters() const; + +private: + void appendAnnotation(const Qt3D::QNodeId &criterionId); + void removeAnnotation(const Qt3D::QNodeId &criterionId); + + void appendBinding(const ParameterMapping &binding); + void removeBinding(const Qt3D::QNodeId &bindingId); + + void appendRenderState(const Qt3D::QNodeId &id, RenderState *renderState); + void removeRenderState(const Qt3D::QNodeId &renderStateId); + + Qt3D::QNodeId m_shaderUuid; + QHash<Qt3D::QNodeId, ParameterMapping> m_bindings; + QHash<Qt3D::QNodeId, RenderState *> m_renderStates; + QList<Qt3D::QNodeId> m_annotationList; + ParameterPack m_parameterPack; +}; + +} // namespace Render + +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_RENDER_RENDERPASS_H diff --git a/src/render/materialsystem/shader.cpp b/src/render/materialsystem/shader.cpp new file mode 100644 index 000000000..1a600bfbe --- /dev/null +++ b/src/render/materialsystem/shader.cpp @@ -0,0 +1,403 @@ +/**************************************************************************** +** +** 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:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.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 "shader_p.h" +#include "renderlogging_p.h" + +#include <QFile> +#include <QOpenGLContext> +#include <QOpenGLShaderProgram> +#include <QMutexLocker> +#include <qshaderprogram.h> +#include <Qt3DRenderer/private/graphicscontext_p.h> +#include <Qt3DRenderer/private/attachmentpack_p.h> +#include <Qt3DCore/qscenepropertychange.h> + +QT_BEGIN_NAMESPACE + +using namespace Qt3D; + +namespace Qt3DRender { +namespace Render { + +Shader::Shader() + : QBackendNode() + , m_program(Q_NULLPTR) + , m_isLoaded(false) + , m_dna(0) + , m_mutex(new QMutex()) +{ + m_shaderCode.resize(static_cast<int>(QShaderProgram::Compute) + 1); +} + +Shader::~Shader() +{ + // TO DO: ShaderProgram is leaked as of now + // Fix that taking care that they may be shared given a same dna + delete m_mutex; +} + +void Shader::cleanup() +{ + m_isLoaded = false; + m_dna = 0; + // TO DO: ShaderProgram is leaked as of now + // Fix that taking care that they may be shared given a same dna + m_program = Q_NULLPTR; + m_uniformsNames.clear(); + m_attributesNames.clear(); + m_uniformBlockNames.clear(); + m_uniforms.clear(); + m_attributes.clear(); + m_uniformBlocks.clear(); +} + +void Shader::updateFromPeer(Qt3D::QNode *peer) +{ + QShaderProgram *shader = static_cast<QShaderProgram *>(peer); + + for (int i = QShaderProgram::Vertex; i <= QShaderProgram::Compute; ++i) { + m_shaderCode[i].clear(); + } + + m_isLoaded = false; + + for (int i = QShaderProgram::Vertex; i <= QShaderProgram::Compute; ++i) { + QShaderProgram::ShaderType type = static_cast<const QShaderProgram::ShaderType>(i); + m_shaderCode[i] = shader->shaderCode(type); + } + updateDNA(); +} + +QVector<QString> Shader::uniformsNames() const +{ + return m_uniformsNames; +} + +QVector<QString> Shader::attributesNames() const +{ + return m_attributesNames; +} + +QVector<QString> Shader::uniformBlockNames() const +{ + return m_uniformBlockNames; +} + +QVector<QByteArray> Shader::shaderCode() const +{ + return m_shaderCode; +} + +void Shader::sceneChangeEvent(const Qt3D::QSceneChangePtr &e) +{ + if (e->type() == NodeUpdated) { + QScenePropertyChangePtr propertyChange = e.staticCast<QScenePropertyChange>(); + QVariant propertyValue = propertyChange->value(); + + if (propertyChange->propertyName() == QByteArrayLiteral("vertexSourceCode")) { + m_shaderCode[QShaderProgram::Vertex] = propertyValue.toByteArray(); + m_isLoaded = false; + } else if (propertyChange->propertyName() == QByteArrayLiteral("fragmentSourceCode")) { + m_shaderCode[QShaderProgram::Fragment] = propertyValue.toByteArray(); + m_isLoaded = false; + } else if (propertyChange->propertyName() == QByteArrayLiteral("tessellationControlSourceCode")) { + m_shaderCode[QShaderProgram::TessellationControl] = propertyValue.toByteArray(); + m_isLoaded = false; + } else if (propertyChange->propertyName() == QByteArrayLiteral("tessellationEvaluationSourceCode")) { + m_shaderCode[QShaderProgram::TessellationEvaluation] = propertyValue.toByteArray(); + m_isLoaded = false; + } else if (propertyChange->propertyName() == QByteArrayLiteral("geometrySourceCode")) { + m_shaderCode[QShaderProgram::Geometry] = propertyValue.toByteArray(); + m_isLoaded = false; + } else if (propertyChange->propertyName() == QByteArrayLiteral("computeSourceCode")) { + m_shaderCode[QShaderProgram::Compute] = propertyValue.toByteArray(); + m_isLoaded = false; + } + if (!m_isLoaded) + updateDNA(); + } +} + +bool Shader::isLoaded() const +{ + return m_isLoaded; +} + +ProgramDNA Shader::dna() const +{ + return m_dna; +} + +QVector<ShaderUniform> Shader::uniforms() const +{ + return m_uniforms; +} + +QVector<ShaderAttribute> Shader::attributes() const +{ + return m_attributes; +} + +QVector<ShaderUniformBlock> Shader::uniformBlocks() const +{ + return m_uniformBlocks; +} + +QHash<QString, ShaderUniform> Shader::activeUniformsForBlock(int blockIndex) const +{ + return m_blockIndexToShaderUniforms.value(blockIndex); +} + +ShaderUniformBlock Shader::uniformBlock(int blockIndex) +{ + for (int i = 0; i < m_uniformBlocks.size(); ++i) { + if (m_uniformBlocks[i].m_index == blockIndex) { + return m_uniformBlocks[i]; + } + } + return ShaderUniformBlock(); +} + +ShaderUniformBlock Shader::uniformBlock(const QString &blockName) +{ + for (int i = 0; i < m_uniformBlocks.size(); ++i) { + if (m_uniformBlocks[i].m_name == blockName) { + return m_uniformBlocks[i]; + } + } + return ShaderUniformBlock(); +} + +/*! + * Must be called with a valid, current QOpenGLContext + */ +QOpenGLShaderProgram *Shader::getOrCreateProgram(GraphicsContext *ctx) +{ + if (!m_isLoaded) { + delete m_program; + m_program = createProgram(ctx); + if (!m_program) + m_program = createDefaultProgram(); + m_isLoaded = true; + } + return m_program; +} + +void Shader::updateUniforms(GraphicsContext *ctx, const QUniformPack &pack) +{ + const QHash<QString, const QUniformValue* > &values = pack.uniforms(); + const QHash<QString, const QUniformValue* >::const_iterator valueEnd = values.constEnd(); + + Q_FOREACH (const ShaderUniform &uniform, m_uniforms) { + QHash<QString, const QUniformValue* >::const_iterator valueIt = values.constFind(uniform.m_name); + if (valueIt != valueEnd) + valueIt.value()->apply(ctx, uniform); + } +} + +void Shader::setFragOutputs(const QHash<QString, int> &fragOutputs) +{ + { + QMutexLocker lock(m_mutex); + m_fragOutputs = fragOutputs; + } + updateDNA(); +} + +static QOpenGLShader::ShaderType shaderType(QShaderProgram::ShaderType type) +{ + switch (type) { + case QShaderProgram::Vertex: return QOpenGLShader::Vertex; + case QShaderProgram::TessellationControl: return QOpenGLShader::TessellationControl; + case QShaderProgram::TessellationEvaluation: return QOpenGLShader::TessellationEvaluation; + case QShaderProgram::Geometry: return QOpenGLShader::Geometry; + case QShaderProgram::Fragment: return QOpenGLShader::Fragment; + case QShaderProgram::Compute: return QOpenGLShader::Compute; + default: Q_UNREACHABLE(); + } +} + +QOpenGLShaderProgram *Shader::createProgram(GraphicsContext *context) +{ + Q_ASSERT(QOpenGLContext::currentContext()); + + // Check if we already have a shader program matching all the shaderCode + QOpenGLShaderProgram *existingProg = context->containsProgram(m_dna); + if (existingProg) + return existingProg; + + // When we arrive at that point, that means that no matching program + // was found, so we need to load it + // Scoped pointer so early-returns delete automatically + QScopedPointer<QOpenGLShaderProgram> p(new QOpenGLShaderProgram); + + for (int i = QShaderProgram::Vertex; i <= QShaderProgram::Compute; ++i) { + // Compile shaders + QShaderProgram::ShaderType type = static_cast<const QShaderProgram::ShaderType>(i); + if (!m_shaderCode[type].isEmpty() && !p->addShaderFromSourceCode(shaderType(type), m_shaderCode[type])) + qWarning() << "Failed to compile shader:" << p->log(); + } + + // Call glBindFragDataLocation and link the program + // Since we are sharing shaders in the backend, we assume that if using custom + // fragOutputs, they should all be the same for a given shader + context->bindFragOutputs(p->programId(), m_fragOutputs); + if (!p->link()) { + qWarning() << "Failed to link shader program:" << p->log(); + return Q_NULLPTR; + } + + // take from scoped-pointer so it doesn't get deleted + return p.take(); +} + +QOpenGLShaderProgram* Shader::createDefaultProgram() +{ + QOpenGLShaderProgram* p = new QOpenGLShaderProgram; + p->addShaderFromSourceCode(QOpenGLShader::Vertex, + ""); + + p->addShaderFromSourceCode(QOpenGLShader::Fragment, + ""); + + p->link(); + + return p; +} + +void Shader::updateDNA() +{ + uint codeHash = qHash(m_shaderCode[QShaderProgram::Vertex] + + m_shaderCode[QShaderProgram::TessellationControl] + + m_shaderCode[QShaderProgram::TessellationEvaluation] + + m_shaderCode[QShaderProgram::Geometry] + + m_shaderCode[QShaderProgram::Fragment] + + m_shaderCode[QShaderProgram::Compute]); + + QMutexLocker locker(m_mutex); + uint attachmentHash = 0; + QHash<QString, int>::const_iterator it = m_fragOutputs.begin(); + QHash<QString, int>::const_iterator end = m_fragOutputs.end(); + while (it != end) { + attachmentHash += ::qHash(it.value()) + ::qHash(it.key()); + ++it; + } + m_dna = codeHash + attachmentHash; +} + +void Shader::initializeUniforms(const QVector<ShaderUniform> &uniformsDescription) +{ + m_uniforms = uniformsDescription; + m_uniformsNames.resize(uniformsDescription.size()); + QHash<QString, ShaderUniform> activeUniformsInDefaultBlock; + + for (int i = 0; i < uniformsDescription.size(); i++) { + m_uniformsNames[i] = uniformsDescription[i].m_name; + if (uniformsDescription[i].m_blockIndex == -1) { // Uniform is in default block + qCDebug(Shaders) << "Active Uniform in Default Block " << uniformsDescription[i].m_name << uniformsDescription[i].m_blockIndex; + activeUniformsInDefaultBlock.insert(uniformsDescription[i].m_name, uniformsDescription[i]); + } + } + m_blockIndexToShaderUniforms.insert(-1, activeUniformsInDefaultBlock); +} + +void Shader::initializeAttributes(const QVector<ShaderAttribute> &attributesDescription) +{ + m_attributes = attributesDescription; + m_attributesNames.resize(attributesDescription.size()); + for (int i = 0; i < attributesDescription.size(); i++) { + m_attributesNames[i] = attributesDescription[i].m_name; + qCDebug(Shaders) << "Active Attribute " << attributesDescription[i].m_name; + } +} + +void Shader::initializeUniformBlocks(const QVector<ShaderUniformBlock> &uniformBlockDescription) +{ + m_uniformBlocks = uniformBlockDescription; + m_uniformBlockNames.resize(uniformBlockDescription.size()); + for (int i = 0; i < uniformBlockDescription.size(); ++i) { + m_uniformBlockNames[i] = uniformBlockDescription[i].m_name; + qCDebug(Shaders) << "Initializing Uniform Block {" << m_uniformBlockNames[i] << "}"; + + // Find all active uniforms for the shader block + QVector<ShaderUniform>::const_iterator uniformsIt = m_uniforms.begin(); + const QVector<ShaderUniform>::const_iterator uniformsEnd = m_uniforms.end(); + + QVector<QString>::const_iterator uniformNamesIt = m_uniformsNames.begin(); + const QVector<QString>::const_iterator uniformNamesEnd = m_attributesNames.end(); + + QHash<QString, ShaderUniform> activeUniformsInBlock; + + while (uniformsIt != uniformsEnd && uniformNamesIt != uniformNamesEnd) { + if (uniformsIt->m_blockIndex == uniformBlockDescription[i].m_index) { + QString uniformName = *uniformNamesIt; + if (!m_uniformBlockNames[i].isEmpty() && !uniformName.startsWith(m_uniformBlockNames[i])) + uniformName = m_uniformBlockNames[i] + QStringLiteral(".") + *uniformNamesIt; + activeUniformsInBlock.insert(uniformName, *uniformsIt); + qCDebug(Shaders) << "Active Uniform Block " << uniformName << " in block " << m_uniformBlockNames[i] << " at index " << uniformsIt->m_blockIndex; + } + ++uniformsIt; + ++uniformNamesIt; + } + m_blockIndexToShaderUniforms.insert(uniformBlockDescription[i].m_index, activeUniformsInBlock); + } +} + +/*! + \internal + Initializes this Shader's state relating to attributes, global block uniforms and + and named uniform blocks by copying these details from \a other. +*/ +void Shader::initialize(const Shader &other) +{ + Q_ASSERT(m_dna == other.m_dna); + m_program = other.m_program; + m_uniformsNames = other.m_uniformsNames; + m_uniforms = other.m_uniforms; + m_attributesNames = other.m_attributesNames; + m_attributes = other.m_attributes; + m_uniformBlockNames = other.m_uniformBlockNames; + m_uniformBlocks = other.m_uniformBlocks; + m_blockIndexToShaderUniforms = other.m_blockIndexToShaderUniforms; + m_fragOutputs = other.m_fragOutputs; + m_isLoaded = other.m_isLoaded; +} + +} // namespace Render +} // namespace Qt3DRender + +QT_END_NAMESPACE diff --git a/src/render/materialsystem/shader_p.h b/src/render/materialsystem/shader_p.h new file mode 100644 index 000000000..7ff0cedea --- /dev/null +++ b/src/render/materialsystem/shader_p.h @@ -0,0 +1,132 @@ +/**************************************************************************** +** +** 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:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.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$ +** +****************************************************************************/ + +#ifndef QT3DRENDER_RENDER_SHADER_H +#define QT3DRENDER_RENDER_SHADER_H + +#include <QVector> +#include <Qt3DRenderer/private/quniformvalue_p.h> +#include <Qt3DRenderer/private/shadervariables_p.h> +#include <Qt3DCore/qbackendnode.h> + +QT_BEGIN_NAMESPACE + +class QOpenGLShaderProgram; +class QMutex; + +namespace Qt3DRender { + +class QShaderProgram; + +namespace Render { + +class ShaderManager; +class AttachmentPack; + +typedef uint ProgramDNA; + +class Q_AUTOTEST_EXPORT Shader : public Qt3D::QBackendNode +{ +public: + Shader(); + ~Shader(); + + void cleanup(); + + void updateFromPeer(Qt3D::QNode *peer) Q_DECL_OVERRIDE; + void updateUniforms(GraphicsContext *ctx, const QUniformPack &pack); + void setFragOutputs(const QHash<QString, int> &fragOutputs); + + QVector<QString> uniformsNames() const; + QVector<QString> attributesNames() const; + QVector<QString> uniformBlockNames() const; + QVector<QByteArray> shaderCode() const; + + void sceneChangeEvent(const Qt3D::QSceneChangePtr &e) Q_DECL_OVERRIDE; + bool isLoaded() const; + ProgramDNA dna() const; + + QVector<ShaderUniform> uniforms() const; + QVector<ShaderAttribute> attributes() const; + QVector<ShaderUniformBlock> uniformBlocks() const; + + QHash<QString, ShaderUniform> activeUniformsForBlock(int blockIndex) const; + ShaderUniformBlock uniformBlock(int blockIndex); + ShaderUniformBlock uniformBlock(const QString &blockName); + +private: + QOpenGLShaderProgram *m_program; + + QOpenGLShaderProgram *createProgram(GraphicsContext *context); + QOpenGLShaderProgram *createDefaultProgram(); + + QVector<QString> m_uniformsNames; + QVector<ShaderUniform> m_uniforms; + + QVector<QString> m_attributesNames; + QVector<ShaderAttribute> m_attributes; + + QVector<QString> m_uniformBlockNames; + QVector<ShaderUniformBlock> m_uniformBlocks; + QHash<int, QHash<QString, ShaderUniform> > m_blockIndexToShaderUniforms; + + QHash<QString, int> m_fragOutputs; + + QVector<QByteArray> m_shaderCode; + + bool m_isLoaded; + ProgramDNA m_dna; + QMutex *m_mutex; + + void updateDNA(); + + // Private so that only GraphicContext can call it + void initializeUniforms(const QVector<ShaderUniform> &uniformsDescription); + void initializeAttributes(const QVector<ShaderAttribute> &attributesDescription); + void initializeUniformBlocks(const QVector<ShaderUniformBlock> &uniformBlockDescription); + + void initialize(const Shader &other); + + QOpenGLShaderProgram *getOrCreateProgram(GraphicsContext *ctx); + friend class GraphicsContext; +}; + +} // namespace Render +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_RENDER_SHADER_H diff --git a/src/render/materialsystem/shaderdata.cpp b/src/render/materialsystem/shaderdata.cpp new file mode 100644 index 000000000..743ea1c60 --- /dev/null +++ b/src/render/materialsystem/shaderdata.cpp @@ -0,0 +1,315 @@ +/**************************************************************************** +** +** 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:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.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 "shaderdata_p.h" +#include "qshaderdata.h" +#include "qshaderdata_p.h" +#include <QMetaProperty> +#include <QMetaObject> +#include <Qt3DCore/qscenepropertychange.h> +#include <private/graphicscontext_p.h> +#include <private/qbackendnode_p.h> +#include <private/uniformbuffer_p.h> +#include <private/managers_p.h> + +QT_BEGIN_NAMESPACE + +using namespace Qt3D; + +namespace Qt3DRender { +namespace Render { + +QList<Qt3D::QNodeId> ShaderData::m_updatedShaderData; + +ShaderData::ShaderData() + : QBackendNode() + , m_manager(Q_NULLPTR) + , m_mutex(new QMutex()) +{ +} + +ShaderData::~ShaderData() +{ + delete m_mutex; +} + +void ShaderData::updateFromPeer(Qt3D::QNode *peer) +{ + m_properties.clear(); + const QShaderData *shaderData = static_cast<const QShaderData *>(peer); + m_propertyReader = shaderData->propertyReader(); + if (!m_propertyReader.isNull()) + readPeerProperties(const_cast<QShaderData *>(shaderData)); +} + +// Call by cleanup job (single thread) +void ShaderData::clearUpdate() +{ + m_updatedProperties.clear(); + const QHash<QString, QVariant>::const_iterator end = m_nestedShaderDataProperties.end(); + QHash<QString, QVariant>::const_iterator it = m_nestedShaderDataProperties.begin(); + + while (it != end) { + if (it.value().userType() == QMetaType::QVariantList) { + Q_FOREACH (const QVariant &v, it.value().value<QVariantList>()) { + ShaderData *nested = m_manager->lookupResource(v.value<QNodeId>()); + if (nested != Q_NULLPTR) + nested->clearUpdate(); + } + } else { + ShaderData *nested = m_manager->lookupResource(it.value().value<QNodeId>()); + if (nested != Q_NULLPTR) + nested->clearUpdate(); + } + ++it; + } +} + +// Called by renderview jobs (several concurrent threads) +/*! + \internal + Lookup if the current ShaderData or a nested ShaderData has updated properties. + UpdateProperties contains either the value of the propertie of a QNodeId if it's another ShaderData. + Transformed properties are updated for all of ShaderData that have ones at the point. + + \note This needs to be performed for every top level ShaderData every time it is used. + As we don't know if the transformed properties use the same viewMatrix for all RenderViews. + */ +bool ShaderData::needsUpdate(const QMatrix4x4 &viewMatrix) +{ + // We can't perform this only once as we don't know if we would be call as the root or a + // nested ShaderData + QMutexLocker lock(m_mutex); + + // Update transformed properties + // We check the matrices and decide if the transform has changed since the previous call to needsUpdate + if (m_viewMatrix != viewMatrix) { + m_viewMatrix = viewMatrix; + const QHash<QString, QShaderData::TransformType>::const_iterator transformedEnd = m_transformedProperties.end(); + QHash<QString, QShaderData::TransformType>::const_iterator transformedIt = m_transformedProperties.begin(); + + while (transformedIt != transformedEnd) { + if (transformedIt.value() == QShaderData::ModelToEye) { + m_updatedProperties.insert(transformedIt.key(), m_viewMatrix * m_worldMatrix * m_originalProperties.value(transformedIt.key()).value<QVector3D>()); + m_properties.insert(transformedIt.key(), m_viewMatrix * m_worldMatrix * m_originalProperties.value(transformedIt.key()).value<QVector3D>()); + } + ++transformedIt; + } + } + + const QHash<QString, QVariant>::const_iterator end = m_nestedShaderDataProperties.end(); + QHash<QString, QVariant>::const_iterator it = m_nestedShaderDataProperties.begin(); + + while (it != end) { + if (it.value().userType() == QMetaType::QVariantList) { + QVariantList updatedNodes; + Q_FOREACH (const QVariant &v, it.value().value<QVariantList>()) { + ShaderData *nested = m_manager->lookupResource(v.value<QNodeId>()); + if (nested != Q_NULLPTR) { + // We need to add the nested nodes the the updated property list + // as if we need to maintain order + // if node[0] doesn't need update but node[1] does, + // if we only have a single element, the renderer would update element [0] + nested->needsUpdate(viewMatrix); + updatedNodes << v; + } + } + if (!updatedNodes.empty()) + m_updatedProperties.insert(it.key(), updatedNodes); + } else { + ShaderData *nested = m_manager->lookupResource(it.value().value<QNodeId>()); + if (nested != Q_NULLPTR && nested->needsUpdate(viewMatrix)) + m_updatedProperties.insert(it.key(), it.value()); + } + ++it; + } + return m_updatedProperties.size() > 0; +} + +void ShaderData::updateTransformedProperties(const QMatrix4x4 &nodeWorldMatrix) +{ + if (m_worldMatrix != nodeWorldMatrix) { + m_worldMatrix = nodeWorldMatrix; + + const QHash<QString, QShaderData::TransformType>::const_iterator transformedEnd = m_transformedProperties.end(); + QHash<QString, QShaderData::TransformType>::const_iterator transformedIt = m_transformedProperties.begin(); + + while (transformedIt != transformedEnd) { + if (transformedIt.value() == QShaderData::ModelToEye) { + m_updatedProperties.insert(transformedIt.key(), m_viewMatrix * m_worldMatrix * m_originalProperties.value(transformedIt.key()).value<QVector3D>()); + m_properties.insert(transformedIt.key(), m_viewMatrix * m_worldMatrix * m_originalProperties.value(transformedIt.key()).value<QVector3D>()); + } else { + m_updatedProperties.insert(transformedIt.key(), m_worldMatrix * m_originalProperties.value(transformedIt.key()).value<QVector3D>()); + m_properties.insert(transformedIt.key(), m_worldMatrix * m_originalProperties.value(transformedIt.key()).value<QVector3D>()); + } + ++transformedIt; + } + } +} + +// This will add the ShaderData to be cleared from updates at the end of the frame +// by the cleanup job +// Called by renderview jobs (several concurrent threads) +void ShaderData::addToClearUpdateList() +{ + QMutexLocker lock(m_mutex); + if (!ShaderData::m_updatedShaderData.contains(peerUuid())) + ShaderData::m_updatedShaderData.append(peerUuid()); +} + +const int qNodeIdTypeId = qMetaTypeId<Qt3D::QNodeId>(); + +void ShaderData::readPeerProperties(QShaderData *shaderData) +{ + const QMetaObject *metaObject = shaderData->metaObject(); + const int propertyOffset = QShaderData::staticMetaObject.propertyOffset(); + const int propertyCount = metaObject->propertyCount(); + + for (int i = propertyOffset; i < propertyCount; ++i) { + const QMetaProperty property = metaObject->property(i); + if (strcmp(property.name(), "data") == 0 || strcmp(property.name(), "childNodes") == 0) // We don't handle default Node properties + continue; + QVariant propertyValue = m_propertyReader->readProperty(shaderData->property(property.name())); + QString propertyName = QString::fromLatin1(property.name()); + + m_properties.insert(propertyName, propertyValue); + m_originalProperties.insert(propertyName, propertyValue); + + // We check if the property is a QNodeId or QList<QNodeId> so that we can + // check nested QShaderData for update + if (propertyValue.userType() == qNodeIdTypeId) { + m_nestedShaderDataProperties.insert(propertyName, propertyValue); + } else if (propertyValue.userType() == QMetaType::QVariantList) { + QVariantList list = propertyValue.value<QVariantList>(); + if (list.count() > 0 && list.at(0).userType() == qNodeIdTypeId) + m_nestedShaderDataProperties.insert(propertyName, propertyValue); + } + } + + // We look for transformed properties + QHash<QString, QVariant>::iterator it = m_properties.begin(); + const QHash<QString, QVariant>::iterator end = m_properties.end(); + + while (it != end) { + if (static_cast<QMetaType::Type>(it.value().type()) == QMetaType::QVector3D) { + // if there is a matching QShaderData::TransformType propertyTransformed + QVariant value = m_properties.value(it.key() + QStringLiteral("Transformed")); + // if that's the case, we apply a space transformation to the property + if (value.isValid() && value.type() == QVariant::Int) + m_transformedProperties.insert(it.key(), static_cast<QShaderData::TransformType>(value.toInt())); + } + ++it; + } +} + +void ShaderData::setManager(ShaderDataManager *manager) +{ + m_manager = manager; +} + +void ShaderData::sceneChangeEvent(const Qt3D::QSceneChangePtr &e) +{ + if (!m_propertyReader.isNull()) { + QScenePropertyChangePtr propertyChange = qSharedPointerCast<QScenePropertyChange>(e); + QString propertyName = QString::fromLatin1(propertyChange->propertyName()); + switch (e->type()) { + case NodeUpdated: { + // Note we aren't notified about nested QShaderData in this call + // only scalar / vec properties + if (m_properties.contains(propertyName)) { + QVariant val = m_propertyReader->readProperty(propertyChange->value()); + // If this is a Transformed property, we need to multiply against the correct + // matrices + m_originalProperties.insert(propertyName, val); + if (m_transformedProperties.contains(propertyName)) { + if (m_transformedProperties[propertyName] == QShaderData::ModelToEye) + val = m_viewMatrix * m_worldMatrix * val.value<QVector3D>(); + else + val = m_worldMatrix * val.value<QVector3D>(); + } + m_properties.insert(propertyName, val); + m_updatedProperties.insert(propertyName, val); + } + break; + } + case NodeAdded: { + m_properties.insert(propertyName, m_propertyReader->readProperty(propertyChange->value())); + m_originalProperties.insert(propertyName, m_propertyReader->readProperty(propertyChange->value())); + m_nestedShaderDataProperties.insert(propertyName, propertyChange->value()); + break; + } + case NodeRemoved: { + if (m_properties.contains(propertyName)) { + m_originalProperties.remove(propertyName); + m_properties.remove(propertyName); + m_nestedShaderDataProperties.remove(propertyName); + } + break; + } + default: + break; + } + } +} + +RenderShaderDataFunctor::RenderShaderDataFunctor(ShaderDataManager *manager) + : m_manager(manager) +{ +} + +Qt3D::QBackendNode *RenderShaderDataFunctor::create(Qt3D::QNode *frontend, const Qt3D::QBackendNodeFactory *factory) const +{ + ShaderData *backend = m_manager->getOrCreateResource(frontend->id()); + backend->setFactory(factory); + backend->setManager(m_manager); + backend->setPeer(frontend); + return backend; +} + +Qt3D::QBackendNode *RenderShaderDataFunctor::get(const Qt3D::QNodeId &id) const +{ + return m_manager->lookupResource(id); +} + +void RenderShaderDataFunctor::destroy(const Qt3D::QNodeId &id) const +{ + m_manager->releaseResource(id); +} + +} // namespace Render +} // namespace Qt3DRender + +QT_END_NAMESPACE diff --git a/src/render/materialsystem/shaderdata_p.h b/src/render/materialsystem/shaderdata_p.h new file mode 100644 index 000000000..d09e5bac8 --- /dev/null +++ b/src/render/materialsystem/shaderdata_p.h @@ -0,0 +1,125 @@ +/**************************************************************************** +** +** 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:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.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$ +** +****************************************************************************/ + +#ifndef QT3DRENDER_RENDER_SHADERDATA_P_H +#define QT3DRENDER_RENDER_SHADERDATA_P_H + +#include <Qt3DCore/qbackendnode.h> +#include <private/shadervariables_p.h> +#include <Qt3DRenderer/qshaderdata.h> +#include <QMutex> +#include <QMatrix4x4> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +namespace Render { + +class GraphicsContext; +class UniformBuffer; +class ShaderDataManager; + +class Q_AUTOTEST_EXPORT ShaderData : public Qt3D::QBackendNode +{ +public: + ShaderData(); + ~ShaderData(); + + void updateFromPeer(Qt3D::QNode *peer) Q_DECL_OVERRIDE; + inline QHash<QString, QVariant> properties() const { return m_properties; } + inline QHash<QString, QVariant> updatedProperties() const { return m_updatedProperties; } + + // Called by cleanup job + inline static QList<Qt3D::QNodeId> updatedShaderDataList() { return m_updatedShaderData; } + inline static void clearShaderDataList() { return m_updatedShaderData.clear(); } + void clearUpdate(); + + // Call by RenderViewJobs + void addToClearUpdateList(); + bool needsUpdate(const QMatrix4x4 &viewMatrix); + + void updateTransformedProperties(const QMatrix4x4 &nodeWordlTransform); + +protected: + void sceneChangeEvent(const Qt3D::QSceneChangePtr &e) Q_DECL_OVERRIDE; + +private: + // 1 to 1 match with frontend properties, modified only by sceneChangeEvent + QHash<QString, QVariant> m_originalProperties; + // 1 to 1 match with frontend properties apart from Transformed + // properties which contain the matrices product + QHash<QString, QVariant> m_properties; + // only updated properties, Transformed properties have the same + // value as in m_properties + QHash<QString, QVariant> m_updatedProperties; + PropertyReaderInterfacePtr m_propertyReader; + QHash<QString, QVariant> m_nestedShaderDataProperties; + QHash<QString, QShaderData::TransformType> m_transformedProperties; + ShaderDataManager *m_manager; + QMutex *m_mutex; + static QList<Qt3D::QNodeId> m_updatedShaderData; + QMatrix4x4 m_worldMatrix; + QMatrix4x4 m_viewMatrix; + + void readPeerProperties(QShaderData *peer); + void setManager(ShaderDataManager *manager); + + friend class RenderShaderDataFunctor; +}; + +class RenderShaderDataFunctor : public Qt3D::QBackendNodeFunctor +{ +public: + explicit RenderShaderDataFunctor(ShaderDataManager *manager); + + Qt3D::QBackendNode *create(Qt3D::QNode *frontend, const Qt3D::QBackendNodeFactory *factory) const Q_DECL_FINAL; + Qt3D::QBackendNode *get(const Qt3D::QNodeId &id) const Q_DECL_FINAL; + void destroy(const Qt3D::QNodeId &id) const Q_DECL_FINAL; + +private: + ShaderDataManager *m_manager; +}; + +} // namespace Render + +} // namespace Qt3DRender + +QT_END_NAMESPACE + +Q_DECLARE_METATYPE(Qt3DRender::Render::ShaderData*) + +#endif // QT3DRENDER_RENDER_SHADERDATA_P_H diff --git a/src/render/materialsystem/technique.cpp b/src/render/materialsystem/technique.cpp new file mode 100644 index 000000000..a3315f30e --- /dev/null +++ b/src/render/materialsystem/technique.cpp @@ -0,0 +1,189 @@ +/**************************************************************************** +** +** 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:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.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 "technique_p.h" + +#include <Qt3DRenderer/qrenderpass.h> +#include <Qt3DRenderer/qparameter.h> +#include <Qt3DRenderer/qtechnique.h> +#include <Qt3DRenderer/qopenglfilter.h> +#include <Qt3DRenderer/private/renderer_p.h> +#include <Qt3DRenderer/private/annotation_p.h> +#include <Qt3DRenderer/private/shader_p.h> +#include <Qt3DCore/private/qaspectmanager_p.h> +#include <Qt3DCore/private/qchangearbiter_p.h> +#include <Qt3DCore/qscenepropertychange.h> + +#include <QDebug> + +QT_BEGIN_NAMESPACE + +using namespace Qt3D; + +namespace Qt3DRender { +namespace Render { + +Technique::Technique() + : QBackendNode() + , m_openglFilter(new QOpenGLFilter()) +{ +} + +Technique::~Technique() +{ + cleanup(); + delete m_openglFilter; +} + +void Technique::cleanup() +{ +} + +void Technique::updateFromPeer(Qt3D::QNode *peer) +{ + m_parameterPack.clear(); + m_renderPasses.clear(); + m_annotationList.clear(); + + QTechnique *technique = static_cast<QTechnique *>(peer); + + if (technique != Q_NULLPTR) { + Q_FOREACH (QParameter *p, technique->parameters()) + m_parameterPack.appendParameter(p->id()); + Q_FOREACH (QRenderPass *rPass, technique->renderPasses()) + appendRenderPass(rPass->id()); + Q_FOREACH (QAnnotation *annotation, technique->annotations()) + appendAnnotation(annotation->id()); + + // Copy OpenGLFilter info from frontend OpenGLFilter + QOpenGLFilter *peerFilter = technique->openGLFilter(); + m_openglFilter->copy(*peerFilter); + } +} + +void Technique::sceneChangeEvent(const Qt3D::QSceneChangePtr &e) +{ + QScenePropertyChangePtr propertyChange = qSharedPointerCast<QScenePropertyChange>(e); + switch (e->type()) { + + case NodeUpdated: { + if (propertyChange->propertyName() == QByteArrayLiteral("openGLFilter")) { + QOpenGLFilter *filter = propertyChange->value().value<QOpenGLFilter *>(); + if (filter != Q_NULLPTR) { + m_openglFilter->copy(*filter); + delete filter; + } + } + break; + } + + case NodeAdded: { + if (propertyChange->propertyName() == QByteArrayLiteral("pass")) { + appendRenderPass(propertyChange->value().value<QNodeId>()); + } + else if (propertyChange->propertyName() == QByteArrayLiteral("parameter")) { + m_parameterPack.appendParameter(propertyChange->value().value<QNodeId>()); + } + else if (propertyChange->propertyName() == QByteArrayLiteral("annotation")) { + appendAnnotation(propertyChange->value().value<QNodeId>()); + } + break; + } + + case NodeRemoved: { + if (propertyChange->propertyName() == QByteArrayLiteral("pass")) { + removeRenderPass(propertyChange->value().value<QNodeId>()); + } + else if (propertyChange->propertyName() == QByteArrayLiteral("parameter")) { + m_parameterPack.removeParameter(propertyChange->value().value<QNodeId>()); + } + else if (propertyChange->propertyName() == QByteArrayLiteral("annotation")) { + removeAnnotation(propertyChange->value().value<QNodeId>()); + } + break; + } + + default: + break; + } +} + +QList<Qt3D::QNodeId> Technique::parameters() const +{ + return m_parameterPack.parameters(); +} + +void Technique::appendRenderPass(const Qt3D::QNodeId &renderPassId) +{ + if (!m_renderPasses.contains(renderPassId)) + m_renderPasses.append(renderPassId); +} + +void Technique::removeRenderPass(const Qt3D::QNodeId &renderPassId) +{ + m_renderPasses.removeOne(renderPassId); +} + +QList<Qt3D::QNodeId> Technique::annotations() const +{ + return m_annotationList; +} + +QList<Qt3D::QNodeId> Technique::renderPasses() const +{ + return m_renderPasses; +} + +QOpenGLFilter *Technique::openGLFilter() const +{ + return m_openglFilter; +} + +void Technique::appendAnnotation(const Qt3D::QNodeId &criterionId) +{ + if (!m_annotationList.contains(criterionId)) + m_annotationList.append(criterionId); +} + +void Technique::removeAnnotation(const Qt3D::QNodeId &criterionId) +{ + m_annotationList.removeOne(criterionId); +} + +} // namespace Render +} // namespace Qt3DRender + +QT_END_NAMESPACE diff --git a/src/render/materialsystem/technique_p.h b/src/render/materialsystem/technique_p.h new file mode 100644 index 000000000..dbebe7fc9 --- /dev/null +++ b/src/render/materialsystem/technique_p.h @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.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$ +** +****************************************************************************/ + +#ifndef QT3DRENDER_RENDER_TECHNIQUE_H +#define QT3DRENDER_RENDER_TECHNIQUE_H + +#include <QVector> +#include <QStringList> +#include <Qt3DRenderer/private/parameterpack_p.h> +#include <Qt3DRenderer/qannotation.h> +#include <Qt3DCore/qbackendnode.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QTechnique; +class QParameter; +class QOpenGLFilter; +class QAnnotation; +class QRenderPass; + +namespace Render { + +class TechniqueManager; + +class Technique : public Qt3D::QBackendNode +{ +public: + Technique(); + ~Technique(); + void cleanup(); + + void updateFromPeer(Qt3D::QNode *peer) Q_DECL_OVERRIDE; + + void sceneChangeEvent(const Qt3D::QSceneChangePtr &e) Q_DECL_OVERRIDE; + QList<Qt3D::QNodeId> parameters() const; + + void appendRenderPass(const Qt3D::QNodeId &renderPassId); + void removeRenderPass(const Qt3D::QNodeId &renderPassId); + + void appendAnnotation(const Qt3D::QNodeId &criterionId); + void removeAnnotation(const Qt3D::QNodeId &criterionId); + + QList<Qt3D::QNodeId> annotations() const; + QList<Qt3D::QNodeId> renderPasses() const; + QOpenGLFilter *openGLFilter() const; + +private: + QOpenGLFilter *m_openglFilter; + + ParameterPack m_parameterPack; + QList<Qt3D::QNodeId> m_annotationList; + QList<Qt3D::QNodeId> m_renderPasses; +}; + +} // namespace Render +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_RENDER_TECHNIQUE_H |