diff options
author | Paul Lemire <paul.lemire@kdab.com> | 2015-03-13 15:17:56 +0100 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2015-04-25 08:05:03 +0000 |
commit | efa3b6e45170274469d5382f3a8cd96ed05c24a8 (patch) | |
tree | 63427ce4a74bb6392e26d5f39c21756d30a48a6c | |
parent | 820227da88ef52ab8ab4337e66029ba4b0915913 (diff) |
Quick3DStateSet extension classes for QML of QStateSet
QStateSet,Quick3DStateSet registered as an extended object under the StateSet
name.
Change-Id: I4334958ab55e403c532f3c200eb273925403dcb5
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
4 files changed, 182 insertions, 2 deletions
diff --git a/src/quick3d/imports/render/qt3dquick3drenderplugin.cpp b/src/quick3d/imports/render/qt3dquick3drenderplugin.cpp index 0a1250f75..4e40686ed 100644 --- a/src/quick3d/imports/render/qt3dquick3drenderplugin.cpp +++ b/src/quick3d/imports/render/qt3dquick3drenderplugin.cpp @@ -101,6 +101,7 @@ #include <Qt3DQuickRenderer/quick3dparameter.h> #include <Qt3DQuickRenderer/quick3dshaderdata.h> #include <Qt3DQuickRenderer/quick3dshaderdataarray.h> +#include <Qt3DQuickRenderer/quick3dstateset.h> static void initResources() { @@ -203,6 +204,7 @@ void Qt3DQuick3DRenderPlugin::registerTypes(const char *uri) qmlRegisterType<Qt3D::QRenderTargetSelector>(uri, 2, 0, "RenderTargetSelector"); qmlRegisterType<Qt3D::QClearBuffer>(uri, 2, 0, "ClearBuffer"); qmlRegisterExtendedUncreatableType<Qt3D::QFrameGraphNode, Qt3D::Render::Quick::Quick3DFrameGraphItem>(uri, 2, 0, "FrameGraphNode", QStringLiteral("FrameGraphNode is a base class")); + qmlRegisterExtendedType<Qt3D::QStateSet, Qt3D::Render::Quick::Quick3DStateSet>(uri, 2, 0, "StateSet"); qmlRegisterType<Qt3D::QFrameGraph>(uri, 2, 0, "FrameGraph"); // RenderTarget diff --git a/src/quick3d/quick3drenderer/items/items.pri b/src/quick3d/quick3drenderer/items/items.pri index b3b1c742a..6d4c905fd 100644 --- a/src/quick3d/quick3drenderer/items/items.pri +++ b/src/quick3d/quick3drenderer/items/items.pri @@ -15,7 +15,8 @@ HEADERS += \ $$PWD/quick3dparameter_p.h \ $$PWD/quick3dparameter.h \ $$PWD/quick3dshaderdata.h \ - $$PWD/quick3dshaderdataarray.h + $$PWD/quick3dshaderdataarray.h \ + $$PWD/quick3dstateset.h SOURCES += \ $$PWD/quick3drenderpassfilter.cpp \ @@ -33,6 +34,7 @@ SOURCES += \ $$PWD/quick3dsortmethod.cpp \ $$PWD/quick3dparameter.cpp \ $$PWD/quick3dshaderdata.cpp \ - $$PWD/quick3dshaderdataarray.cpp + $$PWD/quick3dshaderdataarray.cpp \ + $$PWD/quick3dstateset.cpp INCLUDEPATH += $$PWD diff --git a/src/quick3d/quick3drenderer/items/quick3dstateset.cpp b/src/quick3d/quick3drenderer/items/quick3dstateset.cpp new file mode 100644 index 000000000..fe51cb495 --- /dev/null +++ b/src/quick3d/quick3drenderer/items/quick3dstateset.cpp @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** 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 "quick3dstateset.h" + +QT_BEGIN_NAMESPACE + +namespace Qt3D { + +namespace Render { + +namespace Quick { + +Quick3DStateSet::Quick3DStateSet(QObject *parent) + : QObject(parent) +{ +} + +Quick3DStateSet::~Quick3DStateSet() +{ +} + +QQmlListProperty<QRenderState> Quick3DStateSet::renderStateList() +{ + return QQmlListProperty<Qt3D::QRenderState>(this, 0, + &Quick3DStateSet::appendRenderState, + &Quick3DStateSet::renderStateCount, + &Quick3DStateSet::renderStateAt, + &Quick3DStateSet::clearRenderStates); + +} + +void Quick3DStateSet::appendRenderState(QQmlListProperty<QRenderState> *list, QRenderState *state) +{ + Quick3DStateSet *stateSet = qobject_cast<Quick3DStateSet *>(list->object); + stateSet->parentStateSet()->addRenderState(state); +} + +QRenderState *Quick3DStateSet::renderStateAt(QQmlListProperty<QRenderState> *list, int index) +{ + Quick3DStateSet *stateSet = qobject_cast<Quick3DStateSet *>(list->object); + return stateSet->parentStateSet()->renderStates().at(index); +} + +int Quick3DStateSet::renderStateCount(QQmlListProperty<QRenderState> *list) +{ + Quick3DStateSet *stateSet = qobject_cast<Quick3DStateSet *>(list->object); + return stateSet->parentStateSet()->renderStates().count(); +} + +void Quick3DStateSet::clearRenderStates(QQmlListProperty<QRenderState> *list) +{ + Quick3DStateSet *stateSet = qobject_cast<Quick3DStateSet *>(list->object); + Q_FOREACH (QRenderState *s, stateSet->parentStateSet()->renderStates()) + stateSet->parentStateSet()->removeRenderState(s); +} + +} // Quick + +} // Render + +} // Qt3D + +QT_END_NAMESPACE + diff --git a/src/quick3d/quick3drenderer/items/quick3dstateset.h b/src/quick3d/quick3drenderer/items/quick3dstateset.h new file mode 100644 index 000000000..6a352b21a --- /dev/null +++ b/src/quick3d/quick3drenderer/items/quick3dstateset.h @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** 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_QUICK_QUICK3DSTATESET_H +#define QT3D_RENDER_QUICK_QUICK3DSTATESET_H + +#include <Qt3DQuickRenderer/qt3dquickrenderer_global.h> +#include <Qt3DRenderer/qstateset.h> +#include <QQmlListProperty> + +QT_BEGIN_NAMESPACE + +namespace Qt3D { + +namespace Render { + +namespace Quick { + +class QT3DQUICKRENDERERSHARED_EXPORT Quick3DStateSet : public QObject +{ + Q_OBJECT + Q_PROPERTY(QQmlListProperty<Qt3D::QRenderState> renderStates READ renderStateList CONSTANT) +public: + explicit Quick3DStateSet(QObject *parent = 0); + ~Quick3DStateSet(); + + QQmlListProperty<Qt3D::QRenderState> renderStateList(); + inline QStateSet *parentStateSet() const { return qobject_cast<QStateSet *>(parent()); } + +private: + static void appendRenderState(QQmlListProperty<Qt3D::QRenderState> *list, QRenderState *state); + static QRenderState *renderStateAt(QQmlListProperty<Qt3D::QRenderState> *list, int index); + static int renderStateCount(QQmlListProperty<Qt3D::QRenderState> *list); + static void clearRenderStates(QQmlListProperty<Qt3D::QRenderState> *list); +}; + +} // Quick + +} // Render + +} // Qt3D + +QT_END_NAMESPACE + +#endif // QT3D_RENDER_QUICK_QUICK3DSTATESET_H |