| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the Qt3D module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU Lesser General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
| 21 | ** packaging of this file. Please review the following information to |
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
| 24 | ** |
| 25 | ** GNU General Public License Usage |
| 26 | ** Alternatively, this file may be used under the terms of the GNU |
| 27 | ** General Public License version 2.0 or (at your option) the GNU General |
| 28 | ** Public license version 3 or any later version approved by the KDE Free |
| 29 | ** Qt Foundation. The licenses are as published by the Free Software |
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
| 31 | ** included in the packaging of this file. Please review the following |
| 32 | ** information to ensure the GNU General Public License requirements will |
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
| 35 | ** |
| 36 | ** $QT_END_LICENSE$ |
| 37 | ** |
| 38 | ****************************************************************************/ |
| 39 | |
| 40 | #include "qsortpolicy_p.h" |
| 41 | #include <Qt3DCore/qpropertyvalueaddedchange.h> |
| 42 | #include <Qt3DCore/qpropertyvalueremovedchange.h> |
| 43 | #include <Qt3DRender/qframegraphnodecreatedchange.h> |
| 44 | |
| 45 | QT_BEGIN_NAMESPACE |
| 46 | |
| 47 | using namespace Qt3DCore; |
| 48 | |
| 49 | namespace Qt3DRender { |
| 50 | |
| 51 | QSortPolicyPrivate::QSortPolicyPrivate() |
| 52 | : QFrameGraphNodePrivate() |
| 53 | { |
| 54 | } |
| 55 | |
| 56 | /*! |
| 57 | \class Qt3DRender::QSortPolicy |
| 58 | \inmodule Qt3DRender |
| 59 | \brief Provides storage for the sort types to be used. |
| 60 | \since 5.7 |
| 61 | |
| 62 | \inherits Qt3DRender::QFrameGraphNode |
| 63 | |
| 64 | A Qt3DRender::QSortPolicy class stores the sorting type used by the FrameGraph. |
| 65 | The sort types determine how drawable entities are sorted before drawing to |
| 66 | determine the drawing order. When QSortPolicy is present in the FrameGraph, |
| 67 | the sorting mechanism is determined by the sortTypes list. Multiple sort types |
| 68 | can be used simultaneously. If QSortPolicy is not present in the FrameGraph, |
| 69 | entities are drawn in the order they appear in the entity hierarchy. |
| 70 | */ |
| 71 | |
| 72 | /*! |
| 73 | \qmltype SortPolicy |
| 74 | \inqmlmodule Qt3D.Render |
| 75 | \since 5.7 |
| 76 | \instantiates Qt3DRender::QSortPolicy |
| 77 | \inherits FrameGraphNode |
| 78 | \brief Provides storage for the sort types to be used. |
| 79 | |
| 80 | A SortPolicy class stores the sorting type used by the FrameGraph. |
| 81 | The sort types determine how drawable entities are sorted before drawing to |
| 82 | determine the drawing order. When SortPolicy is present in the FrameGraph, |
| 83 | the sorting mechanism is determined by the sortTypes list. Multiple sort |
| 84 | types can be used simultaneously. If SortPolicy is not present in the FrameGraph, |
| 85 | entities are drawn in the order they appear in the entity hierarchy. |
| 86 | */ |
| 87 | |
| 88 | /*! |
| 89 | \enum QSortPolicy::SortType |
| 90 | |
| 91 | This enum type describes the available sort types. |
| 92 | |
| 93 | \value StateChangeCost sort the objects so as to minimize the cost of |
| 94 | changing from the currently rendered state |
| 95 | |
| 96 | \value BackToFront sort the objects from back to front based on inverted z |
| 97 | order. More accurately, the sorting key is the z component of the |
| 98 | projection of the camera-to-object-center vector onto the camera's view |
| 99 | vector. |
| 100 | |
| 101 | \value Material sort the objects based on their material (shader) value. |
| 102 | |
| 103 | \value FrontToBack sort the objects from front to back. The opposite of |
| 104 | BackToFront. |
| 105 | |
| 106 | \value [since 5.14] Texture sort the objects to minimize texture changes. |
| 107 | |
| 108 | \value [since 5.15] Uniform sort the objects to minimize uniform changes. |
| 109 | */ |
| 110 | |
| 111 | /*! |
| 112 | \property QSortPolicy::sortTypes |
| 113 | Specifies the sorting types to be used. |
| 114 | */ |
| 115 | |
| 116 | /*! |
| 117 | \qmlproperty list<int> SortPolicy::sortTypes |
| 118 | Specifies the sorting types to be used. |
| 119 | |
| 120 | This list can include the following values: |
| 121 | \list |
| 122 | \li StateChangeCost - sort the objects so as to minimize the cost of |
| 123 | changing from the currently rendered state |
| 124 | \li BackToFront - sort the objects from back to front based on inverted z |
| 125 | order. More accurately, the sorting key is the z component of the |
| 126 | projection of the camera-to-object-center vector onto the camera's view |
| 127 | vector. |
| 128 | \li Material - sort the objects based on their material (shader) value. |
| 129 | \li FrontToBack - sort the objects from front to back. The opposite of |
| 130 | BackToFront. |
| 131 | \li [since 5.14] Texture - sort the objects to minimize texture changes. |
| 132 | \li [since 5.15] Uniform - sort the objects to minimize uniform changes. |
| 133 | \endlist |
| 134 | */ |
| 135 | |
| 136 | /*! |
| 137 | Constructs QSortPolicy with given \a parent. |
| 138 | */ |
| 139 | QSortPolicy::QSortPolicy(QNode *parent) |
| 140 | : QFrameGraphNode(*new QSortPolicyPrivate, parent) |
| 141 | { |
| 142 | } |
| 143 | |
| 144 | /*! \internal */ |
| 145 | QSortPolicy::~QSortPolicy() |
| 146 | { |
| 147 | } |
| 148 | |
| 149 | /*! \internal */ |
| 150 | QSortPolicy::QSortPolicy(QSortPolicyPrivate &dd, QNode *parent) |
| 151 | : QFrameGraphNode(dd, parent) |
| 152 | { |
| 153 | } |
| 154 | |
| 155 | QNodeCreatedChangeBasePtr QSortPolicy::createNodeCreationChange() const |
| 156 | { |
| 157 | auto creationChange = QFrameGraphNodeCreatedChangePtr<QSortPolicyData>::create(arguments: this); |
| 158 | QSortPolicyData &data = creationChange->data; |
| 159 | Q_D(const QSortPolicy); |
| 160 | data.sortTypes = d->m_sortTypes; |
| 161 | return creationChange; |
| 162 | } |
| 163 | |
| 164 | /*! |
| 165 | \return the current sort types in use |
| 166 | */ |
| 167 | QVector<QSortPolicy::SortType> QSortPolicy::sortTypes() const |
| 168 | { |
| 169 | Q_D(const QSortPolicy); |
| 170 | return d->m_sortTypes; |
| 171 | } |
| 172 | |
| 173 | QVector<int> QSortPolicy::sortTypesInt() const |
| 174 | { |
| 175 | Q_D(const QSortPolicy); |
| 176 | QVector<int> sortTypesInt; |
| 177 | transformVector(input: d->m_sortTypes, output&: sortTypesInt); |
| 178 | return sortTypesInt; |
| 179 | } |
| 180 | |
| 181 | void QSortPolicy::setSortTypes(const QVector<SortType> &sortTypes) |
| 182 | { |
| 183 | Q_D(QSortPolicy); |
| 184 | if (sortTypes != d->m_sortTypes) { |
| 185 | d->m_sortTypes = sortTypes; |
| 186 | emit sortTypesChanged(sortTypes); |
| 187 | |
| 188 | const bool wasBlocked = blockNotifications(block: true); |
| 189 | emit sortTypesChanged(sortTypes: sortTypesInt()); |
| 190 | blockNotifications(block: wasBlocked); |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | void QSortPolicy::setSortTypes(const QVector<int> &sortTypesInt) |
| 195 | { |
| 196 | QVector<SortType> sortTypes; |
| 197 | transformVector(input: sortTypesInt, output&: sortTypes); |
| 198 | setSortTypes(sortTypes); |
| 199 | } |
| 200 | |
| 201 | } // namespace Qt3DRender |
| 202 | |
| 203 | QT_END_NAMESPACE |
| 204 | |