diff options
author | Juan Jose Casafranca <juan.casafranca@kdab.com> | 2018-07-16 11:33:24 +0200 |
---|---|---|
committer | Juan José Casafranca <juan.casafranca@kdab.com> | 2019-02-12 11:20:48 +0000 |
commit | 22d24c182687ef4334582d5e35744388a7f00f53 (patch) | |
tree | 2a8fa3d9b30671ca5fa81b68f6ae737bfd97da81 /src/render/renderstates | |
parent | 6e0a8452d6b37175b53394a31af5b32aa05c7285 (diff) |
Add QRasterMode render state
QRasterMode allows a user to change the raster mode from fill to lines or points
Change-Id: If96848e38ac4b5a615040b3bae2dec38a03cb031
Reviewed-by: Kevin Ottens <kevin.ottens@kdab.com>
Diffstat (limited to 'src/render/renderstates')
-rw-r--r-- | src/render/renderstates/qrastermode.cpp | 95 | ||||
-rw-r--r-- | src/render/renderstates/qrastermode.h | 96 | ||||
-rw-r--r-- | src/render/renderstates/qrastermode_p.h | 84 | ||||
-rw-r--r-- | src/render/renderstates/renderstatenode.cpp | 8 | ||||
-rw-r--r-- | src/render/renderstates/renderstates.cpp | 6 | ||||
-rw-r--r-- | src/render/renderstates/renderstates.pri | 7 | ||||
-rw-r--r-- | src/render/renderstates/renderstates_p.h | 6 | ||||
-rw-r--r-- | src/render/renderstates/statemask_p.h | 1 | ||||
-rw-r--r-- | src/render/renderstates/statevariant.cpp | 2 |
9 files changed, 303 insertions, 2 deletions
diff --git a/src/render/renderstates/qrastermode.cpp b/src/render/renderstates/qrastermode.cpp new file mode 100644 index 000000000..065a1ca8c --- /dev/null +++ b/src/render/renderstates/qrastermode.cpp @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** Copyright (C) 2018 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 "qrastermode.h" +#include "qrastermode_p.h" +#include <Qt3DRender/private/qrenderstatecreatedchange_p.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +QRasterMode::QRasterMode(QNode *parent) + : QRenderState(*new QRasterModePrivate, parent) +{ +} + +QRasterMode::RasterMode QRasterMode::rasterMode() const +{ + Q_D(const QRasterMode); + return d->m_rasterMode; +} + +QRasterMode::FaceMode QRasterMode::faceMode() const +{ + Q_D(const QRasterMode); + return d->m_faceMode; +} + +void QRasterMode::setRasterMode(QRasterMode::RasterMode rasterMode) +{ + Q_D(QRasterMode); + if (d->m_rasterMode != rasterMode) { + d->m_rasterMode = rasterMode; + emit rasterModeChanged(rasterMode); + } +} + +void QRasterMode::setFaceMode(QRasterMode::FaceMode faceMode) +{ + Q_D(QRasterMode); + if (d->m_faceMode != faceMode) { + d->m_faceMode = faceMode; + emit faceModeChanged(faceMode); + } +} + +Qt3DCore::QNodeCreatedChangeBasePtr QRasterMode::createNodeCreationChange() const +{ + auto creationChange = QRenderStateCreatedChangePtr<QRasterModeData>::create(this); + auto &data = creationChange->data; + Q_D(const QRasterMode); + data.rasterMode = d->m_rasterMode; + data.faceMode = d->m_faceMode; + return creationChange; +} + +} // namespace Qt3DRender + +QT_END_NAMESPACE diff --git a/src/render/renderstates/qrastermode.h b/src/render/renderstates/qrastermode.h new file mode 100644 index 000000000..9448a6932 --- /dev/null +++ b/src/render/renderstates/qrastermode.h @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** Copyright (C) 2018 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_QRASTERMODE_H +#define QT3DRENDER_QRASTERMODE_H + +#include <Qt3DRender/qrenderstate.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QRasterModePrivate; + +class QT3DRENDERSHARED_EXPORT QRasterMode : public QRenderState +{ + Q_OBJECT + Q_PROPERTY(RasterMode rasterMode READ rasterMode WRITE setRasterMode NOTIFY rasterModeChanged) + Q_PROPERTY(FaceMode faceMode READ faceMode WRITE setFaceMode NOTIFY faceModeChanged) +public: + + enum RasterMode { + Points = 0x1B00, + Lines = 0x1B01, + Fill = 0x1B02, + }; + Q_ENUM(RasterMode) // LCOV_EXCL_LINE + + enum FaceMode + { + Front = 0x0404, + Back = 0x0405, + FrontAndBack = 0x0408 + }; + Q_ENUM(FaceMode) // LCOV_EXCL_LINE + + explicit QRasterMode(Qt3DCore::QNode *parent = nullptr); + ~QRasterMode() = default; + + RasterMode rasterMode() const; + FaceMode faceMode() const; + +public Q_SLOTS: + void setRasterMode(RasterMode rasterMode); + void setFaceMode(FaceMode faceMode); + +Q_SIGNALS: + void rasterModeChanged(RasterMode rasterMode); + void faceModeChanged(FaceMode faceMode); + +private: + Q_DECLARE_PRIVATE(QRasterMode) + Qt3DCore::QNodeCreatedChangeBasePtr createNodeCreationChange() const override; +}; + +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_QRASTERMODE_H diff --git a/src/render/renderstates/qrastermode_p.h b/src/render/renderstates/qrastermode_p.h new file mode 100644 index 000000000..506689f02 --- /dev/null +++ b/src/render/renderstates/qrastermode_p.h @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2018 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_QRASTERMODE_P_H +#define QT3DRENDER_QRASTERMODE_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/qrenderstate_p.h> +#include <Qt3DRender/qrastermode.h> +#include <Qt3DRender/private/qt3drender_global_p.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QT3DRENDERSHARED_PRIVATE_EXPORT QRasterModePrivate : public QRenderStatePrivate +{ +public : + QRasterModePrivate() + : QRenderStatePrivate(Render::RasterModeMask) + , m_rasterMode(QRasterMode::Fill) + , m_faceMode(QRasterMode::FrontAndBack) + { + } + + Q_DECLARE_PUBLIC(QRasterMode) + QRasterMode::RasterMode m_rasterMode; + QRasterMode::FaceMode m_faceMode; +}; + +struct QRasterModeData +{ + QRasterMode::FaceMode faceMode; + QRasterMode::RasterMode rasterMode; +}; + +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_QRASTERMODE_P_H diff --git a/src/render/renderstates/renderstatenode.cpp b/src/render/renderstates/renderstatenode.cpp index 1cab44218..f83640154 100644 --- a/src/render/renderstates/renderstatenode.cpp +++ b/src/render/renderstates/renderstatenode.cpp @@ -55,6 +55,8 @@ #include <Qt3DRender/private/qdepthrange_p.h> #include <Qt3DRender/qdepthtest.h> #include <Qt3DRender/private/qdepthtest_p.h> +#include <Qt3DRender/qrastermode.h> +#include <Qt3DRender/private/qrastermode_p.h> #include <Qt3DRender/qdithering.h> #include <Qt3DRender/qfrontface.h> #include <Qt3DRender/private/qfrontface_p.h> @@ -144,6 +146,12 @@ StateVariant createStateImplementation(const Qt3DRender::QRenderStateCreatedChan return StateVariant::createState<DepthTest>(data.depthFunction); } + case RasterModeMask: { + const auto typedChange = qSharedPointerCast<Qt3DRender::QRenderStateCreatedChange<QRasterModeData>>(renderStateChange); + const auto &data = typedChange->data; + return StateVariant::createState<RasterMode>(data.faceMode, data.rasterMode); + } + case FrontFaceStateMask: { const auto typedChange = qSharedPointerCast<Qt3DRender::QRenderStateCreatedChange<QFrontFaceData>>(renderStateChange); const auto &data = typedChange->data; diff --git a/src/render/renderstates/renderstates.cpp b/src/render/renderstates/renderstates.cpp index c954d9d2c..77143ecd3 100644 --- a/src/render/renderstates/renderstates.cpp +++ b/src/render/renderstates/renderstates.cpp @@ -100,6 +100,12 @@ void DepthTest::updateProperty(const char *name, const QVariant &value) if (name == QByteArrayLiteral("depthFunction")) std::get<0>(m_values) = value.toInt(); } +void RasterMode::updateProperty(const char *name, const QVariant &value) +{ + if (name == QByteArrayLiteral("rasterMode")) std::get<0>(m_values) = value.toInt(); + if (name == QByteArrayLiteral("faceMode")) std::get<1>(m_values) = value.toInt(); +} + void CullFace::updateProperty(const char *name, const QVariant &value) { if (name == QByteArrayLiteral("mode")) std::get<0>(m_values) = value.toInt(); diff --git a/src/render/renderstates/renderstates.pri b/src/render/renderstates/renderstates.pri index b084a8759..06ba53a41 100644 --- a/src/render/renderstates/renderstates.pri +++ b/src/render/renderstates/renderstates.pri @@ -49,7 +49,9 @@ HEADERS += \ $$PWD/renderstatenode_p.h \ $$PWD/qmultisampleantialiasing.h \ $$PWD/statemask_p.h \ - $$PWD/statevariant_p.h + $$PWD/statevariant_p.h \ + $$PWD/qrastermode.h \ + $$PWD/qrastermode_p.h SOURCES += \ $$PWD/qalphacoverage.cpp \ @@ -79,4 +81,5 @@ SOURCES += \ $$PWD/qrenderstatecreatedchange.cpp \ $$PWD/renderstatenode.cpp \ $$PWD/statevariant.cpp \ - $$PWD/qmultisampleantialiasing.cpp + $$PWD/qmultisampleantialiasing.cpp \ + $$PWD/qrastermode.cpp diff --git a/src/render/renderstates/renderstates_p.h b/src/render/renderstates/renderstates_p.h index e769be2a4..7c6dc4ebd 100644 --- a/src/render/renderstates/renderstates_p.h +++ b/src/render/renderstates/renderstates_p.h @@ -95,6 +95,12 @@ public: void updateProperty(const char *name, const QVariant &value) override; }; +class Q_AUTOTEST_EXPORT RasterMode : public GenericState<RasterMode, RasterModeMask, GLenum, GLenum> +{ +public: + void updateProperty(const char *name, const QVariant &value) override; +}; + class Q_AUTOTEST_EXPORT NoDepthMask : public GenericState<NoDepthMask, DepthWriteStateMask, GLboolean> { public: diff --git a/src/render/renderstates/statemask_p.h b/src/render/renderstates/statemask_p.h index 6920a7d5b..ca64e30cd 100644 --- a/src/render/renderstates/statemask_p.h +++ b/src/render/renderstates/statemask_p.h @@ -82,6 +82,7 @@ enum StateMask BlendEquationArgumentsMask = 1 << 18, LineWidthMask = 1 << 19, DepthRangeMask = 1 << 20, + RasterModeMask = 1 << 21 }; } // namespace Render diff --git a/src/render/renderstates/statevariant.cpp b/src/render/renderstates/statevariant.cpp index 09c800470..47b3fd0a7 100644 --- a/src/render/renderstates/statevariant.cpp +++ b/src/render/renderstates/statevariant.cpp @@ -68,6 +68,7 @@ RenderStateImpl *StateVariant::state() case StencilOpMask: case StencilWriteStateMask: case LineWidthMask: + case RasterModeMask: return &data.blendEquationArguments; default: Q_UNREACHABLE(); @@ -98,6 +99,7 @@ const RenderStateImpl *StateVariant::constState() const case StencilOpMask: case StencilWriteStateMask: case LineWidthMask: + case RasterModeMask: return &data.blendEquationArguments; default: Q_UNREACHABLE(); |