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
42#include "qcullface.h"
43#include "qcullface_p.h"
44#include <Qt3DRender/private/qrenderstatecreatedchange_p.h>
45
46QT_BEGIN_NAMESPACE
47
48namespace Qt3DRender {
49
50/*!
51 \class Qt3DRender::QCullFace
52 \brief The QCullFace class specifies whether front or back face culling
53 is enabled.
54 \since 5.7
55 \inmodule Qt3DRender
56 \ingroup renderstates
57
58 QCullFace sets whether the front or back facets are culled.
59 Facets include triangles, quadrilaterals, polygons and rectangles.
60
61 It can be added by calling the addRenderState() method on a QRenderPass:
62
63 \code
64 // using namespace Qt3DRender;
65
66 QRenderPass *renderPass = new QRenderPass();
67
68 // Create a front face culling render state
69 QCullFace *cullFront = new QCullFace();
70 cullFront->setMode(QCullFace::Front);
71
72 // Add the render state to the render pass
73 renderPass->addRenderState(cullFront);
74 \endcode
75
76 Or by calling the addRenderState() method on a QRenderStateSet:
77
78 \code
79 // using namespace Qt3DRender;
80
81 QRenderStateSet *renderStateSet = new QRenderStateSet();
82
83 // Create a front face culling render state
84 QCullFace *cullFront = new QCullFace();
85 cullFront->setMode(QCullFace::Front);
86
87 // Add the render state to the render pass
88 renderStateSet->addRenderState(cullFront);
89 \endcode
90
91 \sa QFrontFace
92 */
93
94/*!
95 \qmltype CullFace
96 \brief The CullFace type specifies whether front or back face culling
97 is enabled.
98 \since 5.7
99 \inqmlmodule Qt3D.Render
100 \instantiates Qt3DRender::QCullFace
101 \inherits RenderState
102 \ingroup renderstates
103
104 CullFace sets whether the front or back facets are culled.
105 Facets include triangles, quadrilaterals, polygons and rectangles.
106
107 It can be added to the renderStates property of a RenderPass:
108
109 \qml
110 RenderPass {
111 shaderProgram: ShaderProgram {
112 // ...
113 }
114 renderStates: [
115 CullFace {
116 mode: CullFace.Front
117 }
118 ]
119 }
120 \endqml
121
122 Or added to the renderStates property of a RenderStateSet:
123
124 \qml
125 RenderStateSet {
126 renderStates: [
127 CullFace {
128 mode: CullFace.Front
129 }
130 ]
131 }
132 \endqml
133
134 \sa FrontFace
135 */
136
137/*!
138 \enum Qt3DRender::QCullFace::CullingMode
139
140 This enumeration specifies values for the culling mode.
141
142 \value NoCulling Culling is disabled
143 \value Front Culling is enabled for front facing polygons
144 \value Back Culling is enabled for back facing polygons
145 \value FrontAndBack Culling is enabled for all polygons, points and lines are drawn
146*/
147
148/*!
149 \qmlproperty enumeration CullFace::mode
150 Holds the culling mode used by CullFace. Default is set to QCullFace.Back.
151
152 \list
153 \li CullFace.NoCulling - culling is disabled
154 \li CullFace.Front - culling is enabled for front facing polygons
155 \li CullFace.Back - culling is enabled for back facing polygons
156 \li CullFace.FrontAndBack - culling is enabled for all polygons, but points and lines are drawn
157 \endlist
158*/
159
160/*!
161 \property QCullFace::mode
162 Holds the culling mode used by QCullFace. Default is set to QCullFace.Back.
163*/
164
165/*!
166 Constructs a new QCullFace::QCullFace instance with \a parent as parent.
167 */
168QCullFace::QCullFace(QNode *parent)
169 : QRenderState(*new QCullFacePrivate, parent)
170{
171}
172
173/*! \internal */
174QCullFace::~QCullFace()
175{
176}
177
178QCullFace::CullingMode QCullFace::mode() const
179{
180 Q_D(const QCullFace);
181 return d->m_mode;
182}
183
184void QCullFace::setMode(QCullFace::CullingMode mode)
185{
186 Q_D(QCullFace);
187 if (d->m_mode != mode) {
188 d->m_mode = mode;
189 emit modeChanged(mode);
190 }
191}
192
193Qt3DCore::QNodeCreatedChangeBasePtr QCullFace::createNodeCreationChange() const
194{
195 auto creationChange = QRenderStateCreatedChangePtr<QCullFaceData>::create(arguments: this);
196 auto &data = creationChange->data;
197 Q_D(const QCullFace);
198 data.mode = d->m_mode;
199 return creationChange;
200}
201
202} // namespace Qt3DRender
203
204QT_END_NAMESPACE
205

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