diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2015-01-14 14:41:58 +0100 |
---|---|---|
committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2015-01-16 13:09:14 +0100 |
commit | 7f92bdb14e49078c1744c26f4336a2b6f6d396f9 (patch) | |
tree | ff51f0891bdd850332d2574f8d832b8c748e2a49 | |
parent | 76c27318f47aed108afcc8ac57a2a22ca8de9c03 (diff) |
Introduce the "polygon offset" render state
Change-Id: Ia1705727b362945a26015763ef9e8c749437d9b6
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
-rw-r--r-- | src/quick3d/imports/render/qt3dquick3drenderplugin.cpp | 2 | ||||
-rw-r--r-- | src/render/backend/jobs/renderviewjobutils.cpp | 6 | ||||
-rw-r--r-- | src/render/backend/renderstate_p.h | 3 | ||||
-rw-r--r-- | src/render/backend/states/blendstate.cpp | 16 | ||||
-rw-r--r-- | src/render/backend/states/blendstate_p.h | 13 | ||||
-rw-r--r-- | src/render/frontend/qpolygonoffset.cpp | 110 | ||||
-rw-r--r-- | src/render/frontend/qpolygonoffset.h | 85 | ||||
-rw-r--r-- | src/render/frontend/render-frontend.pri | 6 |
8 files changed, 238 insertions, 3 deletions
diff --git a/src/quick3d/imports/render/qt3dquick3drenderplugin.cpp b/src/quick3d/imports/render/qt3dquick3drenderplugin.cpp index 4ca89b267..36cddc3c8 100644 --- a/src/quick3d/imports/render/qt3dquick3drenderplugin.cpp +++ b/src/quick3d/imports/render/qt3dquick3drenderplugin.cpp @@ -87,6 +87,7 @@ #include <Qt3DRenderer/qclearbuffer.h> #include <Qt3DRenderer/qsortcriterion.h> #include <Qt3DRenderer/qalphacoverage.h> +#include <Qt3DRenderer/qpolygonoffset.h> #include <Qt3DRenderer/qshaderdata.h> #include <Qt3DQuickRenderer/quick3dtechnique.h> #include <Qt3DQuickRenderer/quick3dmaterial.h> @@ -235,6 +236,7 @@ void Qt3DQuick3DRenderPlugin::registerTypes(const char *uri) qmlRegisterType<Qt3D::QScissorTest>(uri, 2, 0, "ScissorTest"); qmlRegisterType<Qt3D::QDithering>(uri, 2, 0, "Dithering"); qmlRegisterType<Qt3D::QAlphaCoverage>(uri, 2, 0, "AlphaCoverage"); + qmlRegisterType<Qt3D::QPolygonOffset>(uri, 2, 0, "PolygonOffset"); // Register types provided as QML files compiled into the plugin for (int i = 0; i < int(sizeof(qmldir) / sizeof(qmldir[0])); i++) { diff --git a/src/render/backend/jobs/renderviewjobutils.cpp b/src/render/backend/jobs/renderviewjobutils.cpp index 44f5d6227..00ae1aff7 100644 --- a/src/render/backend/jobs/renderviewjobutils.cpp +++ b/src/render/backend/jobs/renderviewjobutils.cpp @@ -51,6 +51,7 @@ #include <Qt3DRenderer/qdithering.h> #include <Qt3DRenderer/qfrontface.h> #include <Qt3DRenderer/qopenglfilter.h> +#include <Qt3DRenderer/qpolygonoffset.h> #include <Qt3DRenderer/qscissortest.h> #include <Qt3DRenderer/qstenciltest.h> #include <Qt3DRenderer/sphere.h> @@ -438,6 +439,11 @@ RenderStateSet *buildRenderStateSet(RenderRenderPass *pass, QFrameAllocator *all else if (qobject_cast<QAlphaCoverage *>(renderState) != Q_NULLPTR) { stateSet->addState(AlphaCoverage::getOrCreate()); } + else if (qobject_cast<QPolygonOffset *>(renderState) != Q_NULLPTR) { + QPolygonOffset *polygonOffset = qobject_cast<QPolygonOffset *>(renderState); + stateSet->addState(PolygonOffset::getOrCreate(polygonOffset->factor(), + polygonOffset->units())); + } } return stateSet; diff --git a/src/render/backend/renderstate_p.h b/src/render/backend/renderstate_p.h index a34eb540f..c514f6bc7 100644 --- a/src/render/backend/renderstate_p.h +++ b/src/render/backend/renderstate_p.h @@ -65,7 +65,8 @@ enum StateMask AlphaTestMask = 1 << 7, FrontFaceStateMask = 1 << 8, DitheringStateMask = 1 << 9, - AlphaCoverageStateMask = 1 << 10 + AlphaCoverageStateMask = 1 << 10, + PolygonOffsetStateMask = 1 << 11 }; typedef quint64 StateMaskSet; diff --git a/src/render/backend/states/blendstate.cpp b/src/render/backend/states/blendstate.cpp index b73102e8b..fc33d8145 100644 --- a/src/render/backend/states/blendstate.cpp +++ b/src/render/backend/states/blendstate.cpp @@ -242,6 +242,22 @@ AlphaCoverage *AlphaCoverage::getOrCreate() return getOrCreateImpl(AlphaCoverage()); } +void PolygonOffset::apply(QGraphicsContext *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(factor, units) +{ +} + } // Render } // Qt3D diff --git a/src/render/backend/states/blendstate_p.h b/src/render/backend/states/blendstate_p.h index 34dd3b6fc..0c5fd09b7 100644 --- a/src/render/backend/states/blendstate_p.h +++ b/src/render/backend/states/blendstate_p.h @@ -201,6 +201,19 @@ private: AlphaCoverage(); }; +class PolygonOffset : public GenericState2<PolygonOffset, GLfloat, GLfloat> +{ +public: + void apply(QGraphicsContext *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); +}; + } // Render } // Qt3D diff --git a/src/render/frontend/qpolygonoffset.cpp b/src/render/frontend/qpolygonoffset.cpp new file mode 100644 index 000000000..25403fa4b --- /dev/null +++ b/src/render/frontend/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:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 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 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qpolygonoffset.h" +#include <private/qrenderstate_p.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3D { + +class QPolygonOffsetPrivate : public QRenderStatePrivate +{ +public: + QPolygonOffsetPrivate(QPolygonOffset *qq) + : QRenderStatePrivate(qq) + , m_factor(0) + , m_units(0) + { + } + + float m_factor; + float m_units; + + Q_DECLARE_PUBLIC(QPolygonOffset) +}; + +QPolygonOffset::QPolygonOffset(QNode *parent) + : QRenderState(*new QPolygonOffsetPrivate(this), parent) +{ +} + +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; +} + +} // Qt3D + +QT_END_NAMESPACE diff --git a/src/render/frontend/qpolygonoffset.h b/src/render/frontend/qpolygonoffset.h new file mode 100644 index 000000000..083273093 --- /dev/null +++ b/src/render/frontend/qpolygonoffset.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** 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:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 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 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT3D_QPOLYGONOFFSET_H +#define QT3D_QPOLYGONOFFSET_H + +#include <Qt3DRenderer/qrenderstate.h> +#include <QtGui/qopengl.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3D { + +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(QNode *parent = Q_NULLPTR); + + 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 QNode *ref) Q_DECL_OVERRIDE; + +private: + Q_DECLARE_PRIVATE(QPolygonOffset) + QT3D_CLONEABLE(QPolygonOffset) +}; + +} // Qt3D + +QT_END_NAMESPACE + +#endif // QT3D_QPOLYGONOFFSET_H diff --git a/src/render/frontend/render-frontend.pri b/src/render/frontend/render-frontend.pri index 54a37715e..6d3a1bc9b 100644 --- a/src/render/frontend/render-frontend.pri +++ b/src/render/frontend/render-frontend.pri @@ -65,7 +65,8 @@ HEADERS += \ $$PWD/qparametermapping_p.h \ $$PWD/qparametermapping.h \ $$PWD/qshaderdata.h \ - $$PWD/qshaderdata_p.h + $$PWD/qshaderdata_p.h \ + $$PWD/qpolygonoffset.h SOURCES += \ $$PWD/qmaterial.cpp \ @@ -108,4 +109,5 @@ SOURCES += \ $$PWD/qannotation.cpp \ $$PWD/qabstractmesh.cpp \ $$PWD/qparametermapping.cpp \ - $$PWD/qshaderdata.cpp + $$PWD/qshaderdata.cpp \ + $$PWD/qpolygonoffset.cpp |