| 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_RENDERSTATE_H |
| 6 | #define QT3DRENDER_RENDER_RENDERSTATE_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/genericstate_p.h> |
| 20 | #include <Qt3DRender/private/renderstates_p.h> |
| 21 | #include <Qt3DRender/private/statevariant_p.h> |
| 22 | |
| 23 | QT_BEGIN_NAMESPACE |
| 24 | |
| 25 | namespace Qt3DRender { |
| 26 | |
| 27 | class QRenderState; |
| 28 | |
| 29 | namespace Render { |
| 30 | |
| 31 | class RenderState; |
| 32 | |
| 33 | class Q_3DRENDERSHARED_PRIVATE_EXPORT RenderStateSet |
| 34 | { |
| 35 | public: |
| 36 | RenderStateSet(); |
| 37 | ~RenderStateSet(); |
| 38 | |
| 39 | template<typename GenericState> |
| 40 | void addState(const GenericState &state) |
| 41 | { |
| 42 | addState(StateVariant::fromValue(state)); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * @brief changeCost - metric of cost to change to this state-set from |
| 47 | * a candidate previous state-set. This is used to find an optimal |
| 48 | * ordering of state-sets when sending draw commands. |
| 49 | * @param previousState |
| 50 | * @return |
| 51 | */ |
| 52 | int changeCost(RenderStateSet* previousState); |
| 53 | |
| 54 | StateMaskSet stateMask() const; |
| 55 | void merge(const RenderStateSet *other); |
| 56 | |
| 57 | const std::vector<StateVariant>& states() const noexcept { return m_states; } |
| 58 | std::vector<StateVariant>& states() noexcept { return m_states; } |
| 59 | |
| 60 | bool canAddStateOfType(StateMask type) const; |
| 61 | |
| 62 | /** |
| 63 | * @brief contains - check if this set contains a matching piece of state |
| 64 | * @param ds |
| 65 | * @return |
| 66 | */ |
| 67 | bool contains(const StateVariant &ds) const; |
| 68 | |
| 69 | private: |
| 70 | bool hasStateOfType(StateMask type) const; |
| 71 | bool allowMultipleStatesOfType(StateMask type) const; |
| 72 | |
| 73 | private: |
| 74 | StateMaskSet m_stateMask; |
| 75 | std::vector<StateVariant> m_states; |
| 76 | }; |
| 77 | |
| 78 | template<> |
| 79 | Q_3DRENDERSHARED_PRIVATE_EXPORT void RenderStateSet::addState<StateVariant>(const StateVariant &state); |
| 80 | |
| 81 | } // namespace Render |
| 82 | } // namespace Qt3DRender |
| 83 | |
| 84 | QT_END_NAMESPACE |
| 85 | |
| 86 | #endif // QT3DRENDER_RENDER_RENDERSTATE_H |
| 87 | |