1 | // Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). |
2 | // Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies). |
3 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
4 | |
5 | #ifndef QT3DRENDER_RENDER_GENERICSTATE_H |
6 | #define QT3DRENDER_RENDER_GENERICSTATE_H |
7 | |
8 | // |
9 | // W A R N I N G |
10 | // ------------- |
11 | // |
12 | // This file is not part of the Qt API. It exists for the convenience |
13 | // of other Qt classes. This header file may change from version to |
14 | // version without notice, or even be removed. |
15 | // |
16 | // We mean it. |
17 | // |
18 | |
19 | #include <Qt3DRender/private/backendnode_p.h> |
20 | #include <Qt3DCore/private/qresourcemanager_p.h> |
21 | #include <Qt3DRender/private/statemask_p.h> |
22 | #include <Qt3DRender/private/qt3drender_global_p.h> |
23 | //#include <Qt3DRender/private/statevariant_p.h> |
24 | #include <QList> |
25 | #include <QVector3D> |
26 | #include <QOpenGLContext> |
27 | |
28 | QT_BEGIN_NAMESPACE |
29 | |
30 | namespace Qt3DRender { |
31 | |
32 | class QRenderState; |
33 | |
34 | namespace Render { |
35 | |
36 | class GraphicsContext; |
37 | |
38 | typedef quint64 StateMaskSet; |
39 | |
40 | class Q_3DRENDERSHARED_PRIVATE_EXPORT RenderStateImpl |
41 | { |
42 | public: |
43 | virtual ~RenderStateImpl() {} |
44 | |
45 | virtual StateMask mask() const = 0; |
46 | virtual bool equalTo(const RenderStateImpl &renderState) const = 0; |
47 | virtual void updateProperties(const QRenderState *); |
48 | }; |
49 | |
50 | template <class StateSetImpl, StateMask stateMask, typename ... T> |
51 | class GenericState : public RenderStateImpl |
52 | { |
53 | public: |
54 | GenericState *set(T... values) |
55 | { |
56 | m_values = std::tuple<T ...>(values...); |
57 | return this; |
58 | } |
59 | |
60 | bool equalTo(const RenderStateImpl &renderState) const override |
61 | { |
62 | const GenericState *other = static_cast<const GenericState*>(&renderState); |
63 | return (other != nullptr && other->m_values == m_values); |
64 | } |
65 | |
66 | StateMask mask() const override |
67 | { |
68 | return GenericState::type(); |
69 | } |
70 | |
71 | static StateMask type() |
72 | { |
73 | return stateMask; |
74 | } |
75 | |
76 | std::tuple<T ...> values() const |
77 | { |
78 | return m_values; |
79 | } |
80 | |
81 | protected: |
82 | std::tuple<T ...> m_values; |
83 | }; |
84 | |
85 | } // namespace Render |
86 | } // namespace Qt3DRender |
87 | |
88 | QT_END_NAMESPACE |
89 | |
90 | #endif // QT3DRENDER_RENDER_GENERICSTATE_H |
91 | |