summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2015-07-31 11:54:16 +0200
committerSean Harmer <sean.harmer@kdab.com>2015-08-07 00:11:58 +0000
commitda85992ea6fd990816ccbad6fcfff8d5d9d00416 (patch)
treee13e08b03374784ce24e0594022717b30ede239d /src
parent882211b3b8830a0a0c0639f16d5d95cc212d878f (diff)
RenderAttribute: backend class for QAttribute
Change-Id: I7761533652933f1f11b808ce735b4be4687846ce Reviewed-by: Paul Lemire <paul.lemire@kdab.com> Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src')
-rw-r--r--src/render/backend/render-backend.pri6
-rw-r--r--src/render/backend/renderattribute.cpp156
-rw-r--r--src/render/backend/renderattribute_p.h89
3 files changed, 249 insertions, 2 deletions
diff --git a/src/render/backend/render-backend.pri b/src/render/backend/render-backend.pri
index fad104e48..20450cb25 100644
--- a/src/render/backend/render-backend.pri
+++ b/src/render/backend/render-backend.pri
@@ -52,7 +52,8 @@ HEADERS += \
$$PWD/renderparametermapping_p.h \
$$PWD/rendertextureimage_p.h \
$$PWD/vsyncframeadvanceservice_p.h \
- $$PWD/renderbuffer_p.h
+ $$PWD/renderbuffer_p.h \
+ $$PWD/renderattribute_p.h
SOURCES += \
$$PWD/qrenderaspect.cpp \
@@ -95,4 +96,5 @@ SOURCES += \
$$PWD/renderparametermapping.cpp \
$$PWD/rendertextureimage.cpp \
$$PWD/vsyncframeadvanceservice.cpp \
- $$PWD/renderbuffer.cpp
+ $$PWD/renderbuffer.cpp \
+ $$PWD/renderattribute.cpp
diff --git a/src/render/backend/renderattribute.cpp b/src/render/backend/renderattribute.cpp
new file mode 100644
index 000000000..a8435c5bc
--- /dev/null
+++ b/src/render/backend/renderattribute.cpp
@@ -0,0 +1,156 @@
+/****************************************************************************
+**
+** 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 "renderattribute_p.h"
+#include <Qt3DCore/qscenepropertychange.h>
+#include <Qt3DRenderer/qbuffer.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+namespace Render {
+
+RenderAttribute::RenderAttribute()
+ : QBackendNode(ReadOnly)
+ , m_type(0)
+ , m_count(0)
+ , m_byteStride(0)
+ , m_byteOffset(0)
+ , m_divisor(0)
+ , m_attributeType(QAbstractAttribute::VertexAttribute)
+ , m_attributeDirty(false)
+{
+}
+
+RenderAttribute::~RenderAttribute()
+{
+}
+
+void RenderAttribute::cleanup()
+{
+ m_type = 0;
+ m_count = 0;
+ m_byteStride = 0;
+ m_byteOffset = 0;
+ m_divisor = 0;
+ m_attributeType = QAbstractAttribute::VertexAttribute;
+ m_bufferId = QNodeId();
+ m_name.clear();
+ m_attributeDirty = false;
+}
+
+void RenderAttribute::updateFromPeer(QNode *peer)
+{
+ QAttribute *attribute = static_cast<QAttribute *>(peer);
+ if (attribute) {
+ m_type = attribute->type();
+ m_count = attribute->count();
+ m_byteOffset = attribute->byteOffset();
+ m_byteStride = attribute->byteStride();
+ m_divisor = attribute->divisor();
+ m_attributeType = attribute->attributeType();
+ m_name = attribute->name();
+ if (attribute->buffer())
+ m_bufferId = attribute->buffer()->id();
+ m_attributeDirty = true;
+ }
+}
+
+void RenderAttribute::sceneChangeEvent(const QSceneChangePtr &e)
+{
+ QScenePropertyChangePtr propertyChange = qSharedPointerCast<QScenePropertyChange>(e);
+ QByteArray propertyName = propertyChange->propertyName();
+
+ switch (e->type()) {
+
+ case NodeUpdated: {
+ if (propertyName == QByteArrayLiteral("name")) {
+ m_name = propertyChange->value().value<QString>();
+ m_attributeDirty = true;
+ } else if (propertyName == QByteArrayLiteral("type")) {
+ m_type = propertyChange->value().value<int>();
+ m_attributeDirty = true;
+ } else if (propertyName == QByteArrayLiteral("count")) {
+ m_count = propertyChange->value().value<uint>();
+ m_attributeDirty = true;
+ } else if (propertyName == QByteArrayLiteral("byteStride")) {
+ m_byteStride = propertyChange->value().value<uint>();
+ m_attributeDirty = true;
+ } else if (propertyName == QByteArrayLiteral("byteOffset")) {
+ m_byteOffset = propertyChange->value().value<uint>();
+ m_attributeDirty = true;
+ } else if (propertyName == QByteArrayLiteral("divisor")) {
+ m_divisor = propertyChange->value().value<uint>();
+ m_attributeDirty = true;
+ } else if (propertyName == QByteArrayLiteral("attributeType")) {
+ m_attributeType = static_cast<QAbstractAttribute::AttributeType>(propertyChange->value().value<int>());
+ m_attributeDirty = true;
+ }
+ break;
+ }
+
+ case NodeAdded: {
+ if (propertyName == QByteArrayLiteral("buffer")) {
+ m_bufferId = propertyChange->value().value<QNodeId>();
+ m_attributeDirty = true;
+ }
+ break;
+ }
+
+ case NodeRemoved: {
+ if (propertyName == QByteArrayLiteral("buffer")) {
+ m_bufferId = QNodeId();
+ m_attributeDirty = true;
+ }
+ break;
+ }
+
+ default:
+ break;
+ }
+}
+
+void RenderAttribute::unsetDirty()
+{
+ m_attributeDirty = false;
+}
+
+} // Render
+
+} // Qt3D
+
+QT_END_NAMESPACE
diff --git a/src/render/backend/renderattribute_p.h b/src/render/backend/renderattribute_p.h
new file mode 100644
index 000000000..0cf19d593
--- /dev/null
+++ b/src/render/backend/renderattribute_p.h
@@ -0,0 +1,89 @@
+/****************************************************************************
+**
+** 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 QT3D_RENDER_RENDERATTRIBUTE_H
+#define QT3D_RENDER_RENDERATTRIBUTE_H
+
+#include <Qt3DCore/qbackendnode.h>
+#include <Qt3DRenderer/qattribute.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3D {
+
+namespace Render {
+
+class Q_AUTOTEST_EXPORT RenderAttribute : public QBackendNode
+{
+public:
+ RenderAttribute();
+ ~RenderAttribute();
+
+ void cleanup();
+
+ void updateFromPeer(QNode *peer) Q_DECL_OVERRIDE;
+ void sceneChangeEvent(const QSceneChangePtr &e) Q_DECL_OVERRIDE;
+
+ inline QNodeId bufferId() const { return m_bufferId; }
+ inline QString name() const { return m_name; }
+ inline int type() const { return m_type; }
+ inline uint count() const { return m_count; }
+ inline uint byteStride() const { return m_byteStride; }
+ inline uint byteOffset() const { return m_byteOffset; }
+ inline uint divisor() const { return m_divisor; }
+ inline QAbstractAttribute::AttributeType attributeType() const { return m_attributeType; }
+ inline bool isDirty() const { return m_attributeDirty; }
+ void unsetDirty();
+
+private:
+ QNodeId m_bufferId;
+ QString m_name;
+ int m_type;
+ uint m_count;
+ uint m_byteStride;
+ uint m_byteOffset;
+ uint m_divisor;
+ QAbstractAttribute::AttributeType m_attributeType;
+ bool m_attributeDirty;
+};
+
+} // Render
+
+} // Qt3D
+
+QT_END_NAMESPACE
+
+#endif // QT3D_RENDER_RENDERATTRIBUTE_H