diff options
author | Paul Lemire <paul.lemire@kdab.com> | 2015-07-17 15:11:40 +0200 |
---|---|---|
committer | Paul Lemire <paul.lemire@kdab.com> | 2015-07-24 06:17:02 +0000 |
commit | 098b2181e98cf57b56712d7a335a0f3027653ff0 (patch) | |
tree | 88d3527bb1bd098937d91889f5ee6441a6a39659 | |
parent | 9b8cc06c1d0998cf5418d8480d2995bd530da6b1 (diff) |
Add new QClipPlane render state
glEnable(GL_CLIP_DISTANCE0 + i);
Change-Id: Ic102b1d369d74052ddec08b5fc6bc8fee05a3718
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
-rw-r--r-- | src/render/frontend/qclipplane.cpp | 125 | ||||
-rw-r--r-- | src/render/frontend/qclipplane.h | 74 | ||||
-rw-r--r-- | src/render/frontend/qrenderstate.h | 3 | ||||
-rw-r--r-- | src/render/frontend/render-frontend.pri | 6 |
4 files changed, 205 insertions, 3 deletions
diff --git a/src/render/frontend/qclipplane.cpp b/src/render/frontend/qclipplane.cpp new file mode 100644 index 000000000..61f406187 --- /dev/null +++ b/src/render/frontend/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 Qt3D { + +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(); +} + +} // Qt3D + +QT_END_NAMESPACE diff --git a/src/render/frontend/qclipplane.h b/src/render/frontend/qclipplane.h new file mode 100644 index 000000000..a1d6c0db3 --- /dev/null +++ b/src/render/frontend/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 QT3D_QCLIPPLANE_H +#define QT3D_QCLIPPLANE_H + +#include <Qt3DRenderer/qrenderstate.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3D { + +class QClipPlanePrivate; + +class QT3DRENDERERSHARED_EXPORT QClipPlane : public QRenderState +{ + Q_OBJECT + Q_PROPERTY(int plane READ plane WRITE setPlane NOTIFY planeChanged) +public: + explicit QClipPlane(QNode *parent = 0); + ~QClipPlane(); + + int plane() const; + void setPlane(int); + +protected: + void copy(const QNode *ref) Q_DECL_FINAL; + +Q_SIGNALS: + void planeChanged(); + +private: + Q_DECLARE_PRIVATE(QClipPlane) + QT3D_CLONEABLE(QClipPlane) +}; + +} // Qt3D + +QT_END_NAMESPACE + +#endif // QT3D_QCLIPPLANE_H diff --git a/src/render/frontend/qrenderstate.h b/src/render/frontend/qrenderstate.h index 90290f8dc..7cf89cb11 100644 --- a/src/render/frontend/qrenderstate.h +++ b/src/render/frontend/qrenderstate.h @@ -66,7 +66,8 @@ public: FrontFace, PolygonOffset, ScissorTest, - StencilTest + StencilTest, + ClipPlane }; Q_ENUM(Type) diff --git a/src/render/frontend/render-frontend.pri b/src/render/frontend/render-frontend.pri index 34e8249bd..e146ffc82 100644 --- a/src/render/frontend/render-frontend.pri +++ b/src/render/frontend/render-frontend.pri @@ -74,7 +74,8 @@ HEADERS += \ $$PWD/qabstracttextureimage.h \ $$PWD/qabstracttextureimage_p.h \ $$PWD/qtextureimage.h \ - $$PWD/qtextureproviders.h + $$PWD/qtextureproviders.h \ + $$PWD/qclipplane.h SOURCES += \ $$PWD/qmaterial.cpp \ @@ -123,4 +124,5 @@ SOURCES += \ $$PWD/qwrapmode.cpp \ $$PWD/qabstracttextureimage.cpp \ $$PWD/qtextureimage.cpp \ - $$PWD/qtextureproviders.cpp + $$PWD/qtextureproviders.cpp \ + $$PWD/qclipplane.cpp |