diff options
author | Sean Harmer <sean.harmer@kdab.com> | 2015-09-18 14:13:26 +0100 |
---|---|---|
committer | Paul Lemire <paul.lemire@kdab.com> | 2015-10-13 12:12:52 +0000 |
commit | 9847869acceedab58db4862ebeebb74016eaaf23 (patch) | |
tree | 87bfd89663e23335c61fac03501d666cb4812eac /src/render/renderstates | |
parent | b1810f91ee5eaa3ae9e79efde6b4a0335738c3e8 (diff) |
Move render state classes into own dir and tidy up
Change-Id: I0829c42283d6a25e9b3ec623f45739ea266718cf
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src/render/renderstates')
45 files changed, 5168 insertions, 0 deletions
diff --git a/src/render/renderstates/genericstate_p.h b/src/render/renderstates/genericstate_p.h new file mode 100644 index 000000000..7fc5a4391 --- /dev/null +++ b/src/render/renderstates/genericstate_p.h @@ -0,0 +1,189 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies). +** 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_RENDER_GENERICSTATE_H +#define QT3DRENDER_RENDER_GENERICSTATE_H + +#include <QList> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QRenderState; + +namespace Render { + +class GraphicsContext; + +enum StateMask +{ + BlendStateMask = 1 << 0, + StencilWriteStateMask = 1 << 1, + StencilTestStateMask = 1 << 2, + ScissorStateMask = 1 << 3, + DepthTestStateMask = 1 << 4, + DepthWriteStateMask = 1 << 5, + CullFaceStateMask = 1 << 6, + AlphaTestMask = 1 << 7, + FrontFaceStateMask = 1 << 8, + DitheringStateMask = 1 << 9, + AlphaCoverageStateMask = 1 << 10, + PolygonOffsetStateMask = 1 << 11, + ColorStateMask = 1 << 12, + ClipPlaneMask = 1 << 13, + StencilOpMask = 1 << 14 +}; + +typedef quint64 StateMaskSet; + +class Q_AUTOTEST_EXPORT RenderState +{ +public: + virtual ~RenderState() {} + virtual void apply(GraphicsContext* gc) const = 0; + virtual StateMaskSet mask() const = 0; + + static RenderState *getOrCreateBackendState(QRenderState *renderState); +}; + +template <typename Derived, typename T> +class GenericState1 : public RenderState +{ +public: + + bool isEqual(const Derived& i) const + { return (m_1 == i.m_1); } + + +protected: + GenericState1(T t) : + m_1(t) + {} + + T m_1; + +}; + +template <typename Derived, typename T, typename S> +class GenericState2 : public RenderState +{ +public: + bool isEqual(const Derived& i) const + { return (m_1 == i.m_1) && (m_2 == i.m_2); } +protected: + GenericState2(T t, S s) : + m_1(t), + m_2(s) + {} + + + T m_1; + S m_2; +}; + +template <typename Derived, typename T, typename S, typename U> +class GenericState3 : public RenderState +{ +public: + bool isEqual(const Derived& i) const + { return (m_1 == i.m_1) && (m_2 == i.m_2) && (m_3 == i.m_3); } + +protected: + GenericState3(T t, S s, U u) : + m_1(t), + m_2(s), + m_3(u) + {} + + T m_1; + S m_2; + U m_3; +}; + +template <typename Derived, typename T, typename S, typename U, typename Z> +class GenericState4 : public RenderState +{ +public: + bool isEqual(const Derived& i) const + { return (m_1 == i.m_1) && (m_2 == i.m_2) && (m_3 == i.m_3) && (m_4 == i.m_4); } + +protected: + GenericState4(T t, S s, U u, Z z) : + m_1(t), + m_2(s), + m_3(u), + m_4(z) + {} + + T m_1; + S m_2; + U m_3; + Z m_4; +}; + +template <typename Derived, typename T, typename S, typename U, typename V, typename W, typename Z> +class GenericState6 : public RenderState +{ +public: + bool isEqual(const Derived& i) const + { return (m_1 == i.m_1) && (m_2 == i.m_2) && (m_3 == i.m_3) && (m_4 == i.m_4) && (m_5 == i.m_5) && (m_6 == i.m_6); } + +protected: + GenericState6(T t, S s, U u, V v, W w, Z z) + : m_1(t) + , m_2(s) + , m_3(u) + , m_4(v) + , m_5(w) + , m_6(z) + {} + + T m_1; + S m_2; + U m_3; + V m_4; + W m_5; + Z m_6; +}; + +} // namespace Render +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_RENDER_GENERICSTATE_H diff --git a/src/render/renderstates/qalphacoverage.cpp b/src/render/renderstates/qalphacoverage.cpp new file mode 100644 index 000000000..7a8fea6bb --- /dev/null +++ b/src/render/renderstates/qalphacoverage.cpp @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies). +** 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 "qalphacoverage.h" +#include "qrenderstate_p.h" + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QAlphaCoveragePrivate : public QRenderStatePrivate +{ +public : + QAlphaCoveragePrivate() + : QRenderStatePrivate(QRenderState::AlphaCoverage) + {} + + Q_DECLARE_PUBLIC(QAlphaCoverage) +}; + +QAlphaCoverage::QAlphaCoverage(QNode *parent) + : QRenderState(*new QAlphaCoveragePrivate, parent) +{ +} + +QAlphaCoverage::~QAlphaCoverage() +{ + QNode::cleanup(); +} + +} // namespace Qt3DRender + +QT_END_NAMESPACE diff --git a/src/render/renderstates/qalphacoverage.h b/src/render/renderstates/qalphacoverage.h new file mode 100644 index 000000000..753b28919 --- /dev/null +++ b/src/render/renderstates/qalphacoverage.h @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies). +** 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_QALPHACOVERAGE_H +#define QT3DRENDER_QALPHACOVERAGE_H + +#include <Qt3DRenderer/qrenderstate.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QAlphaCoveragePrivate; + +class QT3DRENDERERSHARED_EXPORT QAlphaCoverage : public QRenderState +{ + Q_OBJECT +public: + explicit QAlphaCoverage(Qt3D::QNode *parent = 0); + ~QAlphaCoverage(); + +private: + Q_DECLARE_PRIVATE(QAlphaCoverage) + QT3D_CLONEABLE(QAlphaCoverage) +}; + +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_QALPHACOVERAGE_H diff --git a/src/render/renderstates/qalphatest.cpp b/src/render/renderstates/qalphatest.cpp new file mode 100644 index 000000000..34071c52d --- /dev/null +++ b/src/render/renderstates/qalphatest.cpp @@ -0,0 +1,112 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies). +** 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 "qalphatest.h" +#include "qrenderstate_p.h" +#include <private/qnode_p.h> +#include <Qt3DCore/qscenepropertychange.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QAlphaTestPrivate : public QRenderStatePrivate +{ +public: + QAlphaTestPrivate() + : QRenderStatePrivate(QRenderState::AlphaTest) + , m_func(QAlphaTest::Never) + , m_clamp(0.0f) + { + } + + Q_DECLARE_PUBLIC(QAlphaTest) + QAlphaTest::AlphaFunc m_func; + float m_clamp; +}; + +QAlphaTest::QAlphaTest(QNode *parent) + : QRenderState(*new QAlphaTestPrivate, parent) +{ +} + +QAlphaTest::~QAlphaTest() +{ + QNode::cleanup(); +} + +void QAlphaTest::copy(const QNode *ref) +{ + QRenderState::copy(ref); + const QAlphaTest *refState = static_cast<const QAlphaTest*>(ref); + d_func()->m_func = refState->d_func()->m_func; + d_func()->m_clamp = refState->d_func()->m_clamp; +} + +QAlphaTest::AlphaFunc QAlphaTest::func() const +{ + Q_D(const QAlphaTest); + return d->m_func; +} + +void QAlphaTest::setFunc(QAlphaTest::AlphaFunc func) +{ + Q_D(QAlphaTest); + if (d->m_func != func) { + d->m_func = func; + emit funcChanged(); + } +} + +float QAlphaTest::clamp() const +{ + Q_D(const QAlphaTest); + return d->m_clamp; +} + +void QAlphaTest::setClamp(float clamp) +{ + Q_D(QAlphaTest); + if (d->m_clamp != clamp) { + d->m_clamp = clamp; + emit clampChanged(); + } +} + +} // namespace Qt3DRender + +QT_END_NAMESPACE diff --git a/src/render/renderstates/qalphatest.h b/src/render/renderstates/qalphatest.h new file mode 100644 index 000000000..d59340ec7 --- /dev/null +++ b/src/render/renderstates/qalphatest.h @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies). +** 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_QALPHATEST_H +#define QT3DRENDER_QALPHATEST_H + +#include <Qt3DRenderer/qrenderstate.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QAlphaTestPrivate; + +class QT3DRENDERERSHARED_EXPORT QAlphaTest : public QRenderState +{ + Q_OBJECT + Q_PROPERTY(AlphaFunc func READ func WRITE setFunc NOTIFY funcChanged) + Q_PROPERTY(float clamp READ clamp WRITE setClamp NOTIFY clampChanged) +public: + + enum AlphaFunc { + Never = 0x0200, + Always = 0x0207, + Less = 0x0201, + LessOrEqual = 0x0203, + Equal = 0x0202, + GreaterOrEqual = 0x0206, + Greater = 0x0204, + NotEqual = 0x0205 + }; + Q_ENUM(AlphaFunc) + + explicit QAlphaTest(Qt3D::QNode *parent = 0); + ~QAlphaTest(); + + AlphaFunc func() const; + void setFunc(AlphaFunc func); + + float clamp() const; + void setClamp(float clamp); + +Q_SIGNALS: + void funcChanged(); + void clampChanged(); + +protected: + void copy(const Qt3D::QNode *ref) Q_DECL_OVERRIDE; + +private: + Q_DECLARE_PRIVATE(QAlphaTest) + QT3D_CLONEABLE(QAlphaTest) +}; + +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_QALPHATEST_H diff --git a/src/render/renderstates/qblendequation.cpp b/src/render/renderstates/qblendequation.cpp new file mode 100644 index 000000000..bee40fc67 --- /dev/null +++ b/src/render/renderstates/qblendequation.cpp @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies). +** 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 "qrenderstate_p.h" +#include "qblendequation.h" +#include <private/qnode_p.h> +#include <Qt3DCore/qscenepropertychange.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QBlendEquationPrivate : public QRenderStatePrivate +{ +public: + QBlendEquationPrivate() + : QRenderStatePrivate(QRenderState::BlendEquation) + { + } + + Q_DECLARE_PUBLIC(QBlendEquation) + QBlendEquation::BlendMode m_mode; +}; + +void QBlendEquation::copy(const QNode *ref) +{ + QRenderState::copy(ref); + const QBlendEquation *refState = reinterpret_cast<const QBlendEquation*>(ref); + d_func()->m_mode = refState->d_func()->m_mode; +} + +QBlendEquation::QBlendEquation(QNode *parent) + : QRenderState(*new QBlendEquationPrivate, parent) +{ +} + +QBlendEquation::~QBlendEquation() +{ + QNode::cleanup(); +} + +QBlendEquation::BlendMode QBlendEquation::mode() const +{ + Q_D(const QBlendEquation); + return d->m_mode; +} + +void QBlendEquation::setMode(QBlendEquation::BlendMode mode) +{ + Q_D(QBlendEquation); + if (d->m_mode != mode) { + d->m_mode = mode; + emit modeChanged(); + } +} + +} // namespace Qt3DRender + +QT_END_NAMESPACE diff --git a/src/render/renderstates/qblendequation.h b/src/render/renderstates/qblendequation.h new file mode 100644 index 000000000..94735fdb6 --- /dev/null +++ b/src/render/renderstates/qblendequation.h @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies). +** 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_QBLENDEQUATION_H +#define QT3DRENDER_QBLENDEQUATION_H + +#include <Qt3DRenderer/qrenderstate.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QBlendEquationPrivate; + +class QT3DRENDERERSHARED_EXPORT QBlendEquation : public QRenderState +{ + Q_OBJECT + Q_PROPERTY(BlendMode mode READ mode WRITE setMode NOTIFY modeChanged) +public: + + enum BlendMode + { + FuncAdd = 0x8006, + FuncSubstract = 0x800A, + FuncReverseSubstract = 0x800B, + Min = 0x8007, + Max = 0x8008 + }; + Q_ENUM(BlendMode) + + explicit QBlendEquation(Qt3D::QNode *parent = 0); + ~QBlendEquation(); + + BlendMode mode() const; + void setMode(BlendMode mode); + +Q_SIGNALS: + void modeChanged(); + +protected: + void copy(const Qt3D::QNode *ref) Q_DECL_OVERRIDE; + +private: + Q_DECLARE_PRIVATE(QBlendEquation) + QT3D_CLONEABLE(QBlendEquation) +}; + +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_QBLENDEQUATION_H diff --git a/src/render/renderstates/qblendstate.cpp b/src/render/renderstates/qblendstate.cpp new file mode 100644 index 000000000..7f7a8d680 --- /dev/null +++ b/src/render/renderstates/qblendstate.cpp @@ -0,0 +1,265 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies). +** 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 "qblendstate.h" +#include "qrenderstate_p.h" +#include <Qt3DCore/qscenepropertychange.h> +#include <private/qnode_p.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QBlendStatePrivate : public QRenderStatePrivate +{ +public: + QBlendStatePrivate(QRenderState::Type type = QRenderState::BlendState) + : QRenderStatePrivate(type) + , m_srcRGB(QBlendState::Zero) + , m_srcAlpha(QBlendState::Zero) + , m_dstRGB(QBlendState::Zero) + , m_dstAlpha(QBlendState::Zero) + { + } + + Q_DECLARE_PUBLIC(QBlendState) + + QBlendState::Blending m_srcRGB; + QBlendState::Blending m_srcAlpha; + QBlendState::Blending m_dstRGB; + QBlendState::Blending m_dstAlpha; +}; + +/*! + \class Qt3D::QBlendState + \inmodule Qt3DRenderer + \since 5.5 + \brief Encapsulates blending information. + */ + +/*! + \qmltype BlendState + \instantiates Qt3D::QBlendState + \inherits RenderState + \inqmlmodule Qt3D.Renderer + \since 5.5 + \brief Encapsulates blending information +*/ + +/*! + The constructor creates a new blend state object with the specified \a parent. + */ +QBlendState::QBlendState(QNode *parent) + : QRenderState(*new QBlendStatePrivate, parent) +{ +} + +QBlendState::~QBlendState() +{ + QNode::cleanup(); +} + +/*! \fn void QBlendState::copy(const QNode *ref) + \internal + Copies \a ref into this object. + */ +void QBlendState::copy(const QNode *ref) +{ + QRenderState::copy(ref); + const QBlendState *refState = static_cast<const QBlendState*>(ref); + d_func()->m_srcRGB = refState->d_func()->m_srcRGB; + d_func()->m_srcAlpha = refState->d_func()->m_srcAlpha; + d_func()->m_dstAlpha = refState->d_func()->m_dstAlpha; + d_func()->m_dstRGB = refState->d_func()->m_dstRGB; +} + +/*! + \internal +*/ +QBlendState::QBlendState(QRenderState::Type type, QNode *parent) + : QRenderState(*new QBlendStatePrivate(type), parent) +{ +} + +/*! + \enum Qt3D::QBlendState::Blending + + \value Zero 0 + \value One 1 + \value SrcColor 0x0300 + \value SrcAlpha 0x0302 + \value Src1Alpha + \value Src1Color + \value DstColor 0x0306 + \value DstAlpha 0x0304 + \value SrcAlphaSaturate 0x0308 + \value ConstantColor 0x8001 + \value ConstantAlpha 0x8003 + \value OneMinusSrcColor 0x0301 + \value OneMinusSrcAlpha 0x0303 + \value OneMinusDstAlpha 0x0305 + \value OneMinusDstColor 0x0307 + \value OneMinusConstantColor 0x8002 + \value OneMinusConstantAlpha 0x8004 + \value OneMinusSrc1Alpha + \value OneMinusSrc1Color0 +*/ + +/*! + \qmlproperty enumeration Qt3D.render::BlendState::srcRGB + + */ + +/*! + \property Qt3D::QBlendState::srcRGB + + */ +QBlendState::Blending QBlendState::srcRGB() const +{ + Q_D(const QBlendState); + return d->m_srcRGB; +} + +void QBlendState::setSrcRGB(QBlendState::Blending srcRGB) +{ + Q_D(QBlendState); + if (d->m_srcRGB != srcRGB) { + d->m_srcRGB = srcRGB; + emit srcRGBChanged(); + } +} + +/*! + \qmlproperty enumeration Qt3D.render::BlendState::dstRGB + + */ + +/*! + \property Qt3D::QBlendState::dstRGB + + */ +QBlendState::Blending QBlendState::dstRGB() const +{ + Q_D(const QBlendState); + return d->m_dstRGB; +} + +void QBlendState::setDstRGB(QBlendState::Blending dstRGB) +{ + Q_D(QBlendState); + if (d->m_dstRGB != dstRGB) { + d->m_dstRGB = dstRGB; + emit dstRGBChanged(); + } +} + +/*! + \qmlproperty enumeration Qt3D.render::BlendState::srcAlpha + + */ + +/*! + \property Qt3D::QBlendState::srcAlpha + + */ +QBlendState::Blending QBlendState::srcAlpha() const +{ + Q_D(const QBlendState); + return d->m_srcAlpha; +} + +void QBlendState::setSrcAlpha(QBlendState::Blending srcAlpha) +{ + Q_D(QBlendState); + if (d->m_srcAlpha != srcAlpha) { + d->m_srcAlpha = srcAlpha; + emit srcAlphaChanged(); + } +} + +/*! + \qmlproperty enumeration Qt3D.render::BlendState::dstAlpha + + */ + +/*! + \property Qt3D::QBlendState::dstAlpha + + */ +QBlendState::Blending QBlendState::dstAlpha() const +{ + Q_D(const QBlendState); + return d->m_dstAlpha; +} + +void QBlendState::setDstAlpha(QBlendState::Blending dstAlpha) +{ + Q_D(QBlendState); + if (d->m_dstAlpha != dstAlpha) { + d->m_dstAlpha = dstAlpha; + emit dstAlphaChanged(); + } +} + +/*! + \class QBlendStateSeparate + \inmodule Qt3DRenderer + \since 5.5 + \brief Encapsulates blending information. + */ + +/*! + \qmltype BlendStateSeparate + \instantiates Qt3D::QBlendStateSeparate + \inherits RenderState + \inqmlmodule Qt3D.Renderer + \since 5.5 + \brief Encapsulates blending information +*/ + +/*! + The constructor creates a QBlendStateSeparate with the + specified \a parent. + */ +QBlendStateSeparate::QBlendStateSeparate(QNode *parent) + : QBlendState(QRenderState::BlendStateSeparate, parent) +{ +} + +} // namespace Qt3DRender + +QT_END_NAMESPACE diff --git a/src/render/renderstates/qblendstate.h b/src/render/renderstates/qblendstate.h new file mode 100644 index 000000000..25072f449 --- /dev/null +++ b/src/render/renderstates/qblendstate.h @@ -0,0 +1,124 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies). +** 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_QBLENDSTATE_H +#define QT3DRENDER_QBLENDSTATE_H + +#include <Qt3DRenderer/qrenderstate.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QBlendStatePrivate; + +class QT3DRENDERERSHARED_EXPORT QBlendState : public QRenderState +{ + Q_OBJECT + Q_PROPERTY(Blending srcRGB READ srcRGB WRITE setSrcRGB NOTIFY srcRGBChanged) + Q_PROPERTY(Blending srcAlpha READ srcAlpha WRITE setSrcAlpha NOTIFY srcAlphaChanged) + Q_PROPERTY(Blending dstRGB READ dstRGB WRITE setDstRGB NOTIFY dstRGBChanged) + Q_PROPERTY(Blending dstAlpha READ dstAlpha WRITE setDstAlpha NOTIFY dstAlphaChanged) + +public: + + enum Blending + { + Zero = 0, + One = 1, + SrcColor = 0x0300, + SrcAlpha = 0x0302, + Src1Alpha, + Src1Color, + DstColor = 0x0306, + DstAlpha = 0x0304, + SrcAlphaSaturate = 0x0308, + ConstantColor = 0x8001, + ConstantAlpha = 0x8003, + OneMinusSrcColor = 0x0301, + OneMinusSrcAlpha = 0x0303, + OneMinusDstAlpha = 0x0305, + OneMinusDstColor = 0x0307, + OneMinusConstantColor = 0x8002, + OneMinusConstantAlpha = 0x8004, + OneMinusSrc1Alpha, + OneMinusSrc1Color0 + }; + Q_ENUM(Blending) + + explicit QBlendState(Qt3D::QNode *parent = 0); + ~QBlendState(); + + Blending srcRGB() const; + void setSrcRGB(Blending srcRGB); + + Blending dstRGB() const; + void setDstRGB(Blending dstRGB); + + Blending srcAlpha() const; + void setSrcAlpha(Blending srcAlpha); + + Blending dstAlpha() const; + void setDstAlpha(Blending dstAlpha); + +Q_SIGNALS: + void srcRGBChanged(); + void srcAlphaChanged(); + void dstRGBChanged(); + void dstAlphaChanged(); + +protected: + void copy(const Qt3D::QNode *ref) Q_DECL_OVERRIDE; + QBlendState(QRenderState::Type type, Qt3D::QNode *parent = 0); + +private: + Q_DECLARE_PRIVATE(QBlendState) + QT3D_CLONEABLE(QBlendState) +}; + +class QT3DRENDERERSHARED_EXPORT QBlendStateSeparate : public QBlendState +{ + Q_OBJECT +public: + explicit QBlendStateSeparate(Qt3D::QNode *parent = 0); +}; + +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_QBLENDSTATE_H diff --git a/src/render/renderstates/qclipplane.cpp b/src/render/renderstates/qclipplane.cpp new file mode 100644 index 000000000..d3f2fadb3 --- /dev/null +++ b/src/render/renderstates/qclipplane.cpp @@ -0,0 +1,125 @@ +/**************************************************************************** +** +** 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 "qclipplane.h" +#include <Qt3DRenderer/private/qrenderstate_p.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QClipPlanePrivate : public QRenderStatePrivate +{ +public: + QClipPlanePrivate() + : QRenderStatePrivate(QRenderState::ClipPlane) + , m_plane(0) + {} + + int m_plane; +}; + +/*! + \class Qt3D::QClipPlane + \inmodule Qt3DRenderer + \since 5.5 + \brief Enables an additional OpenGL clipping plane that can be in shaders + using gl_ClipDistance + + By default, OpenGL supports up to 8 additional clipping planes. + Qt3D::QClipPlane allows to enable one of these additional planes. These + planes can then be manipulated in the shaders using gl_ClipDistance[i] + where i varies between 0 and 8. + */ + +/*! + \qmltype ClipPlane + \instantiates Qt3D::QClipPlane + \inherits RenderState + \inqmlmodule Qt3D.Renderer + \since 5.5 + \brief Enables an additional OpenGL clipping plane that can be in shaders + using gl_ClipDistance + + By default, OpenGL supports up to 8 additional clipping planes. ClipPlane + allows to enable one of these additional planes. These planes can then be + manipulated in the shaders using gl_ClipDistance[i] where i varies between + 0 and 8. +*/ + +QClipPlane::QClipPlane(QNode *parent) + : QRenderState(*new QClipPlanePrivate(), parent) +{ +} + +QClipPlane::~QClipPlane() +{ + QNode::cleanup(); +} + +/*! + * Returns the index of the clip plane. + * \note usually between 0-7 + */ +int QClipPlane::plane() const +{ + Q_D(const QClipPlane); + return d->m_plane; +} + +/*! + * Sets the index of the clip plane to \a plane. + * \note above 7, support is not garanteed + */ +void QClipPlane::setPlane(int plane) +{ + Q_D(QClipPlane); + if (plane != d->m_plane) { + d->m_plane = plane; + Q_EMIT planeChanged(); + } +} + +void QClipPlane::copy(const QNode *ref) +{ + QRenderState::copy(ref); + const QClipPlane *refClip = static_cast<const QClipPlane *>(ref); + d_func()->m_plane = refClip->plane(); +} + +} // namespace Qt3DRender + +QT_END_NAMESPACE diff --git a/src/render/renderstates/qclipplane.h b/src/render/renderstates/qclipplane.h new file mode 100644 index 000000000..7afa6c5e7 --- /dev/null +++ b/src/render/renderstates/qclipplane.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** 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 QT3DRENDER_QCLIPPLANE_H +#define QT3DRENDER_QCLIPPLANE_H + +#include <Qt3DRenderer/qrenderstate.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QClipPlanePrivate; + +class QT3DRENDERERSHARED_EXPORT QClipPlane : public QRenderState +{ + Q_OBJECT + Q_PROPERTY(int plane READ plane WRITE setPlane NOTIFY planeChanged) +public: + explicit QClipPlane(Qt3D::QNode *parent = 0); + ~QClipPlane(); + + int plane() const; + void setPlane(int); + +protected: + void copy(const Qt3D::QNode *ref) Q_DECL_FINAL; + +Q_SIGNALS: + void planeChanged(); + +private: + Q_DECLARE_PRIVATE(QClipPlane) + QT3D_CLONEABLE(QClipPlane) +}; + +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_QCLIPPLANE_H diff --git a/src/render/renderstates/qcolormask.cpp b/src/render/renderstates/qcolormask.cpp new file mode 100644 index 000000000..9f61825ea --- /dev/null +++ b/src/render/renderstates/qcolormask.cpp @@ -0,0 +1,179 @@ +/**************************************************************************** +** +** 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 "qcolormask.h" +#include <Qt3DRenderer/private/qrenderstate_p.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QColorMaskPrivate : public QRenderStatePrivate +{ +public: + QColorMaskPrivate() + : QRenderStatePrivate(QRenderState::ColorMask) + , m_red(true) + , m_green(true) + , m_blue(true) + , m_alpha(true) + {} + + bool m_red; + bool m_green; + bool m_blue; + bool m_alpha; + + Q_DECLARE_PUBLIC(QColorMask) +}; + +/*! + \class Qt3D::QColorMask + \inmodule Qt3DRenderer + + \brief Allows specifying which color components should be written to the + currently bound frame buffer. + + By default, the property for each color component (red, green, blue, alpha) + is set to \c true which means they will be written to the frame buffer. + Setting any of the color component to \c false will prevent it from being + written into the frame buffer. + */ + + +/*! + Constructs a new Qt3D::QColorMask instance with \a parent as parent. + */ +QColorMask::QColorMask(QNode *parent) + : QRenderState(*new QColorMaskPrivate, parent) +{ +} + +QColorMask::~QColorMask() +{ + QNode::cleanup(); +} + +bool QColorMask::isRed() const +{ + Q_D(const QColorMask); + return d->m_red; +} + +bool QColorMask::isGreen() const +{ + Q_D(const QColorMask); + return d->m_green; +} + +bool QColorMask::isBlue() const +{ + Q_D(const QColorMask); + return d->m_blue; +} + +bool QColorMask::isAlpha() const +{ + Q_D(const QColorMask); + return d->m_alpha; +} + +/*! + \property Qt3D::QColorMask::red + Holds whether the red color component should be written to the frame buffer. + */ +void QColorMask::setRed(bool red) +{ + Q_D(QColorMask); + if (red != d->m_red) { + d->m_red = red; + emit redChanged(); + } +} + +/*! + \property Qt3D::QColorMask::green + Holds whether the green color component should be written to the frame buffer. + */ +void QColorMask::setGreen(bool green) +{ + Q_D(QColorMask); + if (green != d->m_green) { + d->m_green = green; + emit greenChanged(); + } +} + +/*! + \property Qt3D::QColorMask::blue + Holds whether the blue color component should be written to the frame buffer. + */ +void QColorMask::setBlue(bool blue) +{ + Q_D(QColorMask); + if (blue != d->m_blue) { + d->m_blue = blue; + emit blueChanged(); + } +} + +/*! + \property Qt3D::QColorMask::alpha + Holds whether the alpha component should be written to the frame buffer. + */ +void QColorMask::setAlpha(bool alpha) +{ + Q_D(QColorMask); + if (alpha != d->m_alpha) { + d->m_alpha = alpha; + emit alphaChanged(); + } +} + +void QColorMask::copy(const QNode *ref) +{ + QRenderState::copy(ref); + const QColorMask *refState = static_cast<const QColorMask *>(ref); + d_func()->m_red = refState->d_func()->m_red; + d_func()->m_green = refState->d_func()->m_green; + d_func()->m_blue = refState->d_func()->m_blue; + d_func()->m_alpha = refState->d_func()->m_alpha; +} + +} // namespace Qt3DRender + +QT_END_NAMESPACE + diff --git a/src/render/renderstates/qcolormask.h b/src/render/renderstates/qcolormask.h new file mode 100644 index 000000000..886feebbb --- /dev/null +++ b/src/render/renderstates/qcolormask.h @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** 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 QT3DRENDER_QCOLORMASK_H +#define QT3DRENDER_QCOLORMASK_H + +#include <Qt3DRenderer/qrenderstate.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QColorMaskPrivate; + +class QT3DRENDERERSHARED_EXPORT QColorMask : public QRenderState +{ + Q_OBJECT + Q_PROPERTY(bool red READ isRed WRITE setRed NOTIFY redChanged) + Q_PROPERTY(bool green READ isGreen WRITE setGreen NOTIFY greenChanged) + Q_PROPERTY(bool blue READ isBlue WRITE setBlue NOTIFY blueChanged) + Q_PROPERTY(bool alpha READ isAlpha WRITE setAlpha NOTIFY alphaChanged) + +public: + explicit QColorMask(Qt3D::QNode *parent = Q_NULLPTR); + ~QColorMask(); + + bool isRed() const; + bool isGreen() const; + bool isBlue() const; + bool isAlpha() const; + + void setRed(bool red); + void setGreen(bool green); + void setBlue(bool blue); + void setAlpha(bool alpha); + +Q_SIGNALS: + void redChanged(); + void greenChanged(); + void blueChanged(); + void alphaChanged(); + +protected: + void copy(const Qt3D::QNode *ref) Q_DECL_FINAL; + +private: + Q_DECLARE_PRIVATE(QColorMask) + QT3D_CLONEABLE(QColorMask) +}; + +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_QCOLORMASK_H diff --git a/src/render/renderstates/qcullface.cpp b/src/render/renderstates/qcullface.cpp new file mode 100644 index 000000000..ce71aaa59 --- /dev/null +++ b/src/render/renderstates/qcullface.cpp @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies). +** 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 "qcullface.h" +#include <private/qnode_p.h> +#include "qrenderstate_p.h" +#include <Qt3DCore/qscenepropertychange.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QCullFacePrivate : public QRenderStatePrivate +{ +public: + QCullFacePrivate() + : QRenderStatePrivate(QRenderState::CullFace) + , m_mode(QCullFace::Back) + { + } + + Q_DECLARE_PUBLIC(QCullFace) + QCullFace::CullingMode m_mode; +}; + +QCullFace::QCullFace(QNode *parent) + : QRenderState(*new QCullFacePrivate, parent) +{ +} + +QCullFace::~QCullFace() +{ + QNode::cleanup(); +} + +void QCullFace::copy(const QNode *ref) +{ + QRenderState::copy(ref); + const QCullFace *refState = static_cast<const QCullFace*>(ref); + d_func()->m_mode = refState->d_func()->m_mode; +} + +QCullFace::CullingMode QCullFace::mode() const +{ + Q_D(const QCullFace); + return d->m_mode; +} + +void QCullFace::setMode(QCullFace::CullingMode mode) +{ + Q_D(QCullFace); + if (d->m_mode != mode) { + d->m_mode = mode; + emit modeChanged(); + } +} + +} // namespace Qt3DRender + +QT_END_NAMESPACE diff --git a/src/render/renderstates/qcullface.h b/src/render/renderstates/qcullface.h new file mode 100644 index 000000000..d8832bcd6 --- /dev/null +++ b/src/render/renderstates/qcullface.h @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies). +** 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_QCULLFACE_H +#define QT3DRENDER_QCULLFACE_H + +#include <Qt3DRenderer/qrenderstate.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QCullFacePrivate; + +class QT3DRENDERERSHARED_EXPORT QCullFace : public QRenderState +{ + Q_OBJECT + Q_PROPERTY(CullingMode mode READ mode WRITE setMode NOTIFY modeChanged) + +public: + + enum CullingMode + { + Front = 0x0404, + Back = 0x0405, + FrontAndBack = 0x0408 + }; + Q_ENUM(CullingMode) + + explicit QCullFace(Qt3D::QNode *parent = 0); + ~QCullFace(); + + CullingMode mode() const; + void setMode(CullingMode mode); + +Q_SIGNALS: + void modeChanged(); + +protected: + void copy(const Qt3D::QNode *ref) Q_DECL_OVERRIDE; + +private: + Q_DECLARE_PRIVATE(QCullFace) + QT3D_CLONEABLE(QCullFace) +}; + +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_QCULLFACE_H diff --git a/src/render/renderstates/qdepthmask.cpp b/src/render/renderstates/qdepthmask.cpp new file mode 100644 index 000000000..76e5339d0 --- /dev/null +++ b/src/render/renderstates/qdepthmask.cpp @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies). +** 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 "qdepthmask.h" +#include "qrenderstate_p.h" +#include <private/qnode_p.h> +#include <Qt3DCore/qscenepropertychange.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QDepthMaskPrivate : public QRenderStatePrivate +{ +public: + QDepthMaskPrivate() + : QRenderStatePrivate(QRenderState::DepthMask) + , m_mask(false) + { + } + + Q_DECLARE_PUBLIC(QDepthMask) + bool m_mask; +}; + +QDepthMask::QDepthMask(QNode *parent) + : QRenderState(*new QDepthMaskPrivate, parent) +{ +} + +QDepthMask::~QDepthMask() +{ + QNode::cleanup(); +} + +void QDepthMask::copy(const QNode *ref) +{ + QRenderState::copy(ref); + const QDepthMask *refState = static_cast<const QDepthMask*>(ref); + d_func()->m_mask = refState->d_func()->m_mask; +} + +bool QDepthMask::mask() const +{ + Q_D(const QDepthMask); + return d->m_mask; +} + +void QDepthMask::setMask(bool mask) +{ + Q_D(QDepthMask); + if (d->m_mask != mask) { + d->m_mask = mask; + emit maskChanged(); + } +} + +} // namespace Qt3DRender + +QT_END_NAMESPACE diff --git a/src/render/renderstates/qdepthmask.h b/src/render/renderstates/qdepthmask.h new file mode 100644 index 000000000..fdd02b4d3 --- /dev/null +++ b/src/render/renderstates/qdepthmask.h @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies). +** 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_QDEPTHMASK_H +#define QT3DRENDER_QDEPTHMASK_H + +#include <Qt3DRenderer/qrenderstate.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QDepthMaskPrivate; + +class QT3DRENDERERSHARED_EXPORT QDepthMask : public QRenderState +{ + Q_OBJECT + Q_PROPERTY (bool mask READ mask WRITE setMask NOTIFY maskChanged) +public: + explicit QDepthMask(Qt3D::QNode *parent = 0); + ~QDepthMask(); + + bool mask() const; + void setMask(bool mask); + +Q_SIGNALS: + void maskChanged(); + +protected: + void copy(const Qt3D::QNode *ref) Q_DECL_OVERRIDE; + +private: + Q_DECLARE_PRIVATE(QDepthMask) + QT3D_CLONEABLE(QDepthMask) +}; + +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_QDEPTHMASK_H diff --git a/src/render/renderstates/qdepthtest.cpp b/src/render/renderstates/qdepthtest.cpp new file mode 100644 index 000000000..017b7ce00 --- /dev/null +++ b/src/render/renderstates/qdepthtest.cpp @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies). +** 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 "qdepthtest.h" +#include "qrenderstate_p.h" +#include <private/qnode_p.h> +#include <Qt3DCore/qscenepropertychange.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QDepthTest; + +class QDepthTestPrivate : public QRenderStatePrivate +{ +public : + QDepthTestPrivate() + : QRenderStatePrivate(QRenderState::DepthTest) + , m_func(QDepthTest::Never) + { + } + + Q_DECLARE_PUBLIC(QDepthTest) + QDepthTest::DepthFunc m_func; +}; + +void QDepthTest::copy(const QNode *ref) +{ + QRenderState::copy(ref); + const QDepthTest *refState = static_cast<const QDepthTest*>(ref); + d_func()->m_func = refState->d_func()->m_func; +} + +QDepthTest::QDepthTest(QNode *parent) + : QRenderState(*new QDepthTestPrivate, parent) +{ +} + +QDepthTest::~QDepthTest() +{ + QNode::cleanup(); +} + +QDepthTest::DepthFunc QDepthTest::func() const +{ + Q_D(const QDepthTest); + return d->m_func; +} + +void QDepthTest::setFunc(QDepthTest::DepthFunc func) +{ + Q_D(QDepthTest); + if (d->m_func != func) { + d->m_func = func; + emit funcChanged(); + } +} + +} // namespace Qt3DRender + +QT_END_NAMESPACE diff --git a/src/render/renderstates/qdepthtest.h b/src/render/renderstates/qdepthtest.h new file mode 100644 index 000000000..e9b4275b6 --- /dev/null +++ b/src/render/renderstates/qdepthtest.h @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies). +** 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_QDEPTHTEST_H +#define QT3DRENDER_QDEPTHTEST_H + +#include <Qt3DRenderer/qrenderstate.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QDepthTestPrivate; + +class QT3DRENDERERSHARED_EXPORT QDepthTest : public QRenderState +{ + Q_OBJECT + Q_PROPERTY(DepthFunc func READ func WRITE setFunc NOTIFY funcChanged) +public: + + enum DepthFunc { + Never = 0x0200, + Always = 0x0207, + Less = 0x0201, + LessOrEqual = 0x0203, + Equal = 0x0202, + GreaterOrEqual = 0x0206, + Greater = 0x0204, + NotEqual = 0x0205 + }; + Q_ENUM(DepthFunc) + + explicit QDepthTest(Qt3D::QNode *parent = 0); + ~QDepthTest(); + + DepthFunc func() const; + void setFunc(DepthFunc func); + +Q_SIGNALS: + void funcChanged(); + +protected: + void copy(const Qt3D::QNode *ref) Q_DECL_OVERRIDE; + +private: + Q_DECLARE_PRIVATE(QDepthTest) + QT3D_CLONEABLE(QDepthTest) +}; + +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_QDEPTHTEST_H diff --git a/src/render/renderstates/qdithering.cpp b/src/render/renderstates/qdithering.cpp new file mode 100644 index 000000000..fd8ce1c2f --- /dev/null +++ b/src/render/renderstates/qdithering.cpp @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies). +** 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 "qdithering.h" +#include "qrenderstate_p.h" +#include <private/qnode_p.h> +#include <Qt3DCore/qscenepropertychange.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QDitheringPrivate : public QRenderStatePrivate +{ +public: + QDitheringPrivate() + : QRenderStatePrivate(QRenderState::Dithering) + {} + + Q_DECLARE_PUBLIC(QDithering) +}; + +QDithering::QDithering(QNode *parent) + : QRenderState(*new QDitheringPrivate, parent) +{ +} + +QDithering::~QDithering() +{ + QNode::cleanup(); +} + +} // namespace Qt3DRender + +QT_END_NAMESPACE diff --git a/src/render/renderstates/qdithering.h b/src/render/renderstates/qdithering.h new file mode 100644 index 000000000..37794e372 --- /dev/null +++ b/src/render/renderstates/qdithering.h @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies). +** 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_QDITHERING_H +#define QT3DRENDER_QDITHERING_H + +#include <Qt3DRenderer/qrenderstate.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QDitheringPrivate; + +class QT3DRENDERERSHARED_EXPORT QDithering : public QRenderState +{ + Q_OBJECT +public: + explicit QDithering(Qt3D::QNode *parent = 0); + ~QDithering(); + +private: + Q_DECLARE_PRIVATE(QDithering) + QT3D_CLONEABLE(QDithering) +}; + +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_QDITHERING_H diff --git a/src/render/renderstates/qfrontface.cpp b/src/render/renderstates/qfrontface.cpp new file mode 100644 index 000000000..4ec5043a4 --- /dev/null +++ b/src/render/renderstates/qfrontface.cpp @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies). +** 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 "qfrontface.h" +#include "qrenderstate_p.h" +#include <private/qnode_p.h> +#include <Qt3DCore/qscenepropertychange.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QFrontFacePrivate : public QRenderStatePrivate +{ +public: + QFrontFacePrivate() + : QRenderStatePrivate(QRenderState::FrontFace) + , m_direction(QFrontFace::ClockWise) + { + } + + Q_DECLARE_PUBLIC(QFrontFace) + QFrontFace::FaceDir m_direction; +}; + +QFrontFace::QFrontFace(QNode *parent) + : QRenderState(*new QFrontFacePrivate, parent) +{ +} + +QFrontFace::~QFrontFace() +{ + QNode::cleanup(); +} + +void QFrontFace::copy(const QNode *ref) +{ + QRenderState::copy(ref); + const QFrontFace *refState = static_cast<const QFrontFace*>(ref); + d_func()->m_direction = refState->d_func()->m_direction; +} + +QFrontFace::FaceDir QFrontFace::direction() const +{ + Q_D(const QFrontFace); + return d->m_direction; +} + +void QFrontFace::setDirection(QFrontFace::FaceDir direction) +{ + Q_D(QFrontFace); + if (d->m_direction != direction) { + d->m_direction = direction; + emit directionChanged(); + } +} + +} // namespace Qt3DRender + +QT_END_NAMESPACE diff --git a/src/render/renderstates/qfrontface.h b/src/render/renderstates/qfrontface.h new file mode 100644 index 000000000..0a2c8cac9 --- /dev/null +++ b/src/render/renderstates/qfrontface.h @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies). +** 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_QFRONTFACE_H +#define QT3DRENDER_QFRONTFACE_H + +#include <Qt3DRenderer/qrenderstate.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QFrontFacePrivate; + +class QT3DRENDERERSHARED_EXPORT QFrontFace : public QRenderState +{ + Q_OBJECT + Q_PROPERTY(FaceDir direction READ direction WRITE setDirection NOTIFY directionChanged) +public: + + enum FaceDir + { + ClockWise = 0x0900, + CounterClockWise = 0x0901 + }; + Q_ENUM(FaceDir) + + explicit QFrontFace(Qt3D::QNode *parent = 0); + ~QFrontFace(); + + FaceDir direction() const; + void setDirection(FaceDir direction); + +Q_SIGNALS: + void directionChanged(); + +protected: + void copy(const Qt3D::QNode *ref) Q_DECL_OVERRIDE; + +private: + Q_DECLARE_PRIVATE(QFrontFace) + QT3D_CLONEABLE(QFrontFace) +}; + +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_QFRONTFACE_H diff --git a/src/render/renderstates/qpolygonoffset.cpp b/src/render/renderstates/qpolygonoffset.cpp new file mode 100644 index 000000000..27c9cde4f --- /dev/null +++ b/src/render/renderstates/qpolygonoffset.cpp @@ -0,0 +1,110 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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 "qpolygonoffset.h" +#include <private/qrenderstate_p.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QPolygonOffsetPrivate : public QRenderStatePrivate +{ +public: + QPolygonOffsetPrivate() + : QRenderStatePrivate(QRenderState::PolygonOffset) + , m_factor(0) + , m_units(0) + { + } + + float m_factor; + float m_units; + + Q_DECLARE_PUBLIC(QPolygonOffset) +}; + +QPolygonOffset::QPolygonOffset(QNode *parent) + : QRenderState(*new QPolygonOffsetPrivate, parent) +{ +} + +QPolygonOffset::~QPolygonOffset() +{ + QNode::cleanup(); +} + +float QPolygonOffset::factor() const +{ + Q_D(const QPolygonOffset); + return d->m_factor; +} + +void QPolygonOffset::setFactor(float factor) +{ + Q_D(QPolygonOffset); + if (d->m_factor != factor) { + d->m_factor = factor; + emit factorChanged(d->m_factor); + } +} + +float QPolygonOffset::units() const +{ + Q_D(const QPolygonOffset); + return d->m_units; +} + +void QPolygonOffset::setUnits(float units) +{ + Q_D(QPolygonOffset); + if (d->m_units != units) { + d->m_units = units; + emit unitsChanged(d->m_units); + } +} + +void QPolygonOffset::copy(const QNode *ref) +{ + QRenderState::copy(ref); + const QPolygonOffset *refState = static_cast<const QPolygonOffset *>(ref); + d_func()->m_factor = refState->d_func()->m_factor; + d_func()->m_units = refState->d_func()->m_units; +} + +} // namespace Qt3DRender + +QT_END_NAMESPACE diff --git a/src/render/renderstates/qpolygonoffset.h b/src/render/renderstates/qpolygonoffset.h new file mode 100644 index 000000000..9aff94a1f --- /dev/null +++ b/src/render/renderstates/qpolygonoffset.h @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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_QPOLYGONOFFSET_H +#define QT3DRENDER_QPOLYGONOFFSET_H + +#include <Qt3DRenderer/qrenderstate.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QPolygonOffsetPrivate; + +class QT3DRENDERERSHARED_EXPORT QPolygonOffset : public QRenderState +{ + Q_OBJECT + + Q_PROPERTY(float factor READ factor WRITE setFactor NOTIFY factorChanged) + Q_PROPERTY(float units READ units WRITE setUnits NOTIFY unitsChanged) +public: + explicit QPolygonOffset(Qt3D::QNode *parent = Q_NULLPTR); + ~QPolygonOffset(); + + float factor() const; + void setFactor(float factor); + + float units() const; + void setUnits(float units); + +Q_SIGNALS: + void factorChanged(float newFactor); + void unitsChanged(float newUnits); + +protected: + void copy(const Qt3D::QNode *ref) Q_DECL_OVERRIDE; + +private: + Q_DECLARE_PRIVATE(QPolygonOffset) + QT3D_CLONEABLE(QPolygonOffset) +}; + +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_QPOLYGONOFFSET_H diff --git a/src/render/renderstates/qrenderstate.cpp b/src/render/renderstates/qrenderstate.cpp new file mode 100644 index 000000000..831962ca4 --- /dev/null +++ b/src/render/renderstates/qrenderstate.cpp @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies). +** 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 "qrenderstate.h" +#include "qrenderstate_p.h" + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +/*! + \class Qt3D::QRenderStatePrivate + \internal +*/ +QRenderStatePrivate::QRenderStatePrivate(QRenderState::Type type) + : QNodePrivate(), + m_type(type) +{ +} + +QRenderState::~QRenderState() +{ + Q_ASSERT_X(Qt3D::QNodePrivate::get(this)->m_wasCleanedUp, Q_FUNC_INFO, "QNode::cleanup should have been called by now. A Qt3DRender::QRenderState subclass didn't call QNode::cleanup in its destructor"); +} + +QRenderState::Type QRenderState::type() const +{ + Q_D(const QRenderState); + return d->m_type; +} + +/*! \internal */ +QRenderState::QRenderState(QRenderStatePrivate &dd, QNode *parent) + : QNode(dd, parent) +{ +} + +} // namespace Qt3DRender + +QT_END_NAMESPACE diff --git a/src/render/renderstates/qrenderstate.h b/src/render/renderstates/qrenderstate.h new file mode 100644 index 000000000..6f730a432 --- /dev/null +++ b/src/render/renderstates/qrenderstate.h @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies). +** 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_QRENDERSTATE_H +#define QT3DRENDER_QRENDERSTATE_H + +#include <Qt3DCore/qnode.h> +#include <Qt3DRenderer/qt3drenderer_global.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QRenderStatePrivate; + +class QT3DRENDERERSHARED_EXPORT QRenderState : public Qt3D::QNode +{ + Q_OBJECT + +public: + enum Type { + AlphaCoverage, + AlphaTest, + BlendEquation, + BlendState, + BlendStateSeparate, + ColorMask, + CullFace, + DepthMask, + DepthTest, + Dithering, + FrontFace, + PolygonOffset, + ScissorTest, + StencilTest, + StencilMask, + StencilOp, + ClipPlane + }; + Q_ENUM(Type) + + ~QRenderState(); + + Type type() const; + +protected: + QRenderState(QRenderStatePrivate &dd, Qt3D::QNode *parent = Q_NULLPTR); + +private: + Q_DECLARE_PRIVATE(QRenderState) +}; + +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_QRENDERSTATE_H diff --git a/src/render/renderstates/qrenderstate_p.h b/src/render/renderstates/qrenderstate_p.h new file mode 100644 index 000000000..21bdd276a --- /dev/null +++ b/src/render/renderstates/qrenderstate_p.h @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies). +** 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_QRENDERSTATE_P_H +#define QT3DRENDER_QRENDERSTATE_P_H + +#include <Qt3DCore/private/qnode_p.h> +#include <Qt3DRenderer/qrenderstate.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QRenderStatePrivate : public Qt3D::QNodePrivate +{ +public: + QRenderStatePrivate(QRenderState::Type type); + Q_DECLARE_PUBLIC(QRenderState) + + const QRenderState::Type m_type; +}; + +} + +QT_END_NAMESPACE + +#endif // QT3DRENDER_QRENDERSTATE_P_H diff --git a/src/render/renderstates/qscissortest.cpp b/src/render/renderstates/qscissortest.cpp new file mode 100644 index 000000000..cc2624f41 --- /dev/null +++ b/src/render/renderstates/qscissortest.cpp @@ -0,0 +1,149 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies). +** 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 "qscissortest.h" +#include "qrenderstate_p.h" +#include <private/qnode_p.h> +#include <Qt3DCore/qscenepropertychange.h> + + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QScissorTestPrivate : public QRenderStatePrivate +{ +public: + QScissorTestPrivate() + : QRenderStatePrivate(QRenderState::ScissorTest) + , m_left(0) + , m_bottom(0) + , m_width(0) + , m_height(0) + { + } + + Q_DECLARE_PUBLIC(QScissorTest) + int m_left; + int m_bottom; + int m_width; + int m_height; +}; + +QScissorTest::QScissorTest(QNode *parent) + : QRenderState(*new QScissorTestPrivate, parent) +{ +} + +QScissorTest::~QScissorTest() +{ + QNode::cleanup(); +} + +void QScissorTest::copy(const QNode *ref) +{ + QRenderState::copy(ref); + const QScissorTest *refState = static_cast<const QScissorTest*>(ref); + d_func()->m_left = refState->d_func()->m_left; + d_func()->m_bottom = refState->d_func()->m_bottom; + d_func()->m_width = refState->d_func()->m_width; + d_func()->m_height = refState->d_func()->m_height; +} + +int QScissorTest::left() const +{ + Q_D(const QScissorTest); + return d->m_left; +} + +void QScissorTest::setLeft(int left) +{ + Q_D(QScissorTest); + if (d->m_left != left) { + d->m_left = left; + emit leftChanged(); + } +} + +int QScissorTest::bottom() const +{ + Q_D(const QScissorTest); + return d->m_bottom; +} + +void QScissorTest::setBottom(int bottom) +{ + Q_D(QScissorTest); + if (d->m_bottom != bottom) { + d->m_bottom = bottom; + emit bottomChanged(); + } +} + +int QScissorTest::width() const +{ + Q_D(const QScissorTest); + return d->m_width; +} + +void QScissorTest::setWidth(int width) +{ + Q_D(QScissorTest); + if (d->m_width != width) { + d->m_width = width; + emit widthChanged(); + } +} + +int QScissorTest::height() const +{ + Q_D(const QScissorTest); + return d->m_height; +} + +void QScissorTest::setHeight(int height) +{ + Q_D(QScissorTest); + if (d->m_height != height) { + d->m_height = height; + emit heightChanged(); + } +} + +} // namespace Qt3DRender + +QT_END_NAMESPACE diff --git a/src/render/renderstates/qscissortest.h b/src/render/renderstates/qscissortest.h new file mode 100644 index 000000000..a607bcd72 --- /dev/null +++ b/src/render/renderstates/qscissortest.h @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies). +** 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_QSCISSORTEST_H +#define QT3DRENDER_QSCISSORTEST_H + +#include <Qt3DRenderer/qrenderstate.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QScissorTestPrivate; + +class QT3DRENDERERSHARED_EXPORT QScissorTest : public QRenderState +{ + Q_OBJECT + Q_PROPERTY(int left READ left WRITE setLeft NOTIFY leftChanged) + Q_PROPERTY(int bottom READ bottom WRITE setBottom NOTIFY bottomChanged) + Q_PROPERTY(int width READ width WRITE setWidth NOTIFY widthChanged) + Q_PROPERTY(int height READ height WRITE setHeight NOTIFY heightChanged) + +public: + explicit QScissorTest(Qt3D::QNode *parent = 0); + ~QScissorTest(); + + int left() const; + void setLeft(int left); + + int bottom() const; + void setBottom(int bottom); + + int width() const; + void setWidth(int width); + + int height() const; + void setHeight(int height); + +Q_SIGNALS: + void leftChanged(); + void bottomChanged(); + void widthChanged(); + void heightChanged(); + +protected: + void copy(const Qt3D::QNode *ref) Q_DECL_OVERRIDE; + +private: + Q_DECLARE_PRIVATE(QScissorTest) + QT3D_CLONEABLE(QScissorTest) +}; + +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_QSCISSORTEST_H diff --git a/src/render/renderstates/qstencilmask.cpp b/src/render/renderstates/qstencilmask.cpp new file mode 100644 index 000000000..44098296a --- /dev/null +++ b/src/render/renderstates/qstencilmask.cpp @@ -0,0 +1,111 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Paul Lemire +** 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 "qstencilmask.h" +#include <Qt3DRenderer/private/qrenderstate_p.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QStencilMaskPrivate : public QRenderStatePrivate +{ +public: + QStencilMaskPrivate() + : QRenderStatePrivate(QRenderState::StencilMask) + , m_frontMask(0) + , m_backMask(0) + {} + + uint m_frontMask; + uint m_backMask; +}; + +/*! + * QStencilMask::QStencilMask + */ + +QStencilMask::QStencilMask(QNode *parent) + : QRenderState(*new QStencilMaskPrivate(), parent) +{ +} + +QStencilMask::~QStencilMask() +{ + QNode::cleanup(); +} + +void QStencilMask::setFrontMask(uint mask) +{ + Q_D(QStencilMask); + if (d->m_frontMask != mask) { + d->m_frontMask = mask; + Q_EMIT frontMaskChanged(); + } +} + +void QStencilMask::setBackMask(uint mask) +{ + Q_D(QStencilMask); + if (d->m_backMask != mask) { + d->m_backMask = mask; + Q_EMIT backMaskChanged(); + } +} + +uint QStencilMask::frontMask() const +{ + Q_D(const QStencilMask); + return d->m_frontMask; +} + +uint QStencilMask::backMask() const +{ + Q_D(const QStencilMask); + return d->m_backMask; +} + +void QStencilMask::copy(const QNode *ref) +{ + QRenderState::copy(ref); + const QStencilMask *otherRef = static_cast<const QStencilMask *>(ref); + d_func()->m_frontMask = otherRef->frontMask(); + d_func()->m_backMask = otherRef->backMask(); +} + +} // namespace Qt3DRender + +QT_END_NAMESPACE diff --git a/src/render/renderstates/qstencilmask.h b/src/render/renderstates/qstencilmask.h new file mode 100644 index 000000000..6e11cff68 --- /dev/null +++ b/src/render/renderstates/qstencilmask.h @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Paul Lemire +** 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_QSTENCILMASK_H +#define QT3DRENDER_QSTENCILMASK_H + +#include <Qt3DRenderer/qrenderstate.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QStencilMaskPrivate; + +class QT3DRENDERERSHARED_EXPORT QStencilMask : public QRenderState +{ + Q_OBJECT + Q_PROPERTY(uint frontMask READ frontMask WRITE setFrontMask NOTIFY frontMaskChanged) + Q_PROPERTY(uint backMask READ backMask WRITE setBackMask NOTIFY backMaskChanged) +public: + explicit QStencilMask(Qt3D::QNode *parent = 0); + ~QStencilMask(); + + void setFrontMask(uint mask); + uint frontMask() const; + void setBackMask(uint mask); + uint backMask() const; + +Q_SIGNALS: + void frontMaskChanged(); + void backMaskChanged(); + +protected: + void copy(const Qt3D::QNode *ref) Q_DECL_FINAL; + +private: + Q_DECLARE_PRIVATE(QStencilMask) + QT3D_CLONEABLE(QStencilMask) +}; + +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_QSTENCILMASK_H diff --git a/src/render/renderstates/qstencilop.cpp b/src/render/renderstates/qstencilop.cpp new file mode 100644 index 000000000..67a571202 --- /dev/null +++ b/src/render/renderstates/qstencilop.cpp @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** 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 "qstencilop.h" +#include "qstencilopseparate.h" +#include <Qt3DRenderer/private/qrenderstate_p.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QStencilOpPrivate : public QRenderStatePrivate +{ +public: + QStencilOpPrivate() + : QRenderStatePrivate(QRenderState::StencilOp) + , m_front(new QStencilOpSeparate(QStencilOpSeparate::Front, q_ptr)) + , m_back(new QStencilOpSeparate(QStencilOpSeparate::Back, q_ptr)) + {} + + QStencilOpSeparate *m_front; + QStencilOpSeparate *m_back; +}; + + +QStencilOp::QStencilOp(QNode *parent) + : QRenderState(*new QStencilOpPrivate(), parent) +{ +} + +QStencilOp::~QStencilOp() +{ + QNode::cleanup(); +} + +QStencilOpSeparate *QStencilOp::front() const +{ + Q_D(const QStencilOp); + return d->m_front; +} + +QStencilOpSeparate *QStencilOp::back() const +{ + Q_D(const QStencilOp); + return d->m_back; +} + +void QStencilOp::copy(const QNode *ref) +{ + QRenderState::copy(ref); + const QStencilOp *refState = static_cast<const QStencilOp*>(ref); + d_func()->m_back->setDepthFail(refState->d_func()->m_back->depthFail()); + d_func()->m_back->setStencilFail(refState->d_func()->m_back->stencilFail()); + d_func()->m_back->setStencilDepthPass(refState->d_func()->m_back->stencilDepthPass()); + d_func()->m_front->setDepthFail(refState->d_func()->m_front->depthFail()); + d_func()->m_front->setStencilFail(refState->d_func()->m_front->stencilFail()); + d_func()->m_front->setStencilDepthPass(refState->d_func()->m_front->stencilDepthPass()); +} + +} // namespace Qt3DRender + +QT_END_NAMESPACE diff --git a/src/render/renderstates/qstencilop.h b/src/render/renderstates/qstencilop.h new file mode 100644 index 000000000..bc212af48 --- /dev/null +++ b/src/render/renderstates/qstencilop.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** 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 QT3DRENDER_QSTENCILOP_H +#define QT3DRENDER_QSTENCILOP_H + +#include <Qt3DRenderer/qrenderstate.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QStencilOpPrivate; +class QStencilOpSeparate; + +class QT3DRENDERERSHARED_EXPORT QStencilOp : public QRenderState +{ + Q_OBJECT + Q_PROPERTY(Qt3DRender::QStencilOpSeparate *front READ front CONSTANT) + Q_PROPERTY(Qt3DRender::QStencilOpSeparate *back READ back CONSTANT) + +public: + explicit QStencilOp(Qt3D::QNode *parent = 0); + ~QStencilOp(); + + QStencilOpSeparate *front() const; + QStencilOpSeparate *back() const; + +protected: + void copy(const Qt3D::QNode *ref) Q_DECL_FINAL; + +private: + Q_DECLARE_PRIVATE(QStencilOp) + QT3D_CLONEABLE(QStencilOp) +}; + +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_QSTENCILOP_H diff --git a/src/render/renderstates/qstencilopseparate.cpp b/src/render/renderstates/qstencilopseparate.cpp new file mode 100644 index 000000000..ec2c4e40c --- /dev/null +++ b/src/render/renderstates/qstencilopseparate.cpp @@ -0,0 +1,125 @@ +/**************************************************************************** +** +** 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 "qstencilopseparate.h" +#include <private/qobject_p.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QStencilOpSeparatePrivate : public QObjectPrivate +{ +public: + QStencilOpSeparatePrivate(QStencilOpSeparate::StencilFaceMode mode) + : QObjectPrivate() + , m_face(mode) + , m_stencilFailOp(QStencilOpSeparate::Keep) + , m_depthFailOp(QStencilOpSeparate::Keep) + , m_stencilDepthPassOp(QStencilOpSeparate::Keep) + { + + } + + QStencilOpSeparate::StencilFaceMode m_face; + QStencilOpSeparate::StencilOp m_stencilFailOp; + QStencilOpSeparate::StencilOp m_depthFailOp; + QStencilOpSeparate::StencilOp m_stencilDepthPassOp; +}; + +QStencilOpSeparate::QStencilOpSeparate(StencilFaceMode mode, QObject *parent) + : QObject(*new QStencilOpSeparatePrivate(mode), parent) +{ +} + +QStencilOpSeparate::~QStencilOpSeparate() +{ +} + +QStencilOpSeparate::StencilFaceMode QStencilOpSeparate::faceMode() const +{ + Q_D(const QStencilOpSeparate); + return d->m_face; +} + +void QStencilOpSeparate::setStencilFail(QStencilOpSeparate::StencilOp op) +{ + Q_D(QStencilOpSeparate); + if (d->m_stencilFailOp != op) { + d->m_stencilFailOp = op; + Q_EMIT stencilFailChanged(); + } +} + +QStencilOpSeparate::StencilOp QStencilOpSeparate::stencilFail() const +{ + Q_D(const QStencilOpSeparate); + return d->m_stencilFailOp; +} + +void QStencilOpSeparate::setDepthFail(QStencilOpSeparate::StencilOp op) +{ + Q_D(QStencilOpSeparate); + if (d->m_depthFailOp != op) { + d->m_depthFailOp = op; + Q_EMIT depthFailChanged(); + } +} + +QStencilOpSeparate::StencilOp QStencilOpSeparate::depthFail() const +{ + Q_D(const QStencilOpSeparate); + return d->m_depthFailOp; +} + +void QStencilOpSeparate::setStencilDepthPass(QStencilOpSeparate::StencilOp op) +{ + Q_D(QStencilOpSeparate); + if (d->m_stencilDepthPassOp != op) { + d->m_stencilDepthPassOp = op; + Q_EMIT stencilDepthPassChanged(); + } +} + +QStencilOpSeparate::StencilOp QStencilOpSeparate::stencilDepthPass() const +{ + Q_D(const QStencilOpSeparate); + return d->m_stencilDepthPassOp; +} + +} // namespace Qt3DRender + +QT_END_NAMESPACE diff --git a/src/render/renderstates/qstencilopseparate.h b/src/render/renderstates/qstencilopseparate.h new file mode 100644 index 000000000..44561131c --- /dev/null +++ b/src/render/renderstates/qstencilopseparate.h @@ -0,0 +1,110 @@ +/**************************************************************************** +** +** 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 QT3DRENDER_QSTENCILOPSEPARATE_H +#define QT3DRENDER_QSTENCILOPSEPARATE_H + +#include <QObject> +#include <Qt3DRenderer/qt3drenderer_global.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QStencilOpPrivate; +class QStencilOpSeparatePrivate; + +class QT3DRENDERERSHARED_EXPORT QStencilOpSeparate : public QObject +{ + Q_OBJECT + Q_PROPERTY(StencilFaceMode faceMode READ faceMode NOTIFY faceModeChanged) + Q_PROPERTY(StencilOp stencilFail READ stencilFail WRITE setStencilFail NOTIFY stencilFailChanged) + Q_PROPERTY(StencilOp depthFail READ depthFail WRITE setDepthFail NOTIFY depthFailChanged) + Q_PROPERTY(StencilOp stencilDepthPass READ stencilDepthPass WRITE setStencilDepthPass NOTIFY stencilDepthPassChanged) + +public: + enum StencilFaceMode + { + Front = 0x0404, + Back = 0x0405, + FrontAndBack = 0x0408 + }; + Q_ENUM(StencilFaceMode) + + enum StencilOp + { + Zero = 0, + Keep = 0x1E00, + Replace = 0x1E01, + Incr = 0x1E02, + Decr = 0x1E03, + IncrWrap = 0x8507, + DecrWrap = 0x8508, + Invert = 0x150A + }; + Q_ENUM(StencilOp) + + ~QStencilOpSeparate(); + + StencilFaceMode faceMode() const; + + void setStencilFail(StencilOp op); + StencilOp stencilFail() const; + + void setDepthFail(StencilOp op); + StencilOp depthFail() const; + + void setStencilDepthPass(StencilOp op); + StencilOp stencilDepthPass() const; + +Q_SIGNALS: + void stencilFailChanged(); + void depthFailChanged(); + void stencilDepthPassChanged(); + void faceModeChanged(); + +private: + explicit QStencilOpSeparate(StencilFaceMode mode, QObject *parent = 0); + Q_DECLARE_PRIVATE(QStencilOpSeparate) + + friend class QStencilOpPrivate; +}; + +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_QSTENCILOPSEPARATE_H diff --git a/src/render/renderstates/qstenciltest.cpp b/src/render/renderstates/qstenciltest.cpp new file mode 100644 index 000000000..2533d71a9 --- /dev/null +++ b/src/render/renderstates/qstenciltest.cpp @@ -0,0 +1,101 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies). +** 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 "qstenciltest.h" +#include "qrenderstate_p.h" +#include <private/qnode_p.h> +#include <Qt3DCore/qscenepropertychange.h> +#include "qstenciltestseparate.h" + + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QStencilTestPrivate : public QRenderStatePrivate +{ +public: + QStencilTestPrivate() + : QRenderStatePrivate(QRenderState::StencilTest) + , m_front(new QStencilTestSeparate(QStencilTestSeparate::Front)) + , m_back(new QStencilTestSeparate(QStencilTestSeparate::Back)) + { + } + + Q_DECLARE_PUBLIC(QStencilTest) + QStencilTestSeparate *m_front; + QStencilTestSeparate *m_back; +}; + +QStencilTest::QStencilTest(QNode *parent) + : QRenderState(*new QStencilTestPrivate, parent) +{ +} + +QStencilTest::~QStencilTest() +{ + QNode::cleanup(); +} + +QStencilTestSeparate *QStencilTest::front() const +{ + Q_D(const QStencilTest); + return d->m_front; +} + +QStencilTestSeparate *QStencilTest::back() const +{ + Q_D(const QStencilTest); + return d->m_back; +} + +void QStencilTest::copy(const QNode *ref) +{ + QRenderState::copy(ref); + const QStencilTest *refState = static_cast<const QStencilTest*>(ref); + d_func()->m_front->setMask(refState->d_func()->m_front->mask()); + d_func()->m_front->setRef(refState->d_func()->m_front->ref()); + d_func()->m_front->setFunc(refState->d_func()->m_front->func()); + d_func()->m_back->setMask(refState->d_func()->m_back->mask()); + d_func()->m_back->setRef(refState->d_func()->m_back->ref()); + d_func()->m_back->setFunc(refState->d_func()->m_back->func()); +} + + +} // namespace Qt3DRender + +QT_END_NAMESPACE diff --git a/src/render/renderstates/qstenciltest.h b/src/render/renderstates/qstenciltest.h new file mode 100644 index 000000000..51469f69c --- /dev/null +++ b/src/render/renderstates/qstenciltest.h @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies). +** 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_QSTENCILTEST_H +#define QT3DRENDER_QSTENCILTEST_H + +#include <Qt3DRenderer/qrenderstate.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QStencilTestPrivate; +class QStencilTestSeparate; + +class QT3DRENDERERSHARED_EXPORT QStencilTest : public QRenderState +{ + Q_OBJECT + Q_PROPERTY(Qt3DRender::QStencilTestSeparate *front READ front CONSTANT) + Q_PROPERTY(Qt3DRender::QStencilTestSeparate *back READ back CONSTANT) +public: + + explicit QStencilTest(Qt3D::QNode *parent = 0); + ~QStencilTest(); + + QStencilTestSeparate *front() const; + QStencilTestSeparate *back() const; + +protected: + void copy(const Qt3D::QNode *ref) Q_DECL_OVERRIDE; + +private: + Q_DECLARE_PRIVATE(QStencilTest) + QT3D_CLONEABLE(QStencilTest) +}; + +} // namespace Qt3DRender + +QT_END_NAMESPACE + + +#endif // QT3DRENDER_QSTENCILTEST_H diff --git a/src/render/renderstates/qstenciltestseparate.cpp b/src/render/renderstates/qstenciltestseparate.cpp new file mode 100644 index 000000000..87b9fc798 --- /dev/null +++ b/src/render/renderstates/qstenciltestseparate.cpp @@ -0,0 +1,126 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Paul Lemire +** 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 "qstenciltestseparate.h" +#include <private/qobject_p.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QStencilTestSeparatePrivate : public QObjectPrivate +{ +public: + QStencilTestSeparatePrivate(QStencilTestSeparate::StencilFaceMode face) + : QObjectPrivate() + , m_face(face) + , m_mask(0) + , m_ref(0) + , m_func(QStencilTestSeparate::Never) + { + } + + Q_DECLARE_PUBLIC(QStencilTestSeparate) + QStencilTestSeparate::StencilFaceMode m_face; + uint m_mask; + int m_ref; + QStencilTestSeparate::StencilFunc m_func; +}; + + +QStencilTestSeparate::QStencilTestSeparate(QStencilTestSeparate::StencilFaceMode face, QObject *parent) + : QObject(*new QStencilTestSeparatePrivate(face), parent) +{ +} + +QStencilTestSeparate::~QStencilTestSeparate() +{ +} + +uint QStencilTestSeparate::mask() const +{ + Q_D(const QStencilTestSeparate); + return d->m_mask; +} + +void QStencilTestSeparate::setMask(uint mask) +{ + Q_D(QStencilTestSeparate); + if (d->m_mask != mask) { + d->m_mask = mask; + emit maskChanged(); + } +} + +int QStencilTestSeparate::ref() const +{ + Q_D(const QStencilTestSeparate); + return d->m_ref; +} + +void QStencilTestSeparate::setRef(int ref) +{ + Q_D(QStencilTestSeparate); + if (d->m_ref != ref) { + d->m_ref = ref; + emit refChanged(); + } +} + +QStencilTestSeparate::StencilFunc QStencilTestSeparate::func() const +{ + Q_D(const QStencilTestSeparate); + return d->m_func; +} + +void QStencilTestSeparate::setFunc(QStencilTestSeparate::StencilFunc func) +{ + Q_D(QStencilTestSeparate); + if (d->m_func != func) { + d->m_func = func; + emit funcChanged(); + } +} + +QStencilTestSeparate::StencilFaceMode QStencilTestSeparate::faceMode() const +{ + Q_D(const QStencilTestSeparate); + return d->m_face; +} + +} // namespace Qt3DRender + +QT_END_NAMESPACE diff --git a/src/render/renderstates/qstenciltestseparate.h b/src/render/renderstates/qstenciltestseparate.h new file mode 100644 index 000000000..5689a1cfb --- /dev/null +++ b/src/render/renderstates/qstenciltestseparate.h @@ -0,0 +1,111 @@ +/**************************************************************************** +** +** Copyright (C) 2015 Paul Lemire +** 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_QSTENCILTESTSEPARATE_H +#define QT3DRENDER_QSTENCILTESTSEPARATE_H + +#include <QObject> +#include <Qt3DRenderer/qt3drenderer_global.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QStencilTestPrivate; +class QStencilTestSeparatePrivate; + +class QT3DRENDERERSHARED_EXPORT QStencilTestSeparate : public QObject +{ + Q_OBJECT + Q_PROPERTY(StencilFaceMode faceMode READ faceMode NOTIFY faceModeChanged) + Q_PROPERTY(uint mask READ mask WRITE setMask NOTIFY maskChanged) + Q_PROPERTY(int ref READ ref WRITE setRef NOTIFY refChanged) + Q_PROPERTY(StencilFunc func READ func WRITE setFunc NOTIFY funcChanged) + +public: + enum StencilFaceMode + { + Front = 0x0404, + Back = 0x0405, + FrontAndBack = 0x0408 + }; + Q_ENUM(StencilFaceMode) + + enum StencilFunc + { + Never = 0x0200, + Always = 0x0207, + Less = 0x0201, + LessOrEqual = 0x0203, + Equal = 0x0202, + GreaterOrEqual = 0x0206, + Greater = 0x0204, + NotEqual = 0x0205 + }; + Q_ENUM(StencilFunc) + + ~QStencilTestSeparate(); + + uint mask() const; + void setMask(uint mask); + + int ref() const; + void setRef(int ref); + + StencilFunc func() const; + void setFunc(StencilFunc func); + + StencilFaceMode faceMode() const; + +Q_SIGNALS: + void maskChanged(); + void funcChanged(); + void refChanged(); + void faceModeChanged(); + +private: + explicit QStencilTestSeparate(StencilFaceMode face, QObject *parent = 0); + + friend class QStencilTestPrivate; + + Q_DECLARE_PRIVATE(QStencilTestSeparate) +}; + +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_QSTENCILTESTSEPARATE_H diff --git a/src/render/renderstates/renderstates.cpp b/src/render/renderstates/renderstates.cpp new file mode 100644 index 000000000..a7e398035 --- /dev/null +++ b/src/render/renderstates/renderstates.cpp @@ -0,0 +1,335 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies). +** 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 "renderstates_p.h" + +#include <Qt3DRenderer/private/graphicscontext_p.h> + +#include <QOpenGLFunctions_3_2_Core> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { +namespace Render { + +template <class State> +State* getOrCreateImpl(const State& data) +{ + static QList<State*> static_instances; + foreach (State* ext, static_instances) { + if (ext->isEqual(data)) + return ext; + } + + State* result = new State(data); + static_instances.append(result); + return result; +} + +void BlendState::apply(GraphicsContext* gc) const +{ + gc->openGLContext()->functions()->glEnable(GL_BLEND); + gc->openGLContext()->functions()->glBlendFunc( m_1, m_2 ); +} + +BlendState *BlendState::getOrCreate(GLenum src, GLenum dst) +{ + BlendState bs(src, dst); + return getOrCreateImpl(bs); +} + +BlendState::BlendState(GLenum src, GLenum dst) : + GenericState2<BlendState, GLenum, GLenum>(src, dst) +{ +} + +void BlendEquation::apply(GraphicsContext *gc) const +{ + gc->blendEquation(m_1); +} + +BlendEquation *BlendEquation::getOrCreate(GLenum func) +{ + return getOrCreateImpl(BlendEquation(func)); +} + +BlendEquation::BlendEquation(GLenum func) : + GenericState1<BlendEquation, GLenum>(func) +{ +} + + +void AlphaFunc::apply(GraphicsContext* gc) const +{ + gc->alphaTest(m_1, m_2); +} + +AlphaFunc *AlphaFunc::getOrCreate(GLenum func, GLclampf value) +{ + AlphaFunc af(func, value); + return getOrCreateImpl(af); +} + +AlphaFunc::AlphaFunc(GLenum func, GLclampf value) : + GenericState2<AlphaFunc, GLenum, GLclampf>(func, value) +{ +} + +void DepthTest::apply(GraphicsContext *gc) const +{ + gc->depthTest(m_1); +} + +DepthTest *DepthTest::getOrCreate(GLenum func) +{ + DepthTest dt(func); + return getOrCreateImpl(dt); +} + +DepthTest::DepthTest(GLenum func) : + GenericState1<DepthTest, GLenum>(func) +{ +} + +void CullFace::apply(GraphicsContext *gc) const +{ + gc->cullFace(m_1); +} + +CullFace *CullFace::getOrCreate(GLenum func) +{ + return getOrCreateImpl(CullFace(func)); +} + +CullFace::CullFace(GLenum func) : + GenericState1<CullFace, GLenum>(func) +{ +} + +void FrontFace::apply(GraphicsContext *gc) const +{ + gc->frontFace(m_1); +} + +FrontFace *FrontFace::getOrCreate(GLenum func) +{ + return getOrCreateImpl(FrontFace(func)); +} + +FrontFace::FrontFace(GLenum func) : + GenericState1<FrontFace, GLenum>(func) +{ +} + +void DepthMask::apply(GraphicsContext *gc) const +{ + gc->depthMask(m_1); +} + +DepthMask *DepthMask::getOrCreate(GLboolean flag) +{ + return getOrCreateImpl(DepthMask(flag)); +} + +DepthMask::DepthMask(GLboolean flag) : + GenericState1<DepthMask, GLboolean>(flag) +{ +} + +Dithering::Dithering() + : RenderState() +{ +} + +void Dithering::apply(GraphicsContext *gc) const +{ + gc->openGLContext()->functions()->glEnable(GL_DITHER); +} + +Dithering *Dithering::getOrCreate() +{ + return getOrCreateImpl(Dithering()); +} + +ScissorTest::ScissorTest(int left, int bottom, int width, int height) + : GenericState4<ScissorTest, int, int, int, int>(left, bottom, width, height) +{ +} + +void ScissorTest::apply(GraphicsContext *gc) const +{ + gc->openGLContext()->functions()->glEnable(GL_SCISSOR_TEST); + gc->openGLContext()->functions()->glScissor(m_1, m_2, m_3, m_4); +} + +ScissorTest *ScissorTest::getOrCreate(int left, int bottom, int width, int height) +{ + return getOrCreateImpl(ScissorTest(left, bottom, width, height)); +} + +StencilTest *StencilTest::getOrCreate(GLenum frontFunc, int frontRef, uint frontMask, GLenum backFunc, int backRef, uint backMask) +{ + return getOrCreateImpl(StencilTest(frontFunc, frontRef, frontMask, + backFunc, backRef, backMask)); +} + +StencilTest::StencilTest(GLenum frontFunc, int frontRef, uint frontMask, GLenum backFunc, int backRef, uint backMask) + : GenericState6<StencilTest, GLenum, int, uint, GLenum, int, uint>(frontFunc, frontRef, frontMask, + backFunc, backRef, backMask) +{ +} + +void StencilTest::apply(GraphicsContext *gc) const +{ + gc->openGLContext()->functions()->glEnable(GL_STENCIL_TEST); + gc->openGLContext()->functions()->glStencilFuncSeparate(GL_FRONT, m_1, m_2, m_3); + gc->openGLContext()->functions()->glStencilFuncSeparate(GL_BACK, m_4, m_5, m_6); +} + +AlphaCoverage::AlphaCoverage() + : RenderState() +{ +} + +void AlphaCoverage::apply(GraphicsContext *gc) const +{ + gc->enableAlphaCoverage(); +} + +AlphaCoverage *AlphaCoverage::getOrCreate() +{ + return getOrCreateImpl(AlphaCoverage()); +} + +void PolygonOffset::apply(GraphicsContext *gc) const +{ + gc->openGLContext()->functions()->glEnable(GL_POLYGON_OFFSET_FILL); + gc->openGLContext()->functions()->glPolygonOffset(m_1, m_2); +} + +PolygonOffset *PolygonOffset::getOrCreate(GLfloat factor, GLfloat units) +{ + return getOrCreateImpl(PolygonOffset(factor, units)); +} + +PolygonOffset::PolygonOffset(GLfloat factor, GLfloat units) + : GenericState2<PolygonOffset, GLfloat, GLfloat>(factor, units) +{ +} + +void ColorMask::apply(GraphicsContext *gc) const +{ + gc->openGLContext()->functions()->glColorMask(m_1, m_2, m_3, m_4); +} + +ColorMask::ColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha) + : GenericState4<ColorMask, GLboolean, GLboolean, GLboolean, GLboolean>(red, green, blue, alpha) +{ +} + +ColorMask *ColorMask::getOrCreate(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha) +{ + return getOrCreateImpl(ColorMask(red, green, blue, alpha)); +} + +void BlendStateSeparate::apply(GraphicsContext *gc) const +{ + gc->openGLContext()->functions()->glEnable(GL_BLEND); + gc->openGLContext()->functions()->glBlendFuncSeparate(m_1, m_2, m_3, m_4); +} + +BlendStateSeparate *BlendStateSeparate::getOrCreate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha) +{ + return getOrCreateImpl(BlendStateSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha)); +} + +BlendStateSeparate::BlendStateSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha) + : GenericState4<BlendStateSeparate, GLenum, GLenum, GLenum, GLenum>(srcRGB, dstRGB, srcAlpha, dstAlpha) +{ +} + +void ClipPlane::apply(GraphicsContext *gc) const +{ + gc->enableClipPlane(m_1); +} + +ClipPlane::ClipPlane(int plane) + : GenericState1<ClipPlane, int>(plane) +{ +} + +ClipPlane *ClipPlane::getOrCreate(int plane) +{ + return getOrCreateImpl(ClipPlane(plane)); +} + +void StencilOp::apply(GraphicsContext *gc) const +{ + gc->openGLContext()->functions()->glStencilOpSeparate(GL_FRONT, m_1, m_2, m_3); + gc->openGLContext()->functions()->glStencilOpSeparate(GL_BACK, m_4, m_5, m_6); +} + +StencilOp *StencilOp::getOrCreate(GLenum fsfail, GLenum fdfail, GLenum fdspass, GLenum bsfail, GLenum bdfail, GLenum bdspass) +{ + return getOrCreateImpl(StencilOp(fsfail, fdfail, fdspass, bsfail, bdfail, bdspass)); +} + +StencilOp::StencilOp(GLenum fsfail, GLenum fdfail, GLenum fdspass, GLenum bsfail, GLenum bdfail, GLenum bdspass) + : GenericState6<StencilOp, GLenum, GLenum, GLenum, GLenum, GLenum, GLenum>(fsfail, fdfail, fdspass, bsfail, bdfail, bdspass) +{ +} + +void StencilMask::apply(GraphicsContext *gc) const +{ + gc->openGLContext()->functions()->glStencilMaskSeparate(GL_FRONT, m_1); + gc->openGLContext()->functions()->glStencilMaskSeparate(GL_BACK, m_2); +} + +StencilMask *StencilMask::getOrCreate(uint frontMask, uint backMask) +{ + return getOrCreateImpl(StencilMask(frontMask, backMask)); +} + +StencilMask::StencilMask(uint frontMask, uint backMask) + : GenericState2<StencilMask, uint, uint>(frontMask, backMask) +{ +} + +} // namespace Render +} // namespace Qt3DRender + +QT_END_NAMESPACE diff --git a/src/render/renderstates/renderstates.pri b/src/render/renderstates/renderstates.pri new file mode 100644 index 000000000..dc5684230 --- /dev/null +++ b/src/render/renderstates/renderstates.pri @@ -0,0 +1,50 @@ +INCLUDEPATH += $$PWD + +HEADERS += \ + $$PWD/genericstate_p.h \ + $$PWD/qalphacoverage.h \ + $$PWD/qalphatest.h \ + $$PWD/qblendequation.h \ + $$PWD/qblendstate.h \ + $$PWD/qclipplane.h \ + $$PWD/qcolormask.h \ + $$PWD/qcullface.h \ + $$PWD/qdepthmask.h \ + $$PWD/qdepthtest.h \ + $$PWD/qdithering.h \ + $$PWD/qfrontface.h \ + $$PWD/qpolygonoffset.h \ + $$PWD/qrenderstate.h \ + $$PWD/qrenderstate_p.h \ + $$PWD/qscissortest.h \ + $$PWD/qstencilmask.h \ + $$PWD/qstencilop.h \ + $$PWD/qstencilopseparate.h \ + $$PWD/qstenciltest.h \ + $$PWD/qstenciltestseparate.h \ + $$PWD/renderstates_p.h \ + $$PWD/renderstateset_p.h + + +SOURCES += \ + $$PWD/qalphacoverage.cpp \ + $$PWD/qalphatest.cpp \ + $$PWD/qblendequation.cpp \ + $$PWD/qblendstate.cpp \ + $$PWD/qclipplane.cpp \ + $$PWD/qcolormask.cpp \ + $$PWD/qcullface.cpp \ + $$PWD/qdepthmask.cpp \ + $$PWD/qdepthtest.cpp \ + $$PWD/qdithering.cpp \ + $$PWD/qfrontface.cpp \ + $$PWD/qpolygonoffset.cpp \ + $$PWD/qrenderstate.cpp \ + $$PWD/qscissortest.cpp \ + $$PWD/qstencilmask.cpp \ + $$PWD/qstencilop.cpp \ + $$PWD/qstencilopseparate.cpp \ + $$PWD/qstenciltest.cpp \ + $$PWD/qstenciltestseparate.cpp \ + $$PWD/renderstates.cpp \ + $$PWD/renderstateset.cpp diff --git a/src/render/renderstates/renderstates_p.h b/src/render/renderstates/renderstates_p.h new file mode 100644 index 000000000..2b0baafef --- /dev/null +++ b/src/render/renderstates/renderstates_p.h @@ -0,0 +1,282 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies). +** 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_RENDER_RENDERSTATES_H +#define QT3DRENDER_RENDER_RENDERSTATES_H + +#include <Qt3DRenderer/private/genericstate_p.h> + +#include <QOpenGLContext> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { +namespace Render { + +class Q_AUTOTEST_EXPORT BlendState : public GenericState2<BlendState, GLenum, GLenum> +{ +public: + virtual void apply(GraphicsContext *gc) const Q_DECL_OVERRIDE; + virtual StateMaskSet mask() const Q_DECL_OVERRIDE + { return BlendStateMask; } + + static BlendState *getOrCreate(GLenum src, GLenum dst); +private: + BlendState(GLenum src, GLenum dst); +}; + +class Q_AUTOTEST_EXPORT BlendStateSeparate : public GenericState4<BlendStateSeparate, GLenum, GLenum, GLenum, GLenum> +{ +public: + virtual void apply(GraphicsContext *gc) const Q_DECL_OVERRIDE; + virtual StateMaskSet mask() const Q_DECL_OVERRIDE + { return BlendStateMask; } + + static BlendStateSeparate *getOrCreate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); +private: + BlendStateSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); +}; + +class Q_AUTOTEST_EXPORT BlendEquation : public GenericState1<BlendEquation, GLenum> +{ +public: + virtual void apply(GraphicsContext *gc) const Q_DECL_OVERRIDE; + + virtual StateMaskSet mask() const Q_DECL_OVERRIDE + { return BlendStateMask; } + + static BlendEquation *getOrCreate(GLenum func); + +private: + BlendEquation(GLenum func); +}; + + +class Q_AUTOTEST_EXPORT AlphaFunc : public GenericState2<AlphaFunc, GLenum, GLclampf> +{ +public: + virtual void apply(GraphicsContext *gc) const Q_DECL_OVERRIDE; + + virtual StateMaskSet mask() const Q_DECL_OVERRIDE + { return AlphaTestMask; } + + static AlphaFunc *getOrCreate(GLenum func, GLclampf value); +private: + AlphaFunc(GLenum func, GLclampf value); +}; + +class Q_AUTOTEST_EXPORT DepthTest : public GenericState1<DepthTest, GLenum> +{ +public: + virtual void apply(GraphicsContext *gc) const Q_DECL_OVERRIDE; + + virtual StateMaskSet mask() const Q_DECL_OVERRIDE + { return DepthTestStateMask; } + + static DepthTest *getOrCreate(GLenum func); + +private: + DepthTest(GLenum func); +}; + +class Q_AUTOTEST_EXPORT DepthMask : public GenericState1<DepthMask, GLboolean> +{ +public: + virtual void apply(GraphicsContext *gc) const Q_DECL_OVERRIDE; + + virtual StateMaskSet mask() const Q_DECL_OVERRIDE + { return DepthWriteStateMask; } + + static DepthMask *getOrCreate(GLboolean func); + +private: + DepthMask(GLboolean func); +}; + +class Q_AUTOTEST_EXPORT CullFace : public GenericState1<CullFace, GLenum> +{ +public: + virtual void apply(GraphicsContext *gc) const Q_DECL_OVERRIDE; + + virtual StateMaskSet mask() const Q_DECL_OVERRIDE + { return CullFaceStateMask; } + + static CullFace *getOrCreate(GLenum func); + +private: + CullFace(GLenum func); +}; + +class Q_AUTOTEST_EXPORT FrontFace : public GenericState1<FrontFace, GLenum> +{ +public: + virtual void apply(GraphicsContext *gc) const Q_DECL_OVERRIDE; + + virtual StateMaskSet mask() const Q_DECL_OVERRIDE + { return FrontFaceStateMask; } + static FrontFace *getOrCreate(GLenum func); + +private: + FrontFace(GLenum func); +}; + +class Q_AUTOTEST_EXPORT Dithering : public RenderState +{ +public: + virtual void apply(GraphicsContext *gc) const Q_DECL_OVERRIDE; + virtual StateMaskSet mask() const Q_DECL_OVERRIDE + { return DitheringStateMask; } + + bool isEqual(const Dithering &) { return true; } + + static Dithering *getOrCreate(); +private: + Dithering(); +}; + +class Q_AUTOTEST_EXPORT ScissorTest : public GenericState4<ScissorTest, int, int, int, int> +{ +public: + virtual void apply(GraphicsContext *gc) const Q_DECL_OVERRIDE; + virtual StateMaskSet mask() const Q_DECL_OVERRIDE + { return ScissorStateMask; } + + static ScissorTest *getOrCreate(int left, int bottom, int width, int height); + +private: + ScissorTest(int left, int bottom, int width, int height); +}; + +class Q_AUTOTEST_EXPORT StencilTest : public GenericState6<StencilTest, GLenum, int, uint, GLenum, int, uint> +{ +public: + virtual void apply(GraphicsContext *gc) const Q_DECL_OVERRIDE; + virtual StateMaskSet mask() const Q_DECL_OVERRIDE + { return StencilTestStateMask; } + static StencilTest *getOrCreate(GLenum frontFunc, int frontRef, uint frontMask, GLenum backFunc, int backRef, uint backMask); + +private: + StencilTest(GLenum frontFunc, int frontRef, uint frontMask, GLenum backFunc, int backRef, uint backMask); +}; + +class Q_AUTOTEST_EXPORT AlphaCoverage : public RenderState +{ +public: + void apply(GraphicsContext *gc) const Q_DECL_OVERRIDE; + StateMaskSet mask() const Q_DECL_OVERRIDE + { return AlphaCoverageStateMask; } + + bool isEqual(const AlphaCoverage &) { return true; } + + static AlphaCoverage *getOrCreate(); + +private: + AlphaCoverage(); +}; + +class Q_AUTOTEST_EXPORT PolygonOffset : public GenericState2<PolygonOffset, GLfloat, GLfloat> +{ +public: + void apply(GraphicsContext *gc) const Q_DECL_OVERRIDE; + StateMaskSet mask() const Q_DECL_OVERRIDE + { return PolygonOffsetStateMask; } + + static PolygonOffset *getOrCreate(GLfloat factor, GLfloat units); + +private: + PolygonOffset(GLfloat factor, GLfloat units); +}; + +class Q_AUTOTEST_EXPORT ColorMask : public GenericState4<ColorMask, GLboolean, GLboolean, GLboolean, GLboolean> +{ +public: + void apply(GraphicsContext *gc) const Q_DECL_FINAL; + StateMaskSet mask() const Q_DECL_FINAL { return ColorStateMask; } + + static ColorMask *getOrCreate(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); + +private: + ColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); +}; + +class Q_AUTOTEST_EXPORT ClipPlane : public GenericState1<ClipPlane, int> +{ +public: + void apply(GraphicsContext *gc) const Q_DECL_FINAL; + + StateMaskSet mask() const Q_DECL_FINAL + { return ClipPlaneMask; } + static ClipPlane *getOrCreate(int plane); + +private: + ClipPlane(int plane); +}; + +class Q_AUTOTEST_EXPORT StencilOp : public GenericState6<StencilOp, GLenum, GLenum, GLenum, GLenum, GLenum, GLenum> +{ +public: + void apply(GraphicsContext *gc) const Q_DECL_FINAL; + + StateMaskSet mask() const Q_DECL_FINAL + { return StencilOpMask; } + static StencilOp *getOrCreate(GLenum fsfail, GLenum fdfail, GLenum fdspass, + GLenum bsfail, GLenum bdfail, GLenum bdspass); + +private: + StencilOp(GLenum fsfail, GLenum fdfail, GLenum fdspass, + GLenum bsfail, GLenum bdfail, GLenum bdspass); +}; + +class Q_AUTOTEST_EXPORT StencilMask : public GenericState2<StencilMask, uint, uint> +{ +public: + void apply(GraphicsContext *gc) const Q_DECL_FINAL; + + StateMaskSet mask() const Q_DECL_FINAL + { return StencilWriteStateMask; } + static StencilMask *getOrCreate(uint frontMask, uint backMask); + +private: + StencilMask(uint frontMask, uint backMask); +}; + +} // namespace Render +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_RENDER_RENDERSTATES_H diff --git a/src/render/renderstates/renderstateset.cpp b/src/render/renderstates/renderstateset.cpp new file mode 100644 index 000000000..3da5e37ef --- /dev/null +++ b/src/render/renderstates/renderstateset.cpp @@ -0,0 +1,336 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies). +** 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 "renderstateset_p.h" + +#include <bitset> + +#include <QDebug> +#include <QOpenGLContext> + +#include <Qt3DRenderer/private/graphicscontext_p.h> +#include <Qt3DRenderer/private/renderstates_p.h> + +#include <Qt3DRenderer/qalphacoverage.h> +#include <Qt3DRenderer/qalphatest.h> +#include <Qt3DRenderer/qblendequation.h> +#include <Qt3DRenderer/qblendstate.h> +#include <Qt3DRenderer/qcolormask.h> +#include <Qt3DRenderer/qcullface.h> +#include <Qt3DRenderer/qdepthmask.h> +#include <Qt3DRenderer/qdepthtest.h> +#include <Qt3DRenderer/qdithering.h> +#include <Qt3DRenderer/qfrontface.h> +#include <Qt3DRenderer/qpolygonoffset.h> +#include <Qt3DRenderer/qscissortest.h> +#include <Qt3DRenderer/qstenciltest.h> +#include <Qt3DRenderer/qstenciltestseparate.h> +#include <Qt3DRenderer/qclipplane.h> +#include <Qt3DRenderer/qstencilop.h> +#include <Qt3DRenderer/qstencilopseparate.h> +#include <Qt3DRenderer/qstencilmask.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { +namespace Render { + +RenderStateSet::RenderStateSet() + : m_stateMask(0) + , m_cachedPrevious(0) +{ +} + +RenderStateSet::~RenderStateSet() +{ +} + +void RenderStateSet::addState(RenderState *ds) +{ + Q_ASSERT(ds); + m_states.append(ds); + m_stateMask |= ds->mask(); +} + +int RenderStateSet::changeCost(RenderStateSet *previousState) +{ + if (previousState == this) + return 0; + + int cost = 0; + + // first, find cost of any resets + StateMaskSet invOurState = ~stateMask(); + StateMaskSet stateToReset = previousState->stateMask() & invOurState; + + std::bitset<64> bs(stateToReset); + cost += int(bs.count()); + + // now, find out how many states we're changing + Q_FOREACH (RenderState* ds, m_states) { + // if the other state contains matching, then doesn't + // contribute to cost at all + if (previousState->contains(ds)) { + continue; + } + + // flat cost for now; could be replaced with a cost() method on + // RenderState + cost += 2; + } + + return cost; +} + +void RenderStateSet::apply(GraphicsContext *gc) +{ + RenderStateSet* previousStates = gc->currentStateSet(); + + const StateMaskSet invOurState = ~stateMask(); + // generate a mask for each set bit in previous, where we do not have + // the corresponding bit set. + + StateMaskSet stateToReset = 0; + if (previousStates) { + stateToReset = previousStates->stateMask() & invOurState; + qCDebug(RenderStates) << "previous states " << QString::number(previousStates->stateMask(), 2); + } + qCDebug(RenderStates) << " current states " << QString::number(stateMask(), 2) << "inverse " << QString::number(invOurState, 2) << " -> states to change: " << QString::number(stateToReset, 2); + + resetMasked(stateToReset, gc); + + if (m_cachedPrevious && previousStates == m_cachedPrevious) { + // state-change cache hit + foreach (RenderState* ds, m_cachedDeltaStates) { + ds->apply(gc); + } + } else { + // compute deltas and cache for next frame + m_cachedDeltaStates.clear(); + m_cachedPrevious = previousStates; + + Q_FOREACH (RenderState* ds, m_states) { + if (previousStates && previousStates->contains(ds)) { + continue; + } + + m_cachedDeltaStates.append(ds); + ds->apply(gc); + } + } +} + +StateMaskSet RenderStateSet::stateMask() const +{ + return m_stateMask; +} + +void RenderStateSet::merge(RenderStateSet *other) +{ + m_stateMask |= other->stateMask(); +} + +void RenderStateSet::resetMasked(StateMaskSet maskOfStatesToReset, GraphicsContext *gc) +{ + // TO DO -> Call gcHelper methods instead of raw GL + // QOpenGLFunctions shouldn't be used here directly + QOpenGLFunctions *funcs = gc->openGLContext()->functions(); + + if (maskOfStatesToReset & ScissorStateMask) { + funcs->glDisable(GL_SCISSOR_TEST); + } + + if (maskOfStatesToReset & BlendStateMask) { + funcs->glDisable(GL_BLEND); + } + + if (maskOfStatesToReset & StencilWriteStateMask) { + funcs->glStencilMask(0); + } + + if (maskOfStatesToReset & StencilTestStateMask) { + funcs->glDisable(GL_STENCIL_TEST); + } + + if (maskOfStatesToReset & DepthTestStateMask) { + funcs->glDisable(GL_DEPTH_TEST); + } + + if (maskOfStatesToReset & DepthWriteStateMask) { + funcs->glDepthMask(GL_TRUE); // reset to default + } + + if (maskOfStatesToReset & FrontFaceStateMask) { + funcs->glFrontFace(GL_CCW); // reset to default + } + + if (maskOfStatesToReset & CullFaceStateMask) { + funcs->glDisable(GL_CULL_FACE); + } + + if (maskOfStatesToReset & DitheringStateMask) { + funcs->glDisable(GL_DITHER); + } + + if (maskOfStatesToReset & AlphaCoverageStateMask) { + gc->disableAlphaCoverage(); + } + + if (maskOfStatesToReset & PolygonOffsetStateMask) { + funcs->glDisable(GL_POLYGON_OFFSET_FILL); + } + + if (maskOfStatesToReset & ColorStateMask) { + funcs->glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); + } + + if (maskOfStatesToReset & ClipPlaneMask) { + GLint max = gc->maxClipPlaneCount(); + for (GLint i = 0; i < max; ++i) + gc->disableClipPlane(i); + } + + if (maskOfStatesToReset & StencilOpMask) { + funcs->glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); + } +} + +bool RenderStateSet::contains(RenderState *ds) const +{ + // trivial reject using the state mask bits + if (!(ds->mask() & stateMask())) + return false; + + return m_states.contains(ds); +} + +RenderState *RenderState::getOrCreateBackendState(QRenderState *renderState) +{ + switch (renderState->type()) { + case QRenderState::AlphaTest: { + QAlphaTest *alphaTest = static_cast<QAlphaTest *>(renderState); + return AlphaFunc::getOrCreate(alphaTest->func(), alphaTest->clamp()); + } + case QRenderState::BlendEquation: { + QBlendEquation *blendEquation = static_cast<QBlendEquation *>(renderState); + return BlendEquation::getOrCreate(blendEquation->mode()); + } + case QRenderState::BlendState: { + QBlendState *blendState = static_cast<QBlendState *>(renderState); + return BlendState::getOrCreate(blendState->srcRGB(), blendState->dstRGB()); + } + case QRenderState::BlendStateSeparate: { + QBlendState *blendState = static_cast<QBlendState *>(renderState); + return BlendStateSeparate::getOrCreate(blendState->srcRGB(), blendState->dstRGB(), blendState->srcAlpha(), blendState->dstAlpha()); + } + case QRenderState::CullFace: { + QCullFace *cullFace = static_cast<QCullFace *>(renderState); + return CullFace::getOrCreate(cullFace->mode()); + } + case QRenderState::DepthMask: { + QDepthMask *depthMask = static_cast<QDepthMask *>(renderState); + return DepthMask::getOrCreate(depthMask->mask()); + } + case QRenderState::DepthTest: { + QDepthTest *depthTest = static_cast<QDepthTest *>(renderState); + return DepthTest::getOrCreate(depthTest->func()); + } + case QRenderState::Dithering: { + return Dithering::getOrCreate(); + } + case QRenderState::FrontFace: { + QFrontFace *frontFace = static_cast<QFrontFace *>(renderState); + return FrontFace::getOrCreate(frontFace->direction()); + } + case QRenderState::ScissorTest: { + QScissorTest *scissorTest = static_cast<QScissorTest *>(renderState); + return ScissorTest::getOrCreate(scissorTest->left(), + scissorTest->bottom(), + scissorTest->width(), + scissorTest->height()); + } + case QRenderState::StencilTest: { + QStencilTest *stencilTest = static_cast<QStencilTest *>(renderState); + return StencilTest::getOrCreate(stencilTest->front()->func(), + stencilTest->front()->ref(), + stencilTest->front()->mask(), + stencilTest->back()->func(), + stencilTest->back()->ref(), + stencilTest->back()->mask()); + } + case QRenderState::AlphaCoverage: { + return AlphaCoverage::getOrCreate(); + } + case QRenderState::PolygonOffset: { + QPolygonOffset *polygonOffset = static_cast<QPolygonOffset *>(renderState); + return PolygonOffset::getOrCreate(polygonOffset->factor(), + polygonOffset->units()); + } + case QRenderState::ColorMask: { + QColorMask *colorMask = static_cast<QColorMask *>(renderState); + return ColorMask::getOrCreate(colorMask->isRed(), + colorMask->isGreen(), + colorMask->isBlue(), + colorMask->isAlpha()); + } + case QRenderState::ClipPlane: { + QClipPlane *clipPlane = static_cast<QClipPlane *>(renderState); + return ClipPlane::getOrCreate(clipPlane->plane()); + } + case QRenderState::StencilOp: { + QStencilOp *stencilOp = static_cast<QStencilOp *>(renderState); + const QStencilOpSeparate *front = stencilOp->front(); + const QStencilOpSeparate *back = stencilOp->back(); + return StencilOp::getOrCreate(front->stencilFail(), front->depthFail(), front->stencilDepthPass(), + back->stencilFail(), back->depthFail(), back->stencilDepthPass()); + } + case QRenderState::StencilMask: { + QStencilMask *stencilMask = static_cast<QStencilMask *>(renderState); + return StencilMask::getOrCreate(stencilMask->frontMask(), stencilMask->backMask()); + } + + default: + Q_UNREACHABLE(); + qFatal("Should not happen"); + return Q_NULLPTR; + } +} + +} // namespace Render +} // namespace Qt3DRender + +QT_END_NAMESPACE diff --git a/src/render/renderstates/renderstateset_p.h b/src/render/renderstates/renderstateset_p.h new file mode 100644 index 000000000..7a2f54000 --- /dev/null +++ b/src/render/renderstates/renderstateset_p.h @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies). +** 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_RENDER_RENDERSTATE_H +#define QT3DRENDER_RENDER_RENDERSTATE_H + +#include <Qt3DRenderer/private/genericstate_p.h> +#include <QVector> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QRenderState; + +namespace Render { + +class GraphicsContext; +class RenderState; + +class RenderStateSet +{ +public: + RenderStateSet(); + ~RenderStateSet(); + + void addState(RenderState* ds); + + /** + * @brief changeCost - metric of cost to change to this state-set from + * a candidate previous state-set. This is used to find an optimal + * ordering of state-sets when sending draw commands. + * @param previousState + * @return + */ + int changeCost(RenderStateSet* previousState); + + void apply(GraphicsContext* gc); + + StateMaskSet stateMask() const; + void merge(RenderStateSet *other); + void resetMasked(StateMaskSet maskOfStatesToReset, GraphicsContext* gc); +private: + /** + * @brief contains - check if this set contains a matching piece of state + * @param ds + * @return + */ + bool contains(RenderState* ds) const; + + QVector<RenderState*> m_states; + + StateMaskSet m_stateMask; + + RenderStateSet* m_cachedPrevious; + QVector<RenderState*> m_cachedDeltaStates; +}; + +} // namespace Render +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_RENDER_RENDERSTATE_H |