1// Copyright (C) 2016 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#ifndef QT3DRENDER_RENDER_STATEVARIANT_P_H
5#define QT3DRENDER_RENDER_STATEVARIANT_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists for the convenience
12// of other Qt classes. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <Qt3DRender/private/renderstates_p.h>
19
20QT_BEGIN_NAMESPACE
21
22namespace Qt3DRender {
23namespace Render {
24
25struct Q_3DRENDERSHARED_PRIVATE_EXPORT StateVariant
26{
27 StateMask type;
28
29 union u_Data {
30 BlendEquationArguments blendEquationArguments;
31 BlendEquation blendEquation;
32 AlphaFunc alphaFunc;
33 MSAAEnabled msaaEnabled;
34 DepthRange depthRange;
35 DepthTest depthTest;
36 NoDepthMask noDepthMask;
37 CullFace cullFace;
38 FrontFace frontFace;
39 Dithering dithering;
40 ScissorTest scissorTest;
41 StencilTest stencilTest;
42 AlphaCoverage alphaCoverage;
43 PointSize pointSize;
44 PolygonOffset polygonOffset;
45 ColorMask colorMask;
46 ClipPlane clipPlane;
47 SeamlessCubemap seamlessCubemap;
48 StencilOp stencilOp;
49 StencilMask stencilMask;
50 LineWidth lineWidth;
51
52 u_Data()
53 {
54 // Assumes the above types don't need to have their ctor called
55 memset(s: static_cast<void *>(this), c: 0, n: sizeof(u_Data));
56 }
57
58 u_Data(const u_Data &other)
59 {
60 memcpy(dest: static_cast<void *>(this), src: static_cast<const void *>(&other), n: sizeof(u_Data));
61 }
62
63 u_Data& operator=(const u_Data &other)
64 {
65 memcpy(dest: static_cast<void *>(this), src: static_cast<const void *>(&other), n: sizeof(u_Data));
66 return *this;
67 }
68
69 ~u_Data()
70 {
71 // Assumes the above types don't need to have their dtor called
72 }
73 } data;
74
75 template<class State, typename ... Args>
76 static StateVariant createState(Args... values)
77 {
78 State state;
79 state.set(values...);
80 return StateVariant::fromValue(state);
81 }
82
83 template<typename GenericState>
84 static StateVariant fromValue(const GenericState &state)
85 {
86 StateVariant v;
87 v.type = GenericState::type();
88 // all union members start at the same memory address
89 // so we can just write into whichever we want
90 memcpy(dest: static_cast<void *>(&v.data), src: static_cast<const void *>(&state), n: sizeof(state));
91 return v;
92 }
93
94 RenderStateImpl *state();
95 const RenderStateImpl *constState() const;
96
97 bool operator ==(const StateVariant &other) const;
98 bool operator !=(const StateVariant &other) const;
99};
100
101} // namespace Render
102} // namespace Qt3DRender
103
104QT_END_NAMESPACE
105
106#endif // QT3DRENDER_RENDER_STATEVARIANT_P_H
107

source code of qt3d/src/render/renderstates/statevariant_p.h