1// Copyright (C) 2014 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#include "qsortpolicy_p.h"
5
6QT_BEGIN_NAMESPACE
7
8using namespace Qt3DCore;
9
10namespace Qt3DRender {
11
12QSortPolicyPrivate::QSortPolicyPrivate()
13 : QFrameGraphNodePrivate()
14{
15}
16
17/*!
18 \class Qt3DRender::QSortPolicy
19 \inmodule Qt3DRender
20 \brief Provides storage for the sort types to be used.
21 \since 5.7
22
23 \inherits Qt3DRender::QFrameGraphNode
24
25 A Qt3DRender::QSortPolicy class stores the sorting type used by the FrameGraph.
26 The sort types determine how drawable entities are sorted before drawing to
27 determine the drawing order. When QSortPolicy is present in the FrameGraph,
28 the sorting mechanism is determined by the sortTypes list. Multiple sort types
29 can be used simultaneously. If QSortPolicy is not present in the FrameGraph,
30 entities are drawn in the order they appear in the entity hierarchy.
31 */
32
33/*!
34 \qmltype SortPolicy
35 \inqmlmodule Qt3D.Render
36 \since 5.7
37 \instantiates Qt3DRender::QSortPolicy
38 \inherits FrameGraphNode
39 \brief Provides storage for the sort types to be used.
40
41 A SortPolicy class stores the sorting type used by the FrameGraph.
42 The sort types determine how drawable entities are sorted before drawing to
43 determine the drawing order. When SortPolicy is present in the FrameGraph,
44 the sorting mechanism is determined by the sortTypes list. Multiple sort
45 types can be used simultaneously. If SortPolicy is not present in the FrameGraph,
46 entities are drawn in the order they appear in the entity hierarchy.
47 */
48
49/*!
50 \enum QSortPolicy::SortType
51
52 This enum type describes the available sort types.
53
54 \value StateChangeCost sort the objects so as to minimize the cost of
55 changing from the currently rendered state
56
57 \value BackToFront sort the objects from back to front based on inverted z
58 order. More accurately, the sorting key is the z component of the
59 projection of the camera-to-object-center vector onto the camera's view
60 vector.
61
62 \value Material sort the objects based on their material (shader) value.
63
64 \value FrontToBack sort the objects from front to back. The opposite of
65 BackToFront.
66
67 \value [since 5.14] Texture sort the objects to minimize texture changes.
68
69 \value [since 5.15] Uniform sort the objects to minimize uniform changes.
70*/
71
72/*!
73 \property QSortPolicy::sortTypes
74 Specifies the sorting types to be used.
75*/
76
77/*!
78 \qmlproperty list<int> SortPolicy::sortTypes
79 Specifies the sorting types to be used.
80
81 This list can include the following values:
82 \list
83 \li StateChangeCost - sort the objects so as to minimize the cost of
84 changing from the currently rendered state
85 \li BackToFront - sort the objects from back to front based on inverted z
86 order. More accurately, the sorting key is the z component of the
87 projection of the camera-to-object-center vector onto the camera's view
88 vector.
89 \li Material - sort the objects based on their material (shader) value.
90 \li FrontToBack - sort the objects from front to back. The opposite of
91 BackToFront.
92 \li [since 5.14] Texture - sort the objects to minimize texture changes.
93 \li [since 5.15] Uniform - sort the objects to minimize uniform changes.
94 \endlist
95*/
96
97/*!
98 Constructs QSortPolicy with given \a parent.
99 */
100QSortPolicy::QSortPolicy(QNode *parent)
101 : QFrameGraphNode(*new QSortPolicyPrivate, parent)
102{
103}
104
105/*! \internal */
106QSortPolicy::~QSortPolicy()
107{
108}
109
110/*! \internal */
111QSortPolicy::QSortPolicy(QSortPolicyPrivate &dd, QNode *parent)
112 : QFrameGraphNode(dd, parent)
113{
114}
115
116/*!
117 \return the current sort types in use
118 */
119QList<QSortPolicy::SortType> QSortPolicy::sortTypes() const
120{
121 Q_D(const QSortPolicy);
122 return d->m_sortTypes;
123}
124
125QList<int> QSortPolicy::sortTypesInt() const
126{
127 Q_D(const QSortPolicy);
128 QList<int> sortTypesInt;
129 transformVector(input: d->m_sortTypes, output&: sortTypesInt);
130 return sortTypesInt;
131}
132
133void QSortPolicy::setSortTypes(const QList<SortType> &sortTypes)
134{
135 Q_D(QSortPolicy);
136 if (sortTypes != d->m_sortTypes) {
137 d->m_sortTypes = sortTypes;
138 emit sortTypesChanged(sortTypes);
139
140 const bool wasBlocked = blockNotifications(block: true);
141 emit sortTypesChanged(sortTypes: sortTypesInt());
142 blockNotifications(block: wasBlocked);
143 }
144}
145
146void QSortPolicy::setSortTypes(const QList<int> &sortTypesInt)
147{
148 QList<SortType> sortTypes;
149 transformVector(input: sortTypesInt, output&: sortTypes);
150 setSortTypes(sortTypes);
151}
152
153} // namespace Qt3DRender
154
155QT_END_NAMESPACE
156
157#include "moc_qsortpolicy.cpp"
158

source code of qt3d/src/render/framegraph/qsortpolicy.cpp