50static QAbstractOpenGLFunctions *
createFunctions(
const QOpenGLVersionProfile &versionProfile)
52#if !QT_CONFIG(opengles2)
53 const int major = versionProfile.version().first;
54 const int minor = versionProfile.version().second;
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;
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;
96 case QSurfaceFormat::NoProfile:
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;
124 Q_UNUSED(versionProfile);
125 return new QOpenGLFunctions_ES2;
197QAbstractOpenGLFunctions *QOpenGLVersionFunctionsFactory::get(
const QOpenGLVersionProfile &versionProfile, QOpenGLContext *context)
200 context = QOpenGLContext::currentContext();
203 qWarning(
"versionFunctions: No OpenGL context");
207#if !QT_CONFIG(opengles2)
208 if (context->isOpenGLES()) {
209 qWarning(
"versionFunctions: Not supported on OpenGL ES");
214 const QSurfaceFormat f = context->format();
217 QOpenGLVersionProfile vp = versionProfile;
219 vp = QOpenGLVersionProfile(f);
222 const auto v = std::pair(f.majorVersion(), f.minorVersion());
223 if (v < vp.version())
228 if (((vp.hasProfiles() && vp.profile() != QSurfaceFormat::CoreProfile) || vp.isLegacyVersion())
229 && f.profile() == QSurfaceFormat::CoreProfile)
233 QAbstractOpenGLFunctions* funcs =
nullptr;
235 auto *data = QOpenGLContextVersionData::forContext(context);
236 auto it = data->functions.constFind(vp);
237 if (it == data->functions.constEnd()) {
238 funcs = createFunctions(vp);
240 funcs->setOwningContext(context);
241 data->functions.insert(vp, funcs);
247 if (funcs && QOpenGLContext::currentContext() == context)
248 funcs->initializeOpenGLFunctions();