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
42QT_BEGIN_NAMESPACE
43
44QShaderFormat::QShaderFormat() noexcept
45 : m_api(NoApi)
46 , m_shaderType(Fragment)
47{
48}
49
50QShaderFormat::Api QShaderFormat::api() const noexcept
51{
52 return m_api;
53}
54
55void QShaderFormat::setApi(QShaderFormat::Api api) noexcept
56{
57 m_api = api;
58}
59
60QVersionNumber QShaderFormat::version() const noexcept
61{
62 return m_version;
63}
64
65void QShaderFormat::setVersion(const QVersionNumber &version) noexcept
66{
67 m_version = version;
68}
69
70QStringList QShaderFormat::extensions() const noexcept
71{
72 return m_extensions;
73}
74
75void QShaderFormat::setExtensions(const QStringList &extensions) noexcept
76{
77 m_extensions = extensions;
78 m_extensions.sort();
79}
80
81QString QShaderFormat::vendor() const noexcept
82{
83 return m_vendor;
84}
85
86void QShaderFormat::setVendor(const QString &vendor) noexcept
87{
88 m_vendor = vendor;
89}
90
91bool QShaderFormat::isValid() const noexcept
92{
93 return m_api != NoApi && m_version.majorVersion() > 0;
94}
95
96bool QShaderFormat::supports(const QShaderFormat &other) const noexcept
97{
98 if (!isValid() || !other.isValid())
99 return false;
100
101 if (m_api == OpenGLES && m_api != other.m_api)
102 return false;
103
104 if (m_api == OpenGLCoreProfile && m_api != other.m_api)
105 return false;
106
107 if (m_version < other.m_version)
108 return false;
109
110 if (m_shaderType != other.m_shaderType)
111 return false;
112
113 const auto containsAllExtensionsFromOther = std::includes(m_extensions.constBegin(),
114 m_extensions.constEnd(),
115 other.m_extensions.constBegin(),
116 other.m_extensions.constEnd());
117 if (!containsAllExtensionsFromOther)
118 return false;
119
120 if (!other.m_vendor.isEmpty() && m_vendor != other.m_vendor)
121 return false;
122
123 return true;
124}
125
126QShaderFormat::ShaderType QShaderFormat::shaderType() const noexcept
127{
128 return m_shaderType;
129}
130
131void QShaderFormat::setShaderType(QShaderFormat::ShaderType shaderType) noexcept
132{
133 m_shaderType = shaderType;
134}
135
136bool operator==(const QShaderFormat &lhs, const QShaderFormat &rhs) noexcept
137{
138 return lhs.api() == rhs.api()
139 && lhs.version() == rhs.version()
140 && lhs.extensions() == rhs.extensions()
141 && lhs.vendor() == rhs.vendor()
142 && lhs.shaderType() == rhs.shaderType();
143}
144
145QT_END_NAMESPACE
146