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 "qstenciloperation.h" |
41 | #include "qstenciloperation_p.h" |
42 | #include "qstenciloperationarguments.h" |
43 | #include <Qt3DRender/private/qrenderstatecreatedchange_p.h> |
44 | |
45 | QT_BEGIN_NAMESPACE |
46 | |
47 | namespace Qt3DRender { |
48 | |
49 | /*! |
50 | \class Qt3DRender::QStencilOperation |
51 | \brief The QStencilOperation class specifies stencil operation. |
52 | \since 5.7 |
53 | \ingroup renderstates |
54 | \inmodule Qt3DRender |
55 | |
56 | A Qt3DRender::QStencilOperation class specifies the stencil operations |
57 | for the front- and back-facing polygons. The stencil operation control |
58 | what is done to fragment when the stencil and depth test pass or fail. |
59 | |
60 | \sa Qt3DRender::QStencilTest |
61 | */ |
62 | |
63 | /*! |
64 | \qmltype StencilOperation |
65 | \brief The StencilOperation type specifies stencil operation. |
66 | \since 5.7 |
67 | \ingroup renderstates |
68 | \inqmlmodule Qt3D.Render |
69 | \inherits RenderState |
70 | \instantiates Qt3DRender::QStencilOperation |
71 | |
72 | A StencilOperation type specifies the stencil operations |
73 | for the front- and back-facing polygons. The stencil operation control |
74 | what is done to fragment when the stencil and depth test pass or fail. |
75 | |
76 | \sa StencilTest |
77 | */ |
78 | |
79 | /*! |
80 | \qmlproperty StencilOperationArguments StencilOperation::front |
81 | Holds the stencil operation arguments for front-facing polygons. |
82 | */ |
83 | |
84 | /*! |
85 | \qmlproperty StencilOperationArguments StencilOperation::back |
86 | Holds the stencil operation arguments for back-facing polygons. |
87 | */ |
88 | |
89 | /*! |
90 | \property QStencilOperation::front |
91 | Holds the stencil operation arguments for front-facing polygons. |
92 | */ |
93 | |
94 | /*! |
95 | \property QStencilOperation::back |
96 | Holds the stencil operation arguments for back-facing polygons. |
97 | */ |
98 | |
99 | /*! |
100 | The constructor creates a new QStencilOperation::QStencilOperation instance with |
101 | the specified \a parent. |
102 | */ |
103 | QStencilOperation::QStencilOperation(QNode *parent) |
104 | : QRenderState(*new QStencilOperationPrivate(), parent) |
105 | { |
106 | Q_D(QStencilOperation); |
107 | |
108 | const auto resend = [d]() { d->update(); }; |
109 | |
110 | (void) connect(sender: d->m_front, signal: &QStencilOperationArguments::allTestsPassOperationChanged, slot: resend); |
111 | (void) connect(sender: d->m_front, signal: &QStencilOperationArguments::depthTestFailureOperationChanged, slot: resend); |
112 | (void) connect(sender: d->m_front, signal: &QStencilOperationArguments::stencilTestFailureOperationChanged, slot: resend); |
113 | (void) connect(sender: d->m_front, signal: &QStencilOperationArguments::faceModeChanged, slot: resend); |
114 | |
115 | (void) connect(sender: d->m_back, signal: &QStencilOperationArguments::allTestsPassOperationChanged, slot: resend); |
116 | (void) connect(sender: d->m_back, signal: &QStencilOperationArguments::depthTestFailureOperationChanged, slot: resend); |
117 | (void) connect(sender: d->m_back, signal: &QStencilOperationArguments::stencilTestFailureOperationChanged, slot: resend); |
118 | (void) connect(sender: d->m_back, signal: &QStencilOperationArguments::faceModeChanged, slot: resend); |
119 | } |
120 | |
121 | /*! \internal */ |
122 | QStencilOperation::~QStencilOperation() |
123 | { |
124 | } |
125 | |
126 | /*! \internal */ |
127 | void QStencilOperationPrivate::fillData(QStencilOperationData &data) const |
128 | { |
129 | data.front.face = m_front->faceMode(); |
130 | data.front.stencilTestFailureOperation = m_front->stencilTestFailureOperation(); |
131 | data.front.depthTestFailureOperation = m_front->depthTestFailureOperation(); |
132 | data.front.allTestsPassOperation = m_front->allTestsPassOperation(); |
133 | data.back.face = m_back->faceMode(); |
134 | data.back.stencilTestFailureOperation = m_back->stencilTestFailureOperation(); |
135 | data.back.depthTestFailureOperation = m_back->depthTestFailureOperation(); |
136 | data.back.allTestsPassOperation = m_back->allTestsPassOperation(); |
137 | } |
138 | |
139 | QStencilOperationArguments *QStencilOperation::front() const |
140 | { |
141 | Q_D(const QStencilOperation); |
142 | return d->m_front; |
143 | } |
144 | |
145 | QStencilOperationArguments *QStencilOperation::back() const |
146 | { |
147 | Q_D(const QStencilOperation); |
148 | return d->m_back; |
149 | } |
150 | |
151 | Qt3DCore::QNodeCreatedChangeBasePtr QStencilOperation::createNodeCreationChange() const |
152 | { |
153 | auto creationChange = QRenderStateCreatedChangePtr<QStencilOperationData>::create(arguments: this); |
154 | d_func()->fillData(data&: creationChange->data); |
155 | return creationChange; |
156 | } |
157 | |
158 | } // namespace Qt3DRender |
159 | |
160 | QT_END_NAMESPACE |
161 | |