summaryrefslogtreecommitdiffstats
path: root/src/render/materialsystem
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2019-06-03 12:11:35 +0200
committerPaul Lemire <paul.lemire@kdab.com>2019-06-05 10:30:43 +0200
commitdad524256b61ef17e5f9843167cdfa757ac4e184 (patch)
tree2066c52a07b86990e2ae78006d738b3c492231ed /src/render/materialsystem
parent361dfd809c3984e0b561b1a60a75beb188d42165 (diff)
Add ShaderImage backend node
Change-Id: Ife2e96df656ae220ecfe1e707d25e49e03ea8809 Reviewed-by: Sean Harmer <sean.harmer@kdab.com> Reviewed-by: Michael Brasser <michael.brasser@live.com>
Diffstat (limited to 'src/render/materialsystem')
-rw-r--r--src/render/materialsystem/materialsystem.pri2
-rw-r--r--src/render/materialsystem/shaderimage.cpp117
-rw-r--r--src/render/materialsystem/shaderimage_p.h105
3 files changed, 224 insertions, 0 deletions
diff --git a/src/render/materialsystem/materialsystem.pri b/src/render/materialsystem/materialsystem.pri
index 5aa36d615..ae3d2f78c 100644
--- a/src/render/materialsystem/materialsystem.pri
+++ b/src/render/materialsystem/materialsystem.pri
@@ -29,6 +29,7 @@ HEADERS += \
$$PWD/shader_p.h \
$$PWD/shaderbuilder_p.h \
$$PWD/shaderdata_p.h \
+ $$PWD/shaderimage_p.h \
$$PWD/technique_p.h \
$$PWD/qgraphicsapifilter.h \
$$PWD/qgraphicsapifilter_p.h \
@@ -54,6 +55,7 @@ SOURCES += \
$$PWD/shader.cpp \
$$PWD/shaderbuilder.cpp \
$$PWD/shaderdata.cpp \
+ $$PWD/shaderimage.cpp \
$$PWD/technique.cpp \
$$PWD/qgraphicsapifilter.cpp \
$$PWD/shadercache.cpp \
diff --git a/src/render/materialsystem/shaderimage.cpp b/src/render/materialsystem/shaderimage.cpp
new file mode 100644
index 000000000..cbda98ed0
--- /dev/null
+++ b/src/render/materialsystem/shaderimage.cpp
@@ -0,0 +1,117 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and 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 "shaderimage_p.h"
+#include <Qt3DRender/private/qshaderimage_p.h>
+#include <Qt3DCore/qpropertyupdatedchange.h>
+
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DRender {
+
+namespace Render {
+
+ShaderImage::ShaderImage()
+ : BackendNode(BackendNode::ReadOnly)
+ , m_textureId()
+ , m_mipLevel(0)
+ , m_layer(0)
+ , m_layered(false)
+ , m_access(QShaderImage::ReadWrite)
+ , m_format(QShaderImage::NoFormat)
+{
+}
+
+void ShaderImage::cleanup()
+{
+ QBackendNode::setEnabled(false);
+ m_textureId = Qt3DCore::QNodeId();
+ m_mipLevel = 0;
+ m_layer = 0;
+ m_layered = false;
+ m_access = QShaderImage::ReadWrite;
+ m_format = QShaderImage::NoFormat;
+}
+
+void ShaderImage::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e)
+{
+ Qt3DCore::QPropertyUpdatedChangePtr propertyChange = qSharedPointerCast<Qt3DCore::QPropertyUpdatedChange>(e);
+ if (e->type() == Qt3DCore::PropertyUpdated) {
+ if (propertyChange->propertyName() == QByteArrayLiteral("texture")) {
+ m_textureId = propertyChange->value().value<Qt3DCore::QNodeId>();
+ markDirty(AbstractRenderer::ParameterDirty);
+ } else if (propertyChange->propertyName() == QByteArrayLiteral("mipLevel")) {
+ m_mipLevel = propertyChange->value().toInt();
+ markDirty(AbstractRenderer::ParameterDirty);
+ } else if (propertyChange->propertyName() == QByteArrayLiteral("layer")) {
+ m_layer = propertyChange->value().toInt();
+ markDirty(AbstractRenderer::ParameterDirty);
+ } else if (propertyChange->propertyName() == QByteArrayLiteral("layered")) {
+ m_layered = propertyChange->value().toBool();
+ markDirty(AbstractRenderer::ParameterDirty);
+ } else if (propertyChange->propertyName() == QByteArrayLiteral("format")) {
+ m_format = propertyChange->value().value<QShaderImage::ImageFormat>();
+ markDirty(AbstractRenderer::ParameterDirty);
+ } else if (propertyChange->propertyName() == QByteArrayLiteral("access")) {
+ m_access = propertyChange->value().value<QShaderImage::Access>();
+ markDirty(AbstractRenderer::ParameterDirty);
+ }
+ }
+ BackendNode::sceneChangeEvent(e);
+}
+
+void ShaderImage::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change)
+{
+ const auto typedChange = qSharedPointerCast<Qt3DCore::QNodeCreatedChange<QShaderImageData>>(change);
+ const QShaderImageData &data = typedChange->data;
+
+ m_textureId = data.textureId;
+ m_mipLevel = data.mipLevel;
+ m_layer = data.layer;
+ m_layered = data.layered;
+ m_access = data.access;
+ m_format = data.format;
+}
+
+} // namespace Render
+
+} // namespace Qt3DRender
+
+QT_END_NAMESPACE
diff --git a/src/render/materialsystem/shaderimage_p.h b/src/render/materialsystem/shaderimage_p.h
new file mode 100644
index 000000000..6e4de4186
--- /dev/null
+++ b/src/render/materialsystem/shaderimage_p.h
@@ -0,0 +1,105 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and 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 QT3DRENDER_RENDER_SHADERIMAGE_P_H
+#define QT3DRENDER_RENDER_SHADERIMAGE_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <Qt3DRender/private/backendnode_p.h>
+#include <Qt3DRender/qshaderimage.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DRender {
+
+namespace Render {
+
+class Q_AUTOTEST_EXPORT ShaderImage : public BackendNode
+{
+public:
+ ShaderImage();
+
+ void cleanup();
+ void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) override;
+
+ Qt3DCore::QNodeId textureId() const { return m_textureId; }
+ int mipLevel() const { return m_mipLevel; }
+ int layer() const { return m_layer; }
+ bool layered() const { return m_layered; }
+ QShaderImage::Access access() const { return m_access; }
+ QShaderImage::ImageFormat format() const { return m_format; }
+
+ // For Unit Test purposes only
+#ifdef QT_BUILD_INTERNAL
+ void setTextureId(Qt3DCore::QNodeId id) { m_textureId = id; }
+ void setMipLevel(int level) { m_mipLevel = level; }
+ void setLayer(int layer) { m_layer = layer; }
+ void setLayered(bool layered) { m_layered = layered; }
+ void setAccess(QShaderImage::Access access) { m_access = access; }
+ void setFormat(QShaderImage::ImageFormat format) { m_format = format; }
+#endif
+
+private:
+ void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) final;
+
+ Qt3DCore::QNodeId m_textureId;
+ int m_mipLevel;
+ int m_layer;
+ bool m_layered;
+ QShaderImage::Access m_access;
+ QShaderImage::ImageFormat m_format;
+};
+
+} // namespace Render
+
+} // namespace Qt3DRender
+
+QT_END_NAMESPACE
+
+#endif // QT3DRENDER_RENDER_SHADERIMAGE_P_H