| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2019 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 "qdepthrange.h" |
| 41 | #include "qdepthrange_p.h" |
| 42 | #include <Qt3DRender/private/qrenderstatecreatedchange_p.h> |
| 43 | |
| 44 | QT_BEGIN_NAMESPACE |
| 45 | |
| 46 | namespace Qt3DRender { |
| 47 | |
| 48 | /*! |
| 49 | \class Qt3DRender::QDepthRange |
| 50 | \inmodule Qt3DRender |
| 51 | \since 5.14 |
| 52 | \ingroup renderstates |
| 53 | \brief Enables remapping depth values written into the depth buffer. |
| 54 | |
| 55 | By default, OpenGL writes scene depth information into the depth buffer in |
| 56 | the range [0.0, 1.0] with 0.0 corresponding to the near clip plane and 1.0 to |
| 57 | the far clip plane. QDepthRange allows mapping these values into a different |
| 58 | range so parts of the scene are always rendered in front of or behind other |
| 59 | parts. Valid values for near and far are between 0 and 1. |
| 60 | */ |
| 61 | |
| 62 | /*! |
| 63 | \qmltype DepthRange |
| 64 | \instantiates Qt3DRender::QDepthRange |
| 65 | \inherits RenderState |
| 66 | \inqmlmodule Qt3D.Render |
| 67 | \ingroup renderstates |
| 68 | \since 5.14 |
| 69 | \brief Enables remapping depth values written into the depth buffer. |
| 70 | |
| 71 | By default, OpenGL writes scene depth information into the depth buffer in |
| 72 | the range [0.0, 1.0] corresponding to the near and far clip planes. |
| 73 | QDepthRange allows mapping these values into a different range. For example |
| 74 | setting the range [0.0, 0.5] will map the rendered scene into the depth |
| 75 | buffer such that objects at the near clip plane have depth value of 0.0 and |
| 76 | objects at the far clip plane have a depth value of 0.5. This allows |
| 77 | rendering parts of the scene always in front of or behind other parts. |
| 78 | */ |
| 79 | |
| 80 | /*! |
| 81 | \qmlproperty real QDepthRange::nearValue |
| 82 | The depth buffer value corresponding to the near clip plane. Valid values for are |
| 83 | between 0 and 1. |
| 84 | */ |
| 85 | |
| 86 | /*! |
| 87 | \qmlproperty real QDepthRange::farValue |
| 88 | The depth buffer value corresponding to the far clip plane. Valid values for are |
| 89 | between 0 and 1. |
| 90 | */ |
| 91 | |
| 92 | /*! |
| 93 | \property QDepthRange::nearValue |
| 94 | The depth buffer value corresponding to the near clip plane. Valid values for are |
| 95 | between 0 and 1. |
| 96 | */ |
| 97 | |
| 98 | /*! |
| 99 | \property QDepthRange::farValue |
| 100 | The depth buffer value corresponding to the far clip plane. Valid values for are |
| 101 | between 0 and 1. |
| 102 | */ |
| 103 | |
| 104 | QDepthRange::QDepthRange(QNode *parent) |
| 105 | : QRenderState(*new QDepthRangePrivate(), parent) |
| 106 | { |
| 107 | } |
| 108 | |
| 109 | /*! \internal */ |
| 110 | QDepthRange::~QDepthRange() |
| 111 | { |
| 112 | } |
| 113 | |
| 114 | double QDepthRange::nearValue() const |
| 115 | { |
| 116 | Q_D(const QDepthRange); |
| 117 | return d->m_nearValue; |
| 118 | } |
| 119 | |
| 120 | double QDepthRange::farValue() const |
| 121 | { |
| 122 | Q_D(const QDepthRange); |
| 123 | return d->m_farValue; |
| 124 | } |
| 125 | |
| 126 | void QDepthRange::setNearValue(double value) |
| 127 | { |
| 128 | Q_D(QDepthRange); |
| 129 | if (value != d->m_nearValue) { |
| 130 | d->m_nearValue = value; |
| 131 | Q_EMIT nearValueChanged(nearValue: value); |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | void QDepthRange::setFarValue(double value) |
| 136 | { |
| 137 | Q_D(QDepthRange); |
| 138 | if (value != d->m_farValue) { |
| 139 | d->m_farValue = value; |
| 140 | Q_EMIT farValueChanged(farValue: value); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | Qt3DCore::QNodeCreatedChangeBasePtr QDepthRange::createNodeCreationChange() const |
| 145 | { |
| 146 | auto creationChange = QRenderStateCreatedChangePtr<QDepthRangeData>::create(arguments: this); |
| 147 | auto &data = creationChange->data; |
| 148 | Q_D(const QDepthRange); |
| 149 | data.nearValue = d->m_nearValue; |
| 150 | data.farValue = d->m_farValue; |
| 151 | return creationChange; |
| 152 | } |
| 153 | |
| 154 | } // namespace Qt3DRender |
| 155 | |
| 156 | QT_END_NAMESPACE |
| 157 | |