diff options
author | Kevin Ottens <kevin.ottens@kdab.com> | 2017-03-30 09:28:17 +0200 |
---|---|---|
committer | Kevin Ottens <kevin.ottens@kdab.com> | 2017-06-20 21:35:30 +0000 |
commit | 29a748511a8bd9dac373d1390d38999b9fd7c49d (patch) | |
tree | 2be549e11c6f0ddb18c70070933404ead788b09f /src/gui/util | |
parent | 3a78c62bb2334ed6b6d7fc23e717b08c1de2c2ef (diff) |
[Shader Graph Gen.] Introduce QShaderGraph
This allows to connect our nodes together via ports. This way user code
can assemble a shader from simpler blocks.
Change-Id: I168dcf4af6aa11ad47b68d91e5a55e96ca922678
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/gui/util')
-rw-r--r-- | src/gui/util/qshadergraph.cpp | 88 | ||||
-rw-r--r-- | src/gui/util/qshadergraph_p.h | 100 | ||||
-rw-r--r-- | src/gui/util/util.pri | 2 |
3 files changed, 190 insertions, 0 deletions
diff --git a/src/gui/util/qshadergraph.cpp b/src/gui/util/qshadergraph.cpp new file mode 100644 index 0000000000..0735c3cfe3 --- /dev/null +++ b/src/gui/util/qshadergraph.cpp @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qshadergraph_p.h" + +QT_BEGIN_NAMESPACE + +void QShaderGraph::addNode(const QShaderNode &node) +{ + removeNode(node); + m_nodes.append(node); +} + +void QShaderGraph::removeNode(const QShaderNode &node) +{ + const auto it = std::find_if(m_nodes.begin(), m_nodes.end(), + [node] (const QShaderNode &n) { return n.uuid() == node.uuid(); }); + if (it != m_nodes.end()) + m_nodes.erase(it); +} + +QVector<QShaderNode> QShaderGraph::nodes() const Q_DECL_NOTHROW +{ + return m_nodes; +} + +void QShaderGraph::addEdge(const QShaderGraph::Edge &edge) +{ + if (m_edges.contains(edge)) + return; + m_edges.append(edge); +} + +void QShaderGraph::removeEdge(const QShaderGraph::Edge &edge) +{ + m_edges.removeAll(edge); +} + +QVector<QShaderGraph::Edge> QShaderGraph::edges() const Q_DECL_NOTHROW +{ + return m_edges; +} + +bool operator==(const QShaderGraph::Edge &lhs, const QShaderGraph::Edge &rhs) Q_DECL_NOTHROW +{ + return lhs.sourceNodeUuid == rhs.sourceNodeUuid + && lhs.sourcePortName == rhs.sourcePortName + && lhs.targetNodeUuid == rhs.targetNodeUuid + && lhs.targetPortName == rhs.targetPortName; +} + +QT_END_NAMESPACE diff --git a/src/gui/util/qshadergraph_p.h b/src/gui/util/qshadergraph_p.h new file mode 100644 index 0000000000..c582dcd18b --- /dev/null +++ b/src/gui/util/qshadergraph_p.h @@ -0,0 +1,100 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QSHADERGRAPH_P_H +#define QSHADERGRAPH_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <QtGui/private/qtguiglobal_p.h> + +#include <QtGui/private/qshadernode_p.h> + +QT_BEGIN_NAMESPACE + +class QShaderGraph +{ +public: + class Edge + { + public: + QUuid sourceNodeUuid; + QString sourcePortName; + QUuid targetNodeUuid; + QString targetPortName; + }; + + Q_GUI_EXPORT void addNode(const QShaderNode &node); + Q_GUI_EXPORT void removeNode(const QShaderNode &node); + Q_GUI_EXPORT QVector<QShaderNode> nodes() const Q_DECL_NOTHROW; + + Q_GUI_EXPORT void addEdge(const Edge &edge); + Q_GUI_EXPORT void removeEdge(const Edge &edge); + Q_GUI_EXPORT QVector<Edge> edges() const Q_DECL_NOTHROW; + +private: + QVector<QShaderNode> m_nodes; + QVector<Edge> m_edges; +}; + +Q_GUI_EXPORT bool operator==(const QShaderGraph::Edge &lhs, const QShaderGraph::Edge &rhs) Q_DECL_NOTHROW; + +inline bool operator!=(const QShaderGraph::Edge &lhs, const QShaderGraph::Edge &rhs) Q_DECL_NOTHROW +{ + return !(lhs == rhs); +} + +Q_DECLARE_TYPEINFO(QShaderGraph, Q_MOVABLE_TYPE); +Q_DECLARE_TYPEINFO(QShaderGraph::Edge, Q_MOVABLE_TYPE); + +QT_END_NAMESPACE + +Q_DECLARE_METATYPE(QShaderGraph) +Q_DECLARE_METATYPE(QShaderGraph::Edge) + +#endif // QSHADERGRAPH_P_H diff --git a/src/gui/util/util.pri b/src/gui/util/util.pri index d467d9dc57..96b25df4f9 100644 --- a/src/gui/util/util.pri +++ b/src/gui/util/util.pri @@ -8,6 +8,7 @@ HEADERS += \ util/qabstractlayoutstyleinfo_p.h \ util/qlayoutpolicy_p.h \ util/qshaderformat_p.h \ + util/qshadergraph_p.h \ util/qshadernode_p.h \ util/qshadernodeport_p.h @@ -18,5 +19,6 @@ SOURCES += \ util/qabstractlayoutstyleinfo.cpp \ util/qlayoutpolicy.cpp \ util/qshaderformat.cpp \ + util/qshadergraph.cpp \ util/qshadernode.cpp \ util/qshadernodeport.cpp |