1// Copyright (C) 2014 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 "qpolygonoffset.h"
5#include "qpolygonoffset_p.h"
6
7QT_BEGIN_NAMESPACE
8
9namespace Qt3DRender {
10
11/*!
12 \class Qt3DRender::QPolygonOffset
13 \brief The QPolygonOffset class sets the scale and steps to calculate depth
14 values for polygon offsets.
15 \since 5.7
16 \inmodule Qt3DRender
17 \ingroup renderstates
18
19 A QPolygonOffset class adds an offset to the fragment depth value prior to
20 depth test and depth write. The offset can be used to avoid z-fighting when
21 rendering polygons with very close depth values such as decals.
22 */
23
24/*!
25 \qmltype PolygonOffset
26 \brief The PolygonOffset type sets the scale and steps to calculate depth
27 values for polygon offsets.
28 \since 5.7
29 \inqmlmodule Qt3D.Render
30 \ingroup renderstates
31 \inherits RenderState
32 \instantiates Qt3DRender::QPolygonOffset
33
34 A PolygonOffset type adds an offset to the fragment depth value prior to
35 depth test and depth write. The offset can be used to avoid z-fighting when
36 rendering polygons with very close depth values such as decals.
37 */
38
39/*!
40 \qmlproperty real PolygonOffset::scaleFactor
41 Holds the scale factor used to create a variable depth offset for
42 each polygon. Default value is 0.
43*/
44
45/*!
46 \qmlproperty real PolygonOffset::depthSteps
47 Holds the units that create constant depth offsets. Default value is 0.
48*/
49
50/*!
51 \property QPolygonOffset::scaleFactor
52 Holds the scale factor used to create a variable depth offset for
53 each polygon. Default value is 0.
54*/
55
56/*!
57 \property QPolygonOffset::depthSteps
58 Holds the units that create constant depth offsets. Default value is 0.
59*/
60
61/*!
62 The constructor creates a new QPolygonOffset::QPolygonOffset instance
63 with the specified \a parent
64 */
65QPolygonOffset::QPolygonOffset(QNode *parent)
66 : QRenderState(*new QPolygonOffsetPrivate, parent)
67{
68}
69
70/*! \internal */
71QPolygonOffset::~QPolygonOffset()
72{
73}
74
75float QPolygonOffset::scaleFactor() const
76{
77 Q_D(const QPolygonOffset);
78 return d->m_scaleFactor;
79}
80
81void QPolygonOffset::setScaleFactor(float scaleFactor)
82{
83 Q_D(QPolygonOffset);
84 if (d->m_scaleFactor != scaleFactor) {
85 d->m_scaleFactor = scaleFactor;
86 emit scaleFactorChanged(scaleFactor: d->m_scaleFactor);
87 }
88}
89
90float QPolygonOffset::depthSteps() const
91{
92 Q_D(const QPolygonOffset);
93 return d->m_depthSteps;
94}
95
96void QPolygonOffset::setDepthSteps(float depthSteps)
97{
98 Q_D(QPolygonOffset);
99 if (d->m_depthSteps != depthSteps) {
100 d->m_depthSteps = depthSteps;
101 emit depthStepsChanged(depthSteps: d->m_depthSteps);
102 }
103}
104
105} // namespace Qt3DRender
106
107QT_END_NAMESPACE
108
109#include "moc_qpolygonoffset.cpp"
110

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