1 | // Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #include "qshaderformat_p.h" |
5 | |
6 | QT_BEGIN_NAMESPACE |
7 | namespace Qt3DRender |
8 | { |
9 | QShaderFormat::QShaderFormat() noexcept |
10 | : m_api(NoApi) |
11 | , m_shaderType(Fragment) |
12 | { |
13 | } |
14 | |
15 | QShaderFormat::Api QShaderFormat::api() const noexcept |
16 | { |
17 | return m_api; |
18 | } |
19 | |
20 | void QShaderFormat::setApi(QShaderFormat::Api api) noexcept |
21 | { |
22 | m_api = api; |
23 | } |
24 | |
25 | QVersionNumber QShaderFormat::version() const noexcept |
26 | { |
27 | return m_version; |
28 | } |
29 | |
30 | void QShaderFormat::setVersion(const QVersionNumber &version) noexcept |
31 | { |
32 | m_version = version; |
33 | } |
34 | |
35 | QStringList QShaderFormat::extensions() const noexcept |
36 | { |
37 | return m_extensions; |
38 | } |
39 | |
40 | void QShaderFormat::setExtensions(const QStringList &extensions) noexcept |
41 | { |
42 | m_extensions = extensions; |
43 | m_extensions.sort(); |
44 | } |
45 | |
46 | QString QShaderFormat::vendor() const noexcept |
47 | { |
48 | return m_vendor; |
49 | } |
50 | |
51 | void QShaderFormat::setVendor(const QString &vendor) noexcept |
52 | { |
53 | m_vendor = vendor; |
54 | } |
55 | |
56 | bool QShaderFormat::isValid() const noexcept |
57 | { |
58 | return m_api != NoApi && m_version.majorVersion() > 0; |
59 | } |
60 | |
61 | bool QShaderFormat::supports(const QShaderFormat &other) const noexcept |
62 | { |
63 | if (!isValid() || !other.isValid()) |
64 | return false; |
65 | |
66 | if (m_api == OpenGLES && m_api != other.m_api) |
67 | return false; |
68 | |
69 | if (m_api == OpenGLCoreProfile && m_api != other.m_api) |
70 | return false; |
71 | |
72 | if (m_api < VulkanFlavoredGLSL && other.m_api >= VulkanFlavoredGLSL) |
73 | return false; |
74 | |
75 | if (m_version < other.m_version) |
76 | return false; |
77 | |
78 | if (m_shaderType != other.m_shaderType) |
79 | return false; |
80 | |
81 | const auto containsAllExtensionsFromOther = std::includes(first1: m_extensions.constBegin(), |
82 | last1: m_extensions.constEnd(), |
83 | first2: other.m_extensions.constBegin(), |
84 | last2: other.m_extensions.constEnd()); |
85 | if (!containsAllExtensionsFromOther) |
86 | return false; |
87 | |
88 | if (!other.m_vendor.isEmpty() && m_vendor != other.m_vendor) |
89 | return false; |
90 | |
91 | return true; |
92 | } |
93 | |
94 | QShaderFormat::ShaderType QShaderFormat::shaderType() const noexcept |
95 | { |
96 | return m_shaderType; |
97 | } |
98 | |
99 | void QShaderFormat::setShaderType(QShaderFormat::ShaderType shaderType) noexcept |
100 | { |
101 | m_shaderType = shaderType; |
102 | } |
103 | |
104 | bool operator==(const QShaderFormat &lhs, const QShaderFormat &rhs) noexcept |
105 | { |
106 | return lhs.api() == rhs.api() |
107 | && lhs.version() == rhs.version() |
108 | && lhs.extensions() == rhs.extensions() |
109 | && lhs.vendor() == rhs.vendor() |
110 | && lhs.shaderType() == rhs.shaderType(); |
111 | } |
112 | } |
113 | QT_END_NAMESPACE |
114 |