51static QAbstractOpenGLFunctions *
createFunctions(
const QOpenGLVersionProfile &versionProfile)
53#if !QT_CONFIG(opengles2)
54 const int major = versionProfile.version().first;
55 const int minor = versionProfile.version().second;
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;
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;
97 case QSurfaceFormat::NoProfile:
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;
125 Q_UNUSED(versionProfile);
126 return new QOpenGLFunctions_ES2;
198QAbstractOpenGLFunctions *QOpenGLVersionFunctionsFactory::get(
const QOpenGLVersionProfile &versionProfile, QOpenGLContext *context)
201 context = QOpenGLContext::currentContext();
204 qWarning(
"versionFunctions: No OpenGL context");
208#if !QT_CONFIG(opengles2)
209 if (context->isOpenGLES()) {
210 qWarning(
"versionFunctions: Not supported on OpenGL ES");
215 const QSurfaceFormat f = context->format();
218 QOpenGLVersionProfile vp = versionProfile;
220 vp = QOpenGLVersionProfile(f);
223 const auto v = std::pair(f.majorVersion(), f.minorVersion());
224 if (v < vp.version())
229 if (((vp.hasProfiles() && vp.profile() != QSurfaceFormat::CoreProfile) || vp.isLegacyVersion())
230 && f.profile() == QSurfaceFormat::CoreProfile)
234 QAbstractOpenGLFunctions* funcs =
nullptr;
236 auto *data = QOpenGLContextVersionData::forContext(context);
237 auto it = data->functions.constFind(vp);
238 if (it == data->functions.constEnd()) {
239 funcs = createFunctions(vp);
241 funcs->setOwningContext(context);
242 data->functions.insert(vp, funcs);
248 if (funcs && QOpenGLContext::currentContext() == context)
249 funcs->initializeOpenGLFunctions();