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
qopenglversionfunctionsfactory.cpp
Go to the documentation of this file.
1// Copyright (C) 2013 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** This file was generated by glgen version 0.1
5** Command line was: glgen
6**
7** glgen is Copyright (C) 2013 Klaralvdalens Datakonsult AB (KDAB)
8**
9** This is an auto-generated file.
10** Do not edit! All changes made to it will be lost.
11**
12****************************************************************************/
13// Qt-Security score:significant reason:default
14
17
18#if !QT_CONFIG(opengles2)
19#include "qopenglfunctions_4_5_core.h"
20#include "qopenglfunctions_4_5_compatibility.h"
21#include "qopenglfunctions_4_4_core.h"
22#include "qopenglfunctions_4_4_compatibility.h"
23#include "qopenglfunctions_4_3_core.h"
24#include "qopenglfunctions_4_3_compatibility.h"
25#include "qopenglfunctions_4_2_core.h"
26#include "qopenglfunctions_4_2_compatibility.h"
27#include "qopenglfunctions_4_1_core.h"
28#include "qopenglfunctions_4_1_compatibility.h"
29#include "qopenglfunctions_4_0_core.h"
30#include "qopenglfunctions_4_0_compatibility.h"
31#include "qopenglfunctions_3_3_core.h"
32#include "qopenglfunctions_3_3_compatibility.h"
33#include "qopenglfunctions_3_2_core.h"
34#include "qopenglfunctions_3_2_compatibility.h"
35#include "qopenglfunctions_3_1.h"
36#include "qopenglfunctions_3_0.h"
37#include "qopenglfunctions_2_1.h"
38#include "qopenglfunctions_2_0.h"
39#include "qopenglfunctions_1_5.h"
40#include "qopenglfunctions_1_4.h"
41#include "qopenglfunctions_1_3.h"
42#include "qopenglfunctions_1_2.h"
43#include "qopenglfunctions_1_1.h"
44#include "qopenglfunctions_1_0.h"
45#else
46#include "qopenglfunctions_es2.h"
47#endif
48
50
51static QAbstractOpenGLFunctions *createFunctions(const QOpenGLVersionProfile &versionProfile)
52{
53#if !QT_CONFIG(opengles2)
54 const int major = versionProfile.version().first;
55 const int minor = versionProfile.version().second;
56
57 if (versionProfile.hasProfiles()) {
58 switch (versionProfile.profile()) {
59 case QSurfaceFormat::CoreProfile:
60 if (major == 4 && minor == 5)
61 return new QOpenGLFunctions_4_5_Core;
62 else if (major == 4 && minor == 4)
63 return new QOpenGLFunctions_4_4_Core;
64 else if (major == 4 && minor == 3)
65 return new QOpenGLFunctions_4_3_Core;
66 else if (major == 4 && minor == 2)
67 return new QOpenGLFunctions_4_2_Core;
68 else if (major == 4 && minor == 1)
69 return new QOpenGLFunctions_4_1_Core;
70 else if (major == 4 && minor == 0)
71 return new QOpenGLFunctions_4_0_Core;
72 else if (major == 3 && minor == 3)
73 return new QOpenGLFunctions_3_3_Core;
74 else if (major == 3 && minor == 2)
75 return new QOpenGLFunctions_3_2_Core;
76 break;
77
78 case QSurfaceFormat::CompatibilityProfile:
79 if (major == 4 && minor == 5)
80 return new QOpenGLFunctions_4_5_Compatibility;
81 else if (major == 4 && minor == 4)
82 return new QOpenGLFunctions_4_4_Compatibility;
83 else if (major == 4 && minor == 3)
84 return new QOpenGLFunctions_4_3_Compatibility;
85 else if (major == 4 && minor == 2)
86 return new QOpenGLFunctions_4_2_Compatibility;
87 else if (major == 4 && minor == 1)
88 return new QOpenGLFunctions_4_1_Compatibility;
89 else if (major == 4 && minor == 0)
90 return new QOpenGLFunctions_4_0_Compatibility;
91 else if (major == 3 && minor == 3)
92 return new QOpenGLFunctions_3_3_Compatibility;
93 else if (major == 3 && minor == 2)
94 return new QOpenGLFunctions_3_2_Compatibility;
95 break;
96
97 case QSurfaceFormat::NoProfile:
98 default:
99 break;
100 };
101 } else {
102 if (major == 3 && minor == 1)
103 return new QOpenGLFunctions_3_1;
104 else if (major == 3 && minor == 0)
105 return new QOpenGLFunctions_3_0;
106 else if (major == 2 && minor == 1)
107 return new QOpenGLFunctions_2_1;
108 else if (major == 2 && minor == 0)
109 return new QOpenGLFunctions_2_0;
110 else if (major == 1 && minor == 5)
111 return new QOpenGLFunctions_1_5;
112 else if (major == 1 && minor == 4)
113 return new QOpenGLFunctions_1_4;
114 else if (major == 1 && minor == 3)
115 return new QOpenGLFunctions_1_3;
116 else if (major == 1 && minor == 2)
117 return new QOpenGLFunctions_1_2;
118 else if (major == 1 && minor == 1)
119 return new QOpenGLFunctions_1_1;
120 else if (major == 1 && minor == 0)
121 return new QOpenGLFunctions_1_0;
122 }
123 return nullptr;
124#else
125 Q_UNUSED(versionProfile);
126 return new QOpenGLFunctions_ES2;
127#endif
128}
129
130/*!
131 \class QOpenGLVersionFunctionsFactory
132 \inmodule QtOpenGL
133 \since 6.0
134 \brief Provides access to OpenGL functions for a specified version and
135 profile.
136*/
137
138/*!
139 \fn template <class T> static T *QOpenGLVersionFunctionsFactory::get(QOpenGLContext *context)
140
141 \overload get()
142
143 Returns a pointer to an object that provides access to all functions for
144 the version and profile of this context. There is no need to call
145 QAbstractOpenGLFunctions::initializeOpenGLFunctions() as long as the \a context
146 is current. It is also possible to call this function when the \a context is not
147 current, but in that case it is the caller's responsibility to ensure proper
148 initialization by calling QAbstractOpenGLFunctions::initializeOpenGLFunctions()
149 afterwards.
150
151 Usually one would use the template version of this function to automatically
152 have the result cast to the correct type.
153
154 \code
155 auto funcs = QOpenGLVersionFunctionsFactory::get<QOpenGLFunctions_3_3_Core>(context);
156 if (!funcs) {
157 qFatal("Could not obtain required OpenGL context version");
158 }
159 \endcode
160
161 It is possible to request a functions object for a different version and profile
162 than that for which the context was created. To do this either use the template
163 version of this function specifying the desired functions object type as the
164 template parameter or by passing in a QOpenGLVersionProfile object as an argument
165 to the non-template function.
166
167 Note that requests for function objects of other versions or profiles can fail and
168 in doing so will return \nullptr. Situations in which creation of the functions
169 object can fail are if the request cannot be satisfied due to asking for functions
170 that are not in the version or profile of this context. For example:
171
172 \list
173 \li Requesting a 3.3 core profile functions object would succeed.
174 \li Requesting a 3.3 compatibility profile functions object would fail. We would fail
175 to resolve the deprecated functions.
176 \li Requesting a 4.3 core profile functions object would fail. We would fail to resolve
177 the new core functions introduced in versions 4.0-4.3.
178 \li Requesting a 3.1 functions object would succeed. There is nothing in 3.1 that is not
179 also in 3.3 core.
180 \endlist
181
182 Note that if creating a functions object via this method that the QOpenGLContext
183 retains ownership of the object. This is to allow the object to be cached and shared.
184*/
185
186/*!
187 Returns a pointer to an object that provides access to all functions for the
188 \a versionProfile of the \a context. There is no need to call
189 QAbstractOpenGLFunctions::initializeOpenGLFunctions() as long as the \a context
190 is current. It is also possible to call this function when the \a context is not
191 current, but in that case it is the caller's responsibility to ensure proper
192 initialization by calling QAbstractOpenGLFunctions::initializeOpenGLFunctions()
193 afterwards.
194
195 Usually one would use the template version of this function to automatically
196 have the result cast to the correct type.
197*/
198QAbstractOpenGLFunctions *QOpenGLVersionFunctionsFactory::get(const QOpenGLVersionProfile &versionProfile, QOpenGLContext *context)
199{
200 if (!context)
201 context = QOpenGLContext::currentContext();
202
203 if (!context) {
204 qWarning("versionFunctions: No OpenGL context");
205 return nullptr;
206 }
207
208#if !QT_CONFIG(opengles2)
209 if (context->isOpenGLES()) {
210 qWarning("versionFunctions: Not supported on OpenGL ES");
211 return nullptr;
212 }
213#endif // !QT_CONFIG(opengles2)
214
215 const QSurfaceFormat f = context->format();
216
217 // Ensure we have a valid version and profile. Default to context's if none specified
218 QOpenGLVersionProfile vp = versionProfile;
219 if (!vp.isValid())
220 vp = QOpenGLVersionProfile(f);
221
222 // Check that context is compatible with requested version
223 const auto v = std::pair(f.majorVersion(), f.minorVersion());
224 if (v < vp.version())
225 return nullptr;
226
227 // If this context only offers core profile functions then we can't create
228 // function objects for legacy or compatibility profile requests
229 if (((vp.hasProfiles() && vp.profile() != QSurfaceFormat::CoreProfile) || vp.isLegacyVersion())
230 && f.profile() == QSurfaceFormat::CoreProfile)
231 return nullptr;
232
233 // Create object if suitable one not cached
234 QAbstractOpenGLFunctions* funcs = nullptr;
235 // TODO: replace with something else
236 auto *data = QOpenGLContextVersionData::forContext(context);
237 auto it = data->functions.constFind(vp);
238 if (it == data->functions.constEnd()) {
239 funcs = createFunctions(vp);
240 if (funcs) {
241 funcs->setOwningContext(context);
242 data->functions.insert(vp, funcs);
243 }
244 } else {
245 funcs = it.value();
246 }
247
248 if (funcs && QOpenGLContext::currentContext() == context)
249 funcs->initializeOpenGLFunctions();
250
251 return funcs;
252}
253
254QT_END_NAMESPACE
Combined button and popup list for selecting options.
static QT_BEGIN_NAMESPACE QAbstractOpenGLFunctions * createFunctions(const QOpenGLVersionProfile &versionProfile)