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