Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qopenglversionprofile.cpp
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
6
7#include <QtCore/QDebug>
8
10
24
25/*!
26 \class QOpenGLVersionProfile
27 \inmodule QtOpenGL
28 \since 5.1
29 \brief The QOpenGLVersionProfile class represents the version and if applicable
30 the profile of an OpenGL context.
31
32 An object of this class can be passed to QOpenGLContext::versionFunctions() to
33 request a functions object for a specific version and profile of OpenGL.
34
35 It also contains some helper functions to check if a version supports profiles
36 or is a legacy version.
37*/
38
39/*!
40 Creates a default invalid QOpenGLVersionProfile object.
41*/
42QOpenGLVersionProfile::QOpenGLVersionProfile()
43 : d(new QOpenGLVersionProfilePrivate)
44{
45}
46
47/*!
48 Creates a QOpenGLVersionProfile object initialised with the version and profile
49 from \a format.
50*/
51QOpenGLVersionProfile::QOpenGLVersionProfile(const QSurfaceFormat &format)
52 : d(new QOpenGLVersionProfilePrivate)
53{
54 d->majorVersion = format.majorVersion();
55 d->minorVersion = format.minorVersion();
56 d->profile = format.profile();
57}
58
59/*!
60 Constructs a copy of \a other.
61*/
62QOpenGLVersionProfile::QOpenGLVersionProfile(const QOpenGLVersionProfile &other)
63 : d(new QOpenGLVersionProfilePrivate)
64{
65 *d = *(other.d);
66}
67
68/*!
69 Destroys the QOpenGLVersionProfile object.
70*/
71QOpenGLVersionProfile::~QOpenGLVersionProfile()
72{
73 delete d;
74}
75
76/*!
77 Assigns the version and profile of \a rhs to this QOpenGLVersionProfile object.
78*/
79QOpenGLVersionProfile &QOpenGLVersionProfile::operator=(const QOpenGLVersionProfile &rhs)
80{
81 if (this == &rhs)
82 return *this;
83 *d = *(rhs.d);
84 return *this;
85}
86
87/*!
88 Returns a std::pair<int,int> where the components represent the major and minor OpenGL
89 version numbers respectively.
90
91 \sa setVersion()
92*/
93std::pair<int, int> QOpenGLVersionProfile::version() const
94{
95 return std::pair( d->majorVersion, d->minorVersion);
96}
97
98/*!
99 Sets the major and minor version numbers to \a majorVersion and \a minorVersion respectively.
100
101 \sa version()
102*/
103void QOpenGLVersionProfile::setVersion(int majorVersion, int minorVersion)
104{
105 d->majorVersion = majorVersion;
106 d->minorVersion = minorVersion;
107}
108
109/*!
110 Returns the OpenGL profile. Only makes sense if profiles are supported by this version.
111
112 \sa setProfile()
113*/
114QSurfaceFormat::OpenGLContextProfile QOpenGLVersionProfile::profile() const
115{
116 return d->profile;
117}
118
119/*!
120 Sets the OpenGL profile \a profile. Only makes sense if profiles are supported by
121 this version.
122
123 \sa profile()
124*/
125void QOpenGLVersionProfile::setProfile(QSurfaceFormat::OpenGLContextProfile profile)
126{
127 d->profile = profile;
128}
129
130/*!
131 Returns \c true if profiles are supported by the OpenGL version returned by version(). Only
132 OpenGL versions >= 3.2 support profiles.
133
134 \sa profile(), version()
135*/
136bool QOpenGLVersionProfile::hasProfiles() const
137{
138 return ( d->majorVersion > 3
139 || (d->majorVersion == 3 && d->minorVersion > 1));
140}
141
142/*!
143 Returns \c true is the OpenGL version returned by version() contains deprecated functions
144 and does not support profiles i.e. if the OpenGL version is <= 3.1.
145*/
146bool QOpenGLVersionProfile::isLegacyVersion() const
147{
148 return (d->majorVersion < 3 || (d->majorVersion == 3 && d->minorVersion == 0));
149}
150
151/*!
152 Returns \c true if the version number is valid. Note that for a default constructed
153 QOpenGLVersionProfile object this function will return \c false.
154
155 \sa setVersion(), version()
156*/
157bool QOpenGLVersionProfile::isValid() const
158{
159 return d->majorVersion > 0 && d->minorVersion >= 0;
160}
161
162#ifndef QT_NO_DEBUG_STREAM
163QDebug operator<<(QDebug debug, const QOpenGLVersionProfile &vp)
164{
165 QDebugStateSaver saver(debug);
166 debug.nospace();
167 debug << "QOpenGLVersionProfile(";
168 if (vp.isValid()) {
169 debug << vp.version().first << '.' << vp.version().second
170 << ", profile=" << vp.profile();
171 } else {
172 debug << "invalid";
173 }
174 debug << ')';
175 return debug;
176}
177
178#endif // QT_NO_DEBUG_STREAM
179QT_END_NAMESPACE
QSurfaceFormat::OpenGLContextProfile profile
Combined button and popup list for selecting options.