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

source code of qtbase/src/opengl/qopenglversionfunctionsfactory.cpp