| 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 "qalphatest.h" | 
| 42 | #include "qalphatest_p.h" | 
| 43 | #include <Qt3DRender/private/qrenderstatecreatedchange_p.h> | 
| 44 |  | 
| 45 | QT_BEGIN_NAMESPACE | 
| 46 |  | 
| 47 | namespace Qt3DRender { | 
| 48 |  | 
| 49 | /*! | 
| 50 |     \class Qt3DRender::QAlphaTest | 
| 51 |     \brief The QAlphaTest class specify alpha reference test. | 
| 52 |     \since 5.7 | 
| 53 |     \inmodule Qt3DRender | 
| 54 |     \ingroup renderstates | 
| 55 |  | 
| 56 |     As the OpenGL documentation explains; The alpha test discards a fragment | 
| 57 |     conditional on the outcome of a comparison between the incoming fragment's | 
| 58 |     alpha value and a constant reference value. | 
| 59 |  */ | 
| 60 |  | 
| 61 | /*! | 
| 62 |     \qmltype AlphaTest | 
| 63 |     \brief The AlphaTest class specify alpha reference test. | 
| 64 |     \since 5.7 | 
| 65 |     \inqmlmodule Qt3D.Render | 
| 66 |     \inherits RenderState | 
| 67 |     \instantiates Qt3DRender::QAlphaTest | 
| 68 |     \ingroup renderstates | 
| 69 |  | 
| 70 |     As the OpenGL documentation explains; The alpha test discards a fragment | 
| 71 |     conditional on the outcome of a comparison between the incoming fragment's | 
| 72 |     alpha value and a constant reference value. | 
| 73 |  */ | 
| 74 |  | 
| 75 | /*! | 
| 76 |     \enum Qt3DRender::QAlphaTest::AlphaFunction | 
| 77 |  | 
| 78 |     Enumeration for the alpha function values | 
| 79 |     \value Never Never pass alpha test | 
| 80 |     \value Always Always pass alpha test | 
| 81 |     \value Less Pass alpha test if fragment alpha is less than reference value | 
| 82 |     \value LessOrEqual Pass alpha test if fragment alpha is less than or equal to reference value | 
| 83 |     \value Equal Pass alpha test if fragment alpha is equal to reference value | 
| 84 |     \value GreaterOrEqual Pass alpha test if fragment alpha is greater than or equal to reference value | 
| 85 |     \value Greater Pass alpha test if fragment alpha is greater than reference value | 
| 86 |     \value NotEqual Pass alpha test if fragment alpha is not equal to reference value | 
| 87 | */ | 
| 88 |  | 
| 89 | /*! | 
| 90 |     \qmlproperty enumeration AlphaTest::alphaFunction | 
| 91 |     Holds the alpha function used by the alpha test. Default is AlphaTest.Never. | 
| 92 |     \list | 
| 93 |     \li AlphaTest.Never | 
| 94 |     \li AlphaTest.Always | 
| 95 |     \li AlphaTest.Less | 
| 96 |     \li AlphaTest.LessOrEqual | 
| 97 |     \li AlphaTest.Equal | 
| 98 |     \li AlphaTest.GreaterOrEqual | 
| 99 |     \li AlphaTest.Greater | 
| 100 |     \li AlphaTest.NotEqual | 
| 101 |     \endlist | 
| 102 |     \sa Qt3DRender::QAlphaTest::AlphaFunction | 
| 103 | */ | 
| 104 |  | 
| 105 | /*! | 
| 106 |     \qmlproperty real AlphaTest::referenceValue | 
| 107 |     Holds the reference value used by the alpha test. Default is 0.0. | 
| 108 |     When set, the value is clamped between 0 and 1. | 
| 109 | */ | 
| 110 |  | 
| 111 | /*! | 
| 112 |     \property QAlphaTest::alphaFunction | 
| 113 |     Holds the alpha function used by the alpha test. Default is Never. | 
| 114 | */ | 
| 115 |  | 
| 116 | /*! | 
| 117 |     \property QAlphaTest::referenceValue | 
| 118 |     Holds the reference value used by the alpha test. Default is 0.0. | 
| 119 |     When set, the value is clamped between 0 and 1. | 
| 120 | */ | 
| 121 |  | 
| 122 |  | 
| 123 | QAlphaTest::QAlphaTest(QNode *parent) | 
| 124 |     : QRenderState(*new QAlphaTestPrivate, parent) | 
| 125 | { | 
| 126 | } | 
| 127 |  | 
| 128 | /*! \internal */ | 
| 129 | QAlphaTest::~QAlphaTest() | 
| 130 | { | 
| 131 | } | 
| 132 |  | 
| 133 | QAlphaTest::AlphaFunction QAlphaTest::alphaFunction() const | 
| 134 | { | 
| 135 |     Q_D(const QAlphaTest); | 
| 136 |     return d->m_alphaFunction; | 
| 137 | } | 
| 138 |  | 
| 139 | void QAlphaTest::setAlphaFunction(QAlphaTest::AlphaFunction alphaFunction) | 
| 140 | { | 
| 141 |     Q_D(QAlphaTest); | 
| 142 |     if (d->m_alphaFunction != alphaFunction) { | 
| 143 |         d->m_alphaFunction = alphaFunction; | 
| 144 |         emit alphaFunctionChanged(alphaFunction); | 
| 145 |     } | 
| 146 | } | 
| 147 |  | 
| 148 | float QAlphaTest::referenceValue() const | 
| 149 | { | 
| 150 |     Q_D(const QAlphaTest); | 
| 151 |     return d->m_referenceValue; | 
| 152 | } | 
| 153 |  | 
| 154 | void QAlphaTest::setReferenceValue(float referenceValue) | 
| 155 | { | 
| 156 |     Q_D(QAlphaTest); | 
| 157 |     if (d->m_referenceValue != referenceValue) { | 
| 158 |         d->m_referenceValue = referenceValue; | 
| 159 |         emit referenceValueChanged(referenceValue); | 
| 160 |     } | 
| 161 | } | 
| 162 |  | 
| 163 | Qt3DCore::QNodeCreatedChangeBasePtr QAlphaTest::createNodeCreationChange() const | 
| 164 | { | 
| 165 |     auto creationChange = QRenderStateCreatedChangePtr<QAlphaTestData>::create(arguments: this); | 
| 166 |     auto &data = creationChange->data; | 
| 167 |     Q_D(const QAlphaTest); | 
| 168 |     data.alphaFunction = d->m_alphaFunction; | 
| 169 |     data.referenceValue = d->m_referenceValue; | 
| 170 |     return creationChange; | 
| 171 | } | 
| 172 |  | 
| 173 | } // namespace Qt3DRender | 
| 174 |  | 
| 175 | QT_END_NAMESPACE | 
| 176 |  |