1/****************************************************************************
2**
3** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
4** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
5** Contact: https://www.qt.io/licensing/
6**
7** This file is part of the Qt3D module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial License Usage
11** Licensees holding valid commercial Qt licenses may use this file in
12** accordance with the commercial license agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and The Qt Company. For licensing terms
15** and conditions see https://www.qt.io/terms-conditions. For further
16** information use the contact form at https://www.qt.io/contact-us.
17**
18** GNU Lesser General Public License Usage
19** Alternatively, this file may be used under the terms of the GNU Lesser
20** General Public License version 3 as published by the Free Software
21** Foundation and appearing in the file LICENSE.LGPL3 included in the
22** packaging of this file. Please review the following information to
23** ensure the GNU Lesser General Public License version 3 requirements
24** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
25**
26** GNU General Public License Usage
27** Alternatively, this file may be used under the terms of the GNU
28** General Public License version 2.0 or (at your option) the GNU General
29** Public license version 3 or any later version approved by the KDE Free
30** Qt Foundation. The licenses are as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
32** included in the packaging of this file. Please review the following
33** information to ensure the GNU General Public License requirements will
34** be met: https://www.gnu.org/licenses/gpl-2.0.html and
35** https://www.gnu.org/licenses/gpl-3.0.html.
36**
37** $QT_END_LICENSE$
38**
39****************************************************************************/
40
41#include "qstenciltest.h"
42#include "qstenciltest_p.h"
43#include "qstenciltestarguments.h"
44#include <Qt3DRender/private/qrenderstatecreatedchange_p.h>
45
46QT_BEGIN_NAMESPACE
47
48namespace Qt3DRender {
49
50/*!
51 \class Qt3DRender::QStencilTest
52 \since 5.7
53 \ingroup renderstates
54 \inmodule Qt3DRender
55 \brief The QStencilTest class specifies arguments for the stecil test.
56
57 A Qt3DRender::QStencilTest class specifies argument for the stencil test.
58 The stencil test comprises of three arguments: stencil test function,
59 stencil test mask and stencil reference value. QStencilTest allows these
60 arguments to be set for both front- and back-facing polygons separately.
61
62 \sa Qt3DRender::QStencilMask, Qt3DRender::QStencilOperation
63 */
64
65/*!
66 \qmltype StencilTest
67 \since 5.7
68 \ingroup renderstates
69 \inqmlmodule Qt3D.Render
70 \brief The StencilTest type specifies arguments for the stecil test.
71 \inherits RenderState
72 \instantiates Qt3DRender::QStencilTest
73
74 A StencilTest type specifies argument for the stencil test.
75 The stencil test comprises of three arguments: stencil test function,
76 stencil test mask and stencil reference value. StencilTest allows these
77 arguments to be set for both front- and back-facing polygons separately.
78
79 \sa StencilMask, StencilOperation
80 */
81
82/*!
83 \qmlproperty StencilTestArguments StencilTest::front
84 Holds the stencil test arguments for front-facing polygons.
85*/
86
87/*!
88 \qmlproperty StencilTestArguments StencilTest::back
89 Holds the stencil test arguments for back-facing polygons.
90*/
91
92/*!
93 \property QStencilTest::front
94 Holds the stencil test arguments for front-facing polygons.
95*/
96
97/*!
98 \property QStencilTest::back
99 Holds the stencil test arguments for back-facing polygons.
100*/
101
102/*!
103 The constructor creates a new QStencilTest::QStencilTest instance with
104 the specified \a parent.
105 */
106QStencilTest::QStencilTest(QNode *parent)
107 : QRenderState(*new QStencilTestPrivate, parent)
108{
109 Q_D(QStencilTest);
110
111 const auto resend = [d]() { d->update(); };
112
113 (void) connect(sender: d->m_front, signal: &QStencilTestArguments::comparisonMaskChanged, slot: resend);
114 (void) connect(sender: d->m_front, signal: &QStencilTestArguments::faceModeChanged, slot: resend);
115 (void) connect(sender: d->m_front, signal: &QStencilTestArguments::referenceValueChanged, slot: resend);
116 (void) connect(sender: d->m_front, signal: &QStencilTestArguments::stencilFunctionChanged, slot: resend);
117
118 (void) connect(sender: d->m_back, signal: &QStencilTestArguments::comparisonMaskChanged, slot: resend);
119 (void) connect(sender: d->m_back, signal: &QStencilTestArguments::faceModeChanged, slot: resend);
120 (void) connect(sender: d->m_back, signal: &QStencilTestArguments::referenceValueChanged, slot: resend);
121 (void) connect(sender: d->m_back, signal: &QStencilTestArguments::stencilFunctionChanged, slot: resend);
122}
123
124/*! \internal */
125QStencilTest::~QStencilTest()
126{
127}
128
129/*! \internal */
130void QStencilTestPrivate::fillData(QStencilTestData &data) const
131{
132 data.front.face = m_front->faceMode();
133 data.front.comparisonMask = m_front->comparisonMask();
134 data.front.referenceValue = m_front->referenceValue();
135 data.front.stencilFunction = m_front->stencilFunction();
136 data.back.face = m_back->faceMode();
137 data.back.comparisonMask = m_back->comparisonMask();
138 data.back.referenceValue = m_back->referenceValue();
139 data.back.stencilFunction = m_back->stencilFunction();
140}
141
142QStencilTestArguments *QStencilTest::front() const
143{
144 Q_D(const QStencilTest);
145 return d->m_front;
146}
147
148QStencilTestArguments *QStencilTest::back() const
149{
150 Q_D(const QStencilTest);
151 return d->m_back;
152}
153
154Qt3DCore::QNodeCreatedChangeBasePtr QStencilTest::createNodeCreationChange() const
155{
156 auto creationChange = QRenderStateCreatedChangePtr<QStencilTestData>::create(arguments: this);
157 d_func()->fillData(data&: creationChange->data);
158 return creationChange;
159}
160
161} // namespace Qt3DRender
162
163QT_END_NAMESPACE
164

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