| 1 | /**************************************************************************** | 
| 2 | ** | 
| 3 | ** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). | 
| 4 | ** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies). | 
| 5 | ** Contact: https://www.qt.io/licensing/ | 
| 6 | ** | 
| 7 | ** This file is part of the Qt3D module of the Qt Toolkit. | 
| 8 | ** | 
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | 
| 10 | ** Commercial License Usage | 
| 11 | ** Licensees holding valid commercial Qt licenses may use this file in | 
| 12 | ** accordance with the commercial license agreement provided with the | 
| 13 | ** Software or, alternatively, in accordance with the terms contained in | 
| 14 | ** a written agreement between you and The Qt Company. For licensing terms | 
| 15 | ** and conditions see https://www.qt.io/terms-conditions. For further | 
| 16 | ** information use the contact form at https://www.qt.io/contact-us. | 
| 17 | ** | 
| 18 | ** GNU Lesser General Public License Usage | 
| 19 | ** Alternatively, this file may be used under the terms of the GNU Lesser | 
| 20 | ** General Public License version 3 as published by the Free Software | 
| 21 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | 
| 22 | ** packaging of this file. Please review the following information to | 
| 23 | ** ensure the GNU Lesser General Public License version 3 requirements | 
| 24 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | 
| 25 | ** | 
| 26 | ** GNU General Public License Usage | 
| 27 | ** Alternatively, this file may be used under the terms of the GNU | 
| 28 | ** General Public License version 2.0 or (at your option) the GNU General | 
| 29 | ** Public license version 3 or any later version approved by the KDE Free | 
| 30 | ** Qt Foundation. The licenses are as published by the Free Software | 
| 31 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | 
| 32 | ** included in the packaging of this file. Please review the following | 
| 33 | ** information to ensure the GNU General Public License requirements will | 
| 34 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | 
| 35 | ** https://www.gnu.org/licenses/gpl-3.0.html. | 
| 36 | ** | 
| 37 | ** $QT_END_LICENSE$ | 
| 38 | ** | 
| 39 | ****************************************************************************/ | 
| 40 |  | 
| 41 | #include "qdepthtest.h" | 
| 42 | #include "qdepthtest_p.h" | 
| 43 | #include <Qt3DRender/private/qrenderstatecreatedchange_p.h> | 
| 44 |  | 
| 45 | QT_BEGIN_NAMESPACE | 
| 46 |  | 
| 47 | namespace Qt3DRender { | 
| 48 |  | 
| 49 | /*! | 
| 50 |     \class Qt3DRender::QDepthTest | 
| 51 |     \brief The QDepthTest class tests the fragment shader's depth value against | 
| 52 |     the depth of a sample being written to. | 
| 53 |     \since 5.7 | 
| 54 |     \inmodule Qt3DRender | 
| 55 |     \ingroup renderstates | 
| 56 |  | 
| 57 |     A QDepthTest class is used to enable depth testing with a given depth test function. | 
| 58 |     The depth test enables writing fragment color values when the depth test passes, and | 
| 59 |     reject fragments which fail the test. The depth test uses the depth function to | 
| 60 |     test the fragments depth value to the value against z-buffer. If the underlying surface | 
| 61 |     does not have z-buffer, then QDepthTest does nothing. | 
| 62 |  | 
| 63 |     \sa QAlphaTest, QStencilTest | 
| 64 |  */ | 
| 65 |  | 
| 66 | /*! | 
| 67 |     \qmltype DepthTest | 
| 68 |     \brief The DepthTest type tests the fragment shader's depth value against | 
| 69 |     the depth of a sample being written to. | 
| 70 |     \since 5.7 | 
| 71 |     \inqmlmodule Qt3D.Render | 
| 72 |     \inherits RenderState | 
| 73 |     \instantiates Qt3DRender::QDepthTest | 
| 74 |     \ingroup renderstates | 
| 75 |  | 
| 76 |     A DepthTest type is used to enable depth testing with a given depth test function. | 
| 77 |     The depth test enables writing fragment color values when the depth test passes, and | 
| 78 |     reject fragments which fail the test. The depth test uses the depth function to | 
| 79 |     test the fragments depth value to the value against z-buffer. If the underlying surface | 
| 80 |     does not have z-buffer, the DepthTest does nothing. | 
| 81 |  | 
| 82 |     \sa AlphaTest, StencilTest | 
| 83 |  */ | 
| 84 |  | 
| 85 | /*! | 
| 86 |     \enum Qt3DRender::QDepthTest::DepthFunction | 
| 87 |  | 
| 88 |     Enumeration for the depth function values | 
| 89 |     \value Never Never pass depth test | 
| 90 |     \value Always Always pass depth test | 
| 91 |     \value Less Pass depth test if fragment depth is less than z-buffer value | 
| 92 |     \value LessOrEqual Pass depth test if fragment depth is less than or equal to z-buffer value | 
| 93 |     \value Equal Pass depth test if fragment depth is equal to z-buffer value | 
| 94 |     \value GreaterOrEqual Pass depth test if fragment depth is greater than or equal to z-buffer value | 
| 95 |     \value Greater Pass depth test if fragment depth is greater than z-buffer value | 
| 96 |     \value NotEqual Pass depth test if fragment depth is not equal to z-buffer value | 
| 97 | */ | 
| 98 |  | 
| 99 | /*! | 
| 100 |     \qmlproperty enumeration DepthTest::depthFunction | 
| 101 |     Holds the current function used by depth test. The default is DepthTest.Never. | 
| 102 |     \list | 
| 103 |     \li DepthTest.Never | 
| 104 |     \li DepthTest.Always | 
| 105 |     \li DepthTest.Less | 
| 106 |     \li DepthTest.LessOrEqual | 
| 107 |     \li DepthTest.Equal | 
| 108 |     \li DepthTest.GreaterOrEqual | 
| 109 |     \li DepthTest.Greater | 
| 110 |     \li DepthTest.NotEqual | 
| 111 |     \endlist | 
| 112 |     \sa Qt3DRender::QDepthTest::DepthFunction | 
| 113 | */ | 
| 114 |  | 
| 115 | /*! | 
| 116 |     \property QDepthTest::depthFunction | 
| 117 |     Holds the current function used by depth test. The default is Never. | 
| 118 | */ | 
| 119 |  | 
| 120 |  | 
| 121 | /*! | 
| 122 |     The constructor creates a new QDepthTest::QDepthTest instance with the specified \a parent. | 
| 123 |  */ | 
| 124 | QDepthTest::QDepthTest(QNode *parent) | 
| 125 |     : QRenderState(*new QDepthTestPrivate, parent) | 
| 126 | { | 
| 127 | } | 
| 128 |  | 
| 129 | /*! \internal */ | 
| 130 | QDepthTest::~QDepthTest() | 
| 131 | { | 
| 132 | } | 
| 133 |  | 
| 134 | QDepthTest::DepthFunction QDepthTest::depthFunction() const | 
| 135 | { | 
| 136 |     Q_D(const QDepthTest); | 
| 137 |     return d->m_depthFunction; | 
| 138 | } | 
| 139 |  | 
| 140 | void QDepthTest::setDepthFunction(QDepthTest::DepthFunction depthFunction) | 
| 141 | { | 
| 142 |     Q_D(QDepthTest); | 
| 143 |     if (d->m_depthFunction != depthFunction) { | 
| 144 |         d->m_depthFunction = depthFunction; | 
| 145 |         emit depthFunctionChanged(depthFunction); | 
| 146 |     } | 
| 147 | } | 
| 148 |  | 
| 149 | Qt3DCore::QNodeCreatedChangeBasePtr QDepthTest::createNodeCreationChange() const | 
| 150 | { | 
| 151 |     auto creationChange = QRenderStateCreatedChangePtr<QDepthTestData>::create(arguments: this); | 
| 152 |     auto &data = creationChange->data; | 
| 153 |     Q_D(const QDepthTest); | 
| 154 |     data.depthFunction = d->m_depthFunction; | 
| 155 |     return creationChange; | 
| 156 | } | 
| 157 |  | 
| 158 | } // namespace Qt3DRender | 
| 159 |  | 
| 160 | QT_END_NAMESPACE | 
| 161 |  |