1/****************************************************************************
2**
3** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB).
4** Contact: http://www.qt-project.org/legal
5**
6** This file is part of the Qt3D module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL3$
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 http://www.qt.io/terms-conditions. For further
15** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
28** Software Foundation and appearing in the file LICENSE.GPL included in
29** the packaging of this file. Please review the following information to
30** ensure the GNU General Public License version 2.0 requirements will be
31** met: http://www.gnu.org/licenses/gpl-2.0.html.
32**
33** $QT_END_LICENSE$
34**
35****************************************************************************/
36
37#include "renderstatenode_p.h"
38#include <Qt3DRender/qrenderstate.h>
39#include <Qt3DRender/private/qrenderstatecreatedchange_p.h>
40
41#include <Qt3DRender/qalphacoverage.h>
42#include <Qt3DRender/qalphatest.h>
43#include <Qt3DRender/private/qalphatest_p.h>
44#include <Qt3DRender/qblendequation.h>
45#include <Qt3DRender/private/qblendequation_p.h>
46#include <Qt3DRender/qblendequationarguments.h>
47#include <Qt3DRender/private/qblendequationarguments_p.h>
48#include <Qt3DRender/qcolormask.h>
49#include <Qt3DRender/private/qcolormask_p.h>
50#include <Qt3DRender/qcullface.h>
51#include <Qt3DRender/private/qcullface_p.h>
52#include <Qt3DRender/qnodepthmask.h>
53#include <Qt3DRender/qdepthrange.h>
54#include <Qt3DRender/private/qdepthrange_p.h>
55#include <Qt3DRender/qdepthtest.h>
56#include <Qt3DRender/private/qdepthtest_p.h>
57#include <Qt3DRender/qrastermode.h>
58#include <Qt3DRender/private/qrastermode_p.h>
59#include <Qt3DRender/qdithering.h>
60#include <Qt3DRender/qfrontface.h>
61#include <Qt3DRender/private/qfrontface_p.h>
62#include <Qt3DRender/qpointsize.h>
63#include <Qt3DRender/private/qpointsize_p.h>
64#include <Qt3DRender/qpolygonoffset.h>
65#include <Qt3DRender/private/qpolygonoffset_p.h>
66#include <Qt3DRender/qscissortest.h>
67#include <Qt3DRender/private/qscissortest_p.h>
68#include <Qt3DRender/qstenciltest.h>
69#include <Qt3DRender/private/qstenciltest_p.h>
70#include <Qt3DRender/qstenciltestarguments.h>
71#include <Qt3DRender/private/qstenciltestarguments_p.h>
72#include <Qt3DRender/qclipplane.h>
73#include <Qt3DRender/private/qclipplane_p.h>
74#include <Qt3DRender/qmultisampleantialiasing.h>
75#include <Qt3DRender/qseamlesscubemap.h>
76#include <Qt3DRender/qstenciloperation.h>
77#include <Qt3DRender/private/qstenciloperation_p.h>
78#include <Qt3DRender/qstenciloperationarguments.h>
79#include <Qt3DRender/private/qstenciloperationarguments_p.h>
80#include <Qt3DRender/qstencilmask.h>
81#include <Qt3DRender/private/qstencilmask_p.h>
82#include <Qt3DRender/qlinewidth.h>
83#include <Qt3DRender/private/qlinewidth_p.h>
84
85QT_BEGIN_NAMESPACE
86
87namespace Qt3DRender {
88namespace Render {
89
90namespace {
91
92StateVariant createStateImplementation(const QRenderState *node)
93{
94 const QRenderStatePrivate *d = static_cast<const QRenderStatePrivate *>(Qt3DCore::QNodePrivate::get(q: node));
95 switch (d->m_type) {
96
97 case AlphaCoverageStateMask: {
98 return StateVariant::createState<AlphaCoverage>();
99 }
100
101 case AlphaTestMask: {
102 const QAlphaTest *alphaTest = static_cast<const QAlphaTest *>(node);
103 return StateVariant::createState<AlphaFunc>(values: alphaTest->alphaFunction(), values: alphaTest->referenceValue());
104 }
105
106 case BlendStateMask: {
107 const QBlendEquation *blendEquation = static_cast<const QBlendEquation *>(node);
108 return StateVariant::createState<BlendEquation>(values: blendEquation->blendFunction());
109 }
110
111 case BlendEquationArgumentsMask: {
112 const QBlendEquationArguments *blendArgs = static_cast<const QBlendEquationArguments *>(node);
113 return StateVariant::createState<BlendEquationArguments>(
114 values: blendArgs->sourceRgb(), values: blendArgs->destinationRgb(),
115 values: blendArgs->sourceAlpha(), values: blendArgs->destinationAlpha(),
116 values: blendArgs->isEnabled(),
117 values: blendArgs->bufferIndex());
118 }
119
120 case MSAAEnabledStateMask: {
121 return StateVariant::createState<MSAAEnabled>(values: node->isEnabled());
122 }
123
124 case CullFaceStateMask: {
125 const QCullFace *cullFace = static_cast<const QCullFace *>(node);
126 return StateVariant::createState<CullFace>(values: cullFace->mode());
127 }
128
129 case DepthRangeMask: {
130 const QDepthRange *depthRange = static_cast<const QDepthRange *>(node);
131 return StateVariant::createState<DepthRange>(values: depthRange->nearValue(), values: depthRange->farValue());
132 }
133
134 case DepthWriteStateMask: {
135 return StateVariant::createState<NoDepthMask>(values: !node->isEnabled());
136 }
137
138 case DepthTestStateMask: {
139 const QDepthTest *depthTest = static_cast<const QDepthTest *>(node);
140 return StateVariant::createState<DepthTest>(values: depthTest->depthFunction());
141 }
142
143 case RasterModeMask: {
144 const QRasterMode *rasterMode = static_cast<const QRasterMode *>(node);
145 return StateVariant::createState<RasterMode>(values: rasterMode->faceMode(), values: rasterMode->rasterMode());
146 }
147
148 case FrontFaceStateMask: {
149 const QFrontFace *frontFace = static_cast<const QFrontFace *>(node);
150 return StateVariant::createState<FrontFace>(values: frontFace->direction());
151 }
152
153 case ScissorStateMask: {
154 const QScissorTest *scissorTest = static_cast<const QScissorTest *>(node);
155 return StateVariant::createState<ScissorTest>(values: scissorTest->left(), values: scissorTest->bottom(),
156 values: scissorTest->width(), values: scissorTest->height());
157 }
158
159 case StencilTestStateMask: {
160 const QStencilTest *stencilTest = static_cast<const QStencilTest *>(node);
161 return StateVariant::createState<StencilTest>(values: stencilTest->front()->stencilFunction(),
162 values: stencilTest->front()->referenceValue(),
163 values: stencilTest->front()->comparisonMask(),
164 values: stencilTest->back()->stencilFunction(),
165 values: stencilTest->back()->referenceValue(),
166 values: stencilTest->back()->comparisonMask());
167 }
168
169 case PointSizeMask: {
170 const QPointSize *pointSize = static_cast<const QPointSize *>(node);
171 const bool isProgrammable = (pointSize->sizeMode() == QPointSize::Programmable);
172 return StateVariant::createState<PointSize>(values: isProgrammable, values: pointSize->value());
173 }
174
175 case PolygonOffsetStateMask: {
176 const QPolygonOffset *offset = static_cast<const QPolygonOffset *>(node);
177 return StateVariant::createState<PolygonOffset>(values: offset->scaleFactor(), values: offset->depthSteps());
178 }
179
180 case ColorStateMask: {
181 const QColorMask *colorMask = static_cast<const QColorMask *>(node);
182 return StateVariant::createState<ColorMask>(values: colorMask->isRedMasked(), values: colorMask->isGreenMasked(),
183 values: colorMask->isBlueMasked(), values: colorMask->isAlphaMasked());
184 }
185
186 case ClipPlaneMask: {
187 const QClipPlane *clipPlane = static_cast<const QClipPlane *>(node);
188 return StateVariant::createState<ClipPlane>(values: clipPlane->planeIndex(),
189 values: clipPlane->normal(),
190 values: clipPlane->distance());
191 }
192
193 case SeamlessCubemapMask: {
194 return StateVariant::createState<SeamlessCubemap>();
195 }
196
197 case StencilOpMask: {
198 const QStencilOperation *stencilOp = static_cast<const QStencilOperation *>(node);
199 return StateVariant::createState<StencilOp>(values: stencilOp->front()->stencilTestFailureOperation(),
200 values: stencilOp->front()->depthTestFailureOperation(),
201 values: stencilOp->front()->allTestsPassOperation(),
202 values: stencilOp->back()->stencilTestFailureOperation(),
203 values: stencilOp->back()->depthTestFailureOperation(),
204 values: stencilOp->back()->allTestsPassOperation());
205 }
206
207 case StencilWriteStateMask: {
208 const QStencilMask *stencilMask = static_cast<const QStencilMask *>(node);
209 return StateVariant::createState<StencilMask>(values: stencilMask->frontOutputMask(),
210 values: stencilMask->backOutputMask());
211 }
212
213 case DitheringStateMask: {
214 return StateVariant::createState<Dithering>();
215 }
216
217 case LineWidthMask: {
218 const QLineWidth *lineWidth = static_cast<const QLineWidth *>(node);
219 return StateVariant::createState<LineWidth>(values: lineWidth->value(), values: lineWidth->smooth());
220 }
221
222 default:
223 Q_UNREACHABLE();
224 return StateVariant();
225 }
226}
227
228} // anonymous
229
230RenderStateNode::RenderStateNode()
231 : BackendNode()
232{
233}
234
235RenderStateNode::~RenderStateNode()
236{
237 cleanup();
238}
239
240void RenderStateNode::cleanup()
241{
242}
243
244void RenderStateNode::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime)
245{
246 const QRenderState *node = qobject_cast<const QRenderState *>(object: frontEnd);
247 if (!node)
248 return;
249
250 BackendNode::syncFromFrontEnd(frontEnd, firstTime);
251
252 if (firstTime)
253 m_impl = createStateImplementation(node);
254
255 m_impl.state()->updateProperties(node);
256 markDirty(changes: AbstractRenderer::AllDirty);
257}
258
259} // namespace Render
260} // namespace Qt3DRender
261
262QT_END_NAMESPACE
263

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