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

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

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