| 1 | /**************************************************************************** | 
|---|---|
| 2 | ** | 
| 3 | ** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). | 
| 4 | ** Contact: https://www.qt.io/licensing/ | 
| 5 | ** | 
| 6 | ** This file is part of the QtGui 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 "qshaderformat_p.h" | 
| 41 | |
| 42 | QT_BEGIN_NAMESPACE | 
| 43 | namespace Qt3DRender | 
| 44 | { | 
| 45 | QShaderFormat::QShaderFormat() noexcept | 
| 46 | : m_api(NoApi) | 
| 47 | , m_shaderType(Fragment) | 
| 48 | { | 
| 49 | } | 
| 50 | |
| 51 | QShaderFormat::Api QShaderFormat::api() const noexcept | 
| 52 | { | 
| 53 | return m_api; | 
| 54 | } | 
| 55 | |
| 56 | void QShaderFormat::setApi(QShaderFormat::Api api) noexcept | 
| 57 | { | 
| 58 | m_api = api; | 
| 59 | } | 
| 60 | |
| 61 | QVersionNumber QShaderFormat::version() const noexcept | 
| 62 | { | 
| 63 | return m_version; | 
| 64 | } | 
| 65 | |
| 66 | void QShaderFormat::setVersion(const QVersionNumber &version) noexcept | 
| 67 | { | 
| 68 | m_version = version; | 
| 69 | } | 
| 70 | |
| 71 | QStringList QShaderFormat::extensions() const noexcept | 
| 72 | { | 
| 73 | return m_extensions; | 
| 74 | } | 
| 75 | |
| 76 | void QShaderFormat::setExtensions(const QStringList &extensions) noexcept | 
| 77 | { | 
| 78 | m_extensions = extensions; | 
| 79 | m_extensions.sort(); | 
| 80 | } | 
| 81 | |
| 82 | QString QShaderFormat::vendor() const noexcept | 
| 83 | { | 
| 84 | return m_vendor; | 
| 85 | } | 
| 86 | |
| 87 | void QShaderFormat::setVendor(const QString &vendor) noexcept | 
| 88 | { | 
| 89 | m_vendor = vendor; | 
| 90 | } | 
| 91 | |
| 92 | bool QShaderFormat::isValid() const noexcept | 
| 93 | { | 
| 94 | return m_api != NoApi && m_version.majorVersion() > 0; | 
| 95 | } | 
| 96 | |
| 97 | bool QShaderFormat::supports(const QShaderFormat &other) const noexcept | 
| 98 | { | 
| 99 | if (!isValid() || !other.isValid()) | 
| 100 | return false; | 
| 101 | |
| 102 | if (m_api == OpenGLES && m_api != other.m_api) | 
| 103 | return false; | 
| 104 | |
| 105 | if (m_api == OpenGLCoreProfile && m_api != other.m_api) | 
| 106 | return false; | 
| 107 | |
| 108 | if (m_api < VulkanFlavoredGLSL && other.m_api >= VulkanFlavoredGLSL) | 
| 109 | return false; | 
| 110 | |
| 111 | if (m_version < other.m_version) | 
| 112 | return false; | 
| 113 | |
| 114 | if (m_shaderType != other.m_shaderType) | 
| 115 | return false; | 
| 116 | |
| 117 | const auto containsAllExtensionsFromOther = std::includes(first1: m_extensions.constBegin(), | 
| 118 | last1: m_extensions.constEnd(), | 
| 119 | first2: other.m_extensions.constBegin(), | 
| 120 | last2: other.m_extensions.constEnd()); | 
| 121 | if (!containsAllExtensionsFromOther) | 
| 122 | return false; | 
| 123 | |
| 124 | if (!other.m_vendor.isEmpty() && m_vendor != other.m_vendor) | 
| 125 | return false; | 
| 126 | |
| 127 | return true; | 
| 128 | } | 
| 129 | |
| 130 | QShaderFormat::ShaderType QShaderFormat::shaderType() const Q_DECL_NOTHROW | 
| 131 | { | 
| 132 | return m_shaderType; | 
| 133 | } | 
| 134 | |
| 135 | void QShaderFormat::setShaderType(QShaderFormat::ShaderType shaderType) Q_DECL_NOTHROW | 
| 136 | { | 
| 137 | m_shaderType = shaderType; | 
| 138 | } | 
| 139 | |
| 140 | bool operator==(const QShaderFormat &lhs, const QShaderFormat &rhs) noexcept | 
| 141 | { | 
| 142 | return lhs.api() == rhs.api() | 
| 143 | && lhs.version() == rhs.version() | 
| 144 | && lhs.extensions() == rhs.extensions() | 
| 145 | && lhs.vendor() == rhs.vendor() | 
| 146 | && lhs.shaderType() == rhs.shaderType(); | 
| 147 | } | 
| 148 | } | 
| 149 | QT_END_NAMESPACE | 
| 150 | 
