1// Copyright (C) 2019 Klaralvdalens Datakonsult AB (KDAB).
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qdepthrange.h"
5#include "qdepthrange_p.h"
6
7QT_BEGIN_NAMESPACE
8
9namespace Qt3DRender {
10
11/*!
12 \class Qt3DRender::QDepthRange
13 \inmodule Qt3DRender
14 \since 5.14
15 \ingroup renderstates
16 \brief Enables remapping depth values written into the depth buffer.
17
18 By default, OpenGL writes scene depth information into the depth buffer in
19 the range [0.0, 1.0] with 0.0 corresponding to the near clip plane and 1.0 to
20 the far clip plane. QDepthRange allows mapping these values into a different
21 range so parts of the scene are always rendered in front of or behind other
22 parts. Valid values for near and far are between 0 and 1.
23 */
24
25/*!
26 \qmltype DepthRange
27 \instantiates Qt3DRender::QDepthRange
28 \inherits RenderState
29 \inqmlmodule Qt3D.Render
30 \ingroup renderstates
31 \since 5.14
32 \brief Enables remapping depth values written into the depth buffer.
33
34 By default, OpenGL writes scene depth information into the depth buffer in
35 the range [0.0, 1.0] corresponding to the near and far clip planes.
36 QDepthRange allows mapping these values into a different range. For example
37 setting the range [0.0, 0.5] will map the rendered scene into the depth
38 buffer such that objects at the near clip plane have depth value of 0.0 and
39 objects at the far clip plane have a depth value of 0.5. This allows
40 rendering parts of the scene always in front of or behind other parts.
41*/
42
43/*!
44 \qmlproperty real QDepthRange::nearValue
45 The depth buffer value corresponding to the near clip plane. Valid values for are
46 between 0 and 1.
47*/
48
49/*!
50 \qmlproperty real QDepthRange::farValue
51 The depth buffer value corresponding to the far clip plane. Valid values for are
52 between 0 and 1.
53*/
54
55/*!
56 \property QDepthRange::nearValue
57 The depth buffer value corresponding to the near clip plane. Valid values for are
58 between 0 and 1.
59*/
60
61/*!
62 \property QDepthRange::farValue
63 The depth buffer value corresponding to the far clip plane. Valid values for are
64 between 0 and 1.
65*/
66
67QDepthRange::QDepthRange(QNode *parent)
68 : QRenderState(*new QDepthRangePrivate(), parent)
69{
70}
71
72/*! \internal */
73QDepthRange::~QDepthRange()
74{
75}
76
77double QDepthRange::nearValue() const
78{
79 Q_D(const QDepthRange);
80 return d->m_nearValue;
81}
82
83double QDepthRange::farValue() const
84{
85 Q_D(const QDepthRange);
86 return d->m_farValue;
87}
88
89void QDepthRange::setNearValue(double value)
90{
91 Q_D(QDepthRange);
92 if (value != d->m_nearValue) {
93 d->m_nearValue = value;
94 Q_EMIT nearValueChanged(nearValue: value);
95 }
96}
97
98void QDepthRange::setFarValue(double value)
99{
100 Q_D(QDepthRange);
101 if (value != d->m_farValue) {
102 d->m_farValue = value;
103 Q_EMIT farValueChanged(farValue: value);
104 }
105}
106
107} // namespace Qt3DRender
108
109QT_END_NAMESPACE
110
111#include "moc_qdepthrange.cpp"
112

source code of qt3d/src/render/renderstates/qdepthrange.cpp