| 1 | /**************************************************************************** | 
| 2 | ** | 
| 3 | ** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB). | 
| 4 | ** Contact: https://www.qt.io/licensing/ | 
| 5 | ** | 
| 6 | ** This file is part of the Qt3D module of the Qt Toolkit. | 
| 7 | ** | 
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | 
| 9 | ** Commercial License Usage | 
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | 
| 11 | ** accordance with the commercial license agreement provided with the | 
| 12 | ** Software or, alternatively, in accordance with the terms contained in | 
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | 
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | 
| 15 | ** information use the contact form at https://www.qt.io/contact-us. | 
| 16 | ** | 
| 17 | ** GNU Lesser General Public License Usage | 
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | 
| 19 | ** General Public License version 3 as published by the Free Software | 
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | 
| 21 | ** packaging of this file. Please review the following information to | 
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | 
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | 
| 24 | ** | 
| 25 | ** GNU General Public License Usage | 
| 26 | ** Alternatively, this file may be used under the terms of the GNU | 
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | 
| 28 | ** Public license version 3 or any later version approved by the KDE Free | 
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | 
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | 
| 31 | ** included in the packaging of this file. Please review the following | 
| 32 | ** information to ensure the GNU General Public License requirements will | 
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | 
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | 
| 35 | ** | 
| 36 | ** $QT_END_LICENSE$ | 
| 37 | ** | 
| 38 | ****************************************************************************/ | 
| 39 |  | 
| 40 | #include "qclipplane.h" | 
| 41 | #include "qclipplane_p.h" | 
| 42 | #include <Qt3DRender/private/qrenderstatecreatedchange_p.h> | 
| 43 |  | 
| 44 | QT_BEGIN_NAMESPACE | 
| 45 |  | 
| 46 | namespace Qt3DRender { | 
| 47 |  | 
| 48 | /*! | 
| 49 |     \class Qt3DRender::QClipPlane | 
| 50 |     \inmodule Qt3DRender | 
| 51 |     \since 5.5 | 
| 52 |     \brief Enables an additional OpenGL clipping plane that can be in shaders | 
| 53 |     using gl_ClipDistance. | 
| 54 |  | 
| 55 |     By default, OpenGL supports up to 8 additional clipping planes. | 
| 56 |     Qt3DCore::QClipPlane allows to enable one of these additional planes. These | 
| 57 |     planes can then be manipulated in the shaders using gl_ClipDistance[i] | 
| 58 |     where i varies between 0 and 7. The underlying implementation may support more | 
| 59 |     than 8 clip planes, but it is not guaranteed. | 
| 60 |  */ | 
| 61 |  | 
| 62 | /*! | 
| 63 |     \qmltype ClipPlane | 
| 64 |     \instantiates Qt3DRender::QClipPlane | 
| 65 |     \inherits RenderState | 
| 66 |     \inqmlmodule Qt3D.Render | 
| 67 |     \since 5.5 | 
| 68 |     \brief Enables an additional OpenGL clipping plane that can be in shaders | 
| 69 |     using gl_ClipDistance. | 
| 70 |  | 
| 71 |     By default, OpenGL supports up to 8 additional clipping planes. ClipPlane | 
| 72 |     allows to enable one of these additional planes. These planes can then be | 
| 73 |     manipulated in the shaders using gl_ClipDistance[i] where i varies between | 
| 74 |     0 and 7. The underlying implementation may support more than 8 clip planes, | 
| 75 |     but it is not guaranteed. | 
| 76 | */ | 
| 77 |  | 
| 78 | /*! | 
| 79 |     \qmlproperty int ClipPlane::planeIndex | 
| 80 |     Holds the index of the plane. | 
| 81 |     \note Usually between 0-7. | 
| 82 | */ | 
| 83 |  | 
| 84 | /*! | 
| 85 |     \qmlproperty vector3d ClipPlane::normal | 
| 86 |     Holds the normal of the plane. | 
| 87 | */ | 
| 88 |  | 
| 89 | /*! | 
| 90 |     \qmlproperty real ClipPlane::distance | 
| 91 |     Holds the distance of the plane from the world origin. | 
| 92 | */ | 
| 93 |  | 
| 94 |  | 
| 95 | /*! | 
| 96 |     \property QClipPlane::planeIndex | 
| 97 |     Holds the index of the plane. | 
| 98 |     \note Usually between 0-7. | 
| 99 | */ | 
| 100 |  | 
| 101 | /*! | 
| 102 |     \property QClipPlane::normal | 
| 103 |     Holds the normal of the plane. | 
| 104 | */ | 
| 105 |  | 
| 106 | /*! | 
| 107 |     \property QClipPlane::distance | 
| 108 |     Holds the distance of the plane from the world origin. | 
| 109 | */ | 
| 110 |  | 
| 111 |  | 
| 112 | QClipPlane::QClipPlane(QNode *parent) | 
| 113 |     : QRenderState(*new QClipPlanePrivate(), parent) | 
| 114 | { | 
| 115 | } | 
| 116 |  | 
| 117 | /*! \internal */ | 
| 118 | QClipPlane::~QClipPlane() | 
| 119 | { | 
| 120 | } | 
| 121 |  | 
| 122 | int QClipPlane::planeIndex() const | 
| 123 | { | 
| 124 |     Q_D(const QClipPlane); | 
| 125 |     return d->m_planeIndex; | 
| 126 | } | 
| 127 |  | 
| 128 | QVector3D QClipPlane::normal() const | 
| 129 | { | 
| 130 |     Q_D(const QClipPlane); | 
| 131 |     return d->m_normal; | 
| 132 | } | 
| 133 |  | 
| 134 | float QClipPlane::distance() const | 
| 135 | { | 
| 136 |     Q_D(const QClipPlane); | 
| 137 |     return d->m_distance; | 
| 138 | } | 
| 139 |  | 
| 140 | void QClipPlane::setPlaneIndex(int planeIndex) | 
| 141 | { | 
| 142 |     Q_D(QClipPlane); | 
| 143 |     if (planeIndex != d->m_planeIndex) { | 
| 144 |         d->m_planeIndex = planeIndex; | 
| 145 |         Q_EMIT planeIndexChanged(planeIndex); | 
| 146 |     } | 
| 147 | } | 
| 148 |  | 
| 149 | void QClipPlane::setNormal(QVector3D normal) | 
| 150 | { | 
| 151 |     Q_D(QClipPlane); | 
| 152 |     if (normal != d->m_normal) { | 
| 153 |         d->m_normal = normal; | 
| 154 |         Q_EMIT normalChanged(normal); | 
| 155 |     } | 
| 156 | } | 
| 157 |  | 
| 158 | void QClipPlane::setDistance(float distance) | 
| 159 | { | 
| 160 |     Q_D(QClipPlane); | 
| 161 |     if (distance != d->m_distance) { | 
| 162 |         d->m_distance = distance; | 
| 163 |         Q_EMIT distanceChanged(distance); | 
| 164 |     } | 
| 165 | } | 
| 166 |  | 
| 167 | Qt3DCore::QNodeCreatedChangeBasePtr QClipPlane::createNodeCreationChange() const | 
| 168 | { | 
| 169 |     auto creationChange = QRenderStateCreatedChangePtr<QClipPlaneData>::create(arguments: this); | 
| 170 |     auto &data = creationChange->data; | 
| 171 |     Q_D(const QClipPlane); | 
| 172 |     data.normal = d->m_normal; | 
| 173 |     data.distance = d->m_distance; | 
| 174 |     data.planeIndex = d->m_planeIndex; | 
| 175 |     return creationChange; | 
| 176 | } | 
| 177 |  | 
| 178 | } // namespace Qt3DRender | 
| 179 |  | 
| 180 | QT_END_NAMESPACE | 
| 181 |  |