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

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