1/****************************************************************************
2**
3** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt3D 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 "qgraphicsapifilter.h"
41#include "qgraphicsapifilter_p.h"
42#include "private/qobject_p.h"
43#include <QOpenGLContext>
44
45QT_BEGIN_NAMESPACE
46
47namespace Qt3DRender {
48
49GraphicsApiFilterData::GraphicsApiFilterData()
50 : m_api(QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL ? QGraphicsApiFilter::OpenGL : QGraphicsApiFilter::OpenGLES)
51 , m_profile(QGraphicsApiFilter::NoProfile) // matches all (no profile, core, compat)
52 , m_minor(0)
53 , m_major(0)
54{}
55
56QString GraphicsApiFilterData::toString() const
57{
58 QLatin1String api;
59 switch (m_api) {
60 case QGraphicsApiFilter::OpenGL: api = QLatin1String("OpenGL"); break;
61 case QGraphicsApiFilter::OpenGLES: api = QLatin1String("OpenGL"); break;
62 case QGraphicsApiFilter::Vulkan: api = QLatin1String("Vulkan"); break;
63 case QGraphicsApiFilter::DirectX: api = QLatin1String("DirectX"); break;
64 case QGraphicsApiFilter::RHI: api = QLatin1String("RHI"); break;
65 default: Q_UNREACHABLE();
66 }
67
68 QLatin1String profile;
69 switch (m_profile) {
70 case QGraphicsApiFilter::CoreProfile: profile = QLatin1String(" (Core Profile)"); break;
71 case QGraphicsApiFilter::CompatibilityProfile: profile = QLatin1String(" (Compatibility Profile)"); break;
72 default: break;
73 }
74
75 return QString(QLatin1String("%1 %2.%3%4 (%5)").arg(args&: api, args: QString::number(m_major), args: QString::number(m_minor), args&: profile, args: m_vendor));
76}
77
78bool GraphicsApiFilterData::operator ==(const GraphicsApiFilterData &other) const
79{
80 // Check API
81 if (other.m_api != m_api)
82 return false;
83
84 // Check versions
85 const bool versionsCompatible = other.m_major < m_major
86 || (other.m_major == m_major && other.m_minor <= m_minor);
87 if (!versionsCompatible)
88 return false;
89
90 // Check profiles if requiring OpenGL (profiles not relevant for OpenGL ES)
91 if (other.m_api == QGraphicsApiFilter::OpenGL) {
92 const bool profilesCompatible = m_profile != QGraphicsApiFilter::CoreProfile
93 || other.m_profile == m_profile;
94 if (!profilesCompatible)
95 return false;
96 }
97
98 // Check extensions
99 for (const QString &neededExt : other.m_extensions) {
100 if (!m_extensions.contains(str: neededExt))
101 return false;
102 }
103
104 // Check vendor
105 if (!other.m_vendor.isEmpty())
106 return (other.m_vendor == m_vendor);
107
108 // If we get here everything looks good :)
109 return true;
110}
111
112bool GraphicsApiFilterData::operator <(const GraphicsApiFilterData &other) const
113{
114 if (this->m_major > other.m_major)
115 return false;
116 if (this->m_major == other.m_major &&
117 this->m_minor > other.m_minor)
118 return false;
119 return true;
120}
121
122bool GraphicsApiFilterData::operator !=(const GraphicsApiFilterData &other) const
123{
124 return !(*this == other);
125}
126
127QGraphicsApiFilterPrivate *QGraphicsApiFilterPrivate::get(QGraphicsApiFilter *q)
128{
129 return q->d_func();
130}
131
132const QGraphicsApiFilterPrivate *QGraphicsApiFilterPrivate::get(const QGraphicsApiFilter *q)
133{
134 return q->d_func();
135}
136
137/*!
138 \class Qt3DRender::QGraphicsApiFilter
139 \inmodule Qt3DRender
140 \since 5.5
141 \brief The QGraphicsApiFilter class identifies the API required for the attached QTechnique.
142*/
143
144/*!
145 \qmltype GraphicsApiFilter
146 \instantiates Qt3DRender::QGraphicsApiFilter
147 \inherits QtObject
148 \inqmlmodule Qt3D.Render
149 \since 5.5
150 \brief For OpenGL identifies the API required for the attached technique.
151*/
152
153/*! \fn Qt3DRender::QGraphicsApiFilter::QGraphicsApiFilter(QObject *parent)
154 Constructs a new QGraphicsApiFilter with the specified \a parent.
155 */
156QGraphicsApiFilter::QGraphicsApiFilter(QObject *parent)
157 : QObject(*new QGraphicsApiFilterPrivate, parent)
158{
159}
160
161/*! \internal */
162QGraphicsApiFilter::~QGraphicsApiFilter()
163{
164}
165
166/*!
167 \enum Qt3DRender::QGraphicsApiFilter::Api
168
169 \value OpenGLES QSurfaceFormat::OpenGLES
170 \value OpenGL QSurfaceFormat::OpenGL
171 \value Vulkan Vulkan
172 \value DirectX DirectX
173
174*/
175
176/*!
177 \enum Qt3DRender::QGraphicsApiFilter::OpenGLProfile
178
179 This enum identifies the type of profile required.
180
181 \value NoProfile QSurfaceFormat::NoProfile
182 \value CoreProfile QSurfaceFormat::CoreProfile
183 \value CompatibilityProfile QSurfaceFormat::CompatibilityProfile
184
185*/
186
187/*!
188 \property Qt3DRender::QGraphicsApiFilter::api
189
190*/
191
192/*!
193 \qmlproperty enumeration Qt3D.Render::GraphicsApiFilter::api
194
195
196 \value OpenGLES QSurfaceFormat::OpenGLES
197 \value OpenGL QSurfaceFormat::OpenGL
198*/
199
200QGraphicsApiFilter::Api QGraphicsApiFilter::api() const
201{
202 Q_D(const QGraphicsApiFilter);
203 return d->m_data.m_api;
204}
205
206/*!
207 \property Qt3DRender::QGraphicsApiFilter::profile
208
209*/
210
211/*!
212 \qmlproperty enumeration Qt3D.Render::GraphicsApiFilter::profile
213
214 \value NoProfile QSurfaceFormat::NoProfile
215 \value CoreProfile QSurfaceFormat::CoreProfile
216 \value CompatibilityProfile QSurfaceFormat::CompatibilityProfile
217*/
218
219QGraphicsApiFilter::OpenGLProfile QGraphicsApiFilter::profile() const
220{
221 Q_D(const QGraphicsApiFilter);
222 return d->m_data.m_profile;
223}
224
225/*!
226 \property Qt3DRender::QGraphicsApiFilter::minorVersion
227
228 */
229
230/*!
231 \qmlproperty int Qt3D.Render::GraphicsApiFilter::minorVersion
232
233*/
234
235int QGraphicsApiFilter::minorVersion() const
236{
237 Q_D(const QGraphicsApiFilter);
238 return d->m_data.m_minor;
239}
240
241/*!
242 \property Qt3DRender::QGraphicsApiFilter::majorVersion
243
244 */
245
246/*!
247 \qmlproperty int Qt3D.Render::GraphicsApiFilter::majorVersion
248
249*/
250
251int QGraphicsApiFilter::majorVersion() const
252{
253 Q_D(const QGraphicsApiFilter);
254 return d->m_data.m_major;
255}
256
257/*!
258 \property Qt3DRender::QGraphicsApiFilter::extensions
259
260 */
261
262/*!
263 \qmlproperty stringlist Qt3D.Render::GraphicsApiFilter::extensions
264
265*/
266
267QStringList QGraphicsApiFilter::extensions() const
268{
269 Q_D(const QGraphicsApiFilter);
270 return d->m_data.m_extensions;
271}
272
273/*!
274 \property Qt3DRender::QGraphicsApiFilter::vendor
275
276 */
277
278/*!
279 \qmlproperty string Qt3D.Render::GraphicsApiFilter::vendor
280
281*/
282
283QString QGraphicsApiFilter::vendor() const
284{
285 Q_D(const QGraphicsApiFilter);
286 return d->m_data.m_vendor;
287}
288
289void QGraphicsApiFilter::setApi(QGraphicsApiFilter::Api api)
290{
291 Q_D(QGraphicsApiFilter);
292 if (d->m_data.m_api != api) {
293 d->m_data.m_api = api;
294 emit apiChanged(api);
295 emit graphicsApiFilterChanged();
296 }
297}
298
299void QGraphicsApiFilter::setProfile(QGraphicsApiFilter::OpenGLProfile profile)
300{
301 Q_D(QGraphicsApiFilter);
302 if (d->m_data.m_profile != profile) {
303 d->m_data.m_profile = profile;
304 emit profileChanged(profile);
305 emit graphicsApiFilterChanged();
306 }
307}
308
309void QGraphicsApiFilter::setMinorVersion(int minorVersion)
310{
311 Q_D(QGraphicsApiFilter);
312 if (minorVersion != d->m_data.m_minor) {
313 d->m_data.m_minor = minorVersion;
314 emit minorVersionChanged(minorVersion);
315 emit graphicsApiFilterChanged();
316 }
317}
318
319void QGraphicsApiFilter::setMajorVersion(int majorVersion)
320{
321 Q_D(QGraphicsApiFilter);
322 if (d->m_data.m_major != majorVersion) {
323 d->m_data.m_major = majorVersion;
324 emit majorVersionChanged(majorVersion);
325 emit graphicsApiFilterChanged();
326 }
327}
328
329void QGraphicsApiFilter::setExtensions(const QStringList &extensions)
330{
331 Q_D(QGraphicsApiFilter);
332 if (d->m_data.m_extensions != extensions) {
333 d->m_data.m_extensions = extensions;
334 emit extensionsChanged(extensions);
335 emit graphicsApiFilterChanged();
336 }
337}
338
339void QGraphicsApiFilter::setVendor(const QString &vendor)
340{
341 Q_D(QGraphicsApiFilter);
342 if (d->m_data.m_vendor != vendor) {
343 d->m_data.m_vendor = vendor;
344 emit vendorChanged(vendor);
345 emit graphicsApiFilterChanged();
346 }
347}
348
349/*! \fn bool Qt3DRender::operator ==(const QGraphicsApiFilter &reference, const QGraphicsApiFilter &sample)
350 \relates Qt3DRender::QGraphicsApiFilter
351
352 Returns \c true if \a reference and \a sample are equivalent.
353 */
354bool operator ==(const QGraphicsApiFilter &reference, const QGraphicsApiFilter &sample)
355{
356 return QGraphicsApiFilterPrivate::get(q: const_cast<QGraphicsApiFilter *>(&reference))->m_data ==
357 QGraphicsApiFilterPrivate::get(q: const_cast<QGraphicsApiFilter *>(&sample))->m_data;
358}
359
360/*! \fn bool Qt3DRender::operator !=(const QGraphicsApiFilter &reference, const QGraphicsApiFilter &sample)
361 \relates Qt3DRender::QGraphicsApiFilter
362
363 Returns \c true if \a reference and \a sample are different.
364 */
365bool operator !=(const QGraphicsApiFilter &reference, const QGraphicsApiFilter &sample)
366{
367 return !(reference == sample);
368}
369
370/*! \fn void Qt3DRender::QGraphicsApiFilter::graphicsApiFilterChanged()
371 This signal is emitted when the value of any property is changed.
372*/
373} // namespace Qt3DRender
374
375QT_END_NAMESPACE
376

source code of qt3d/src/render/materialsystem/qgraphicsapifilter.cpp