6std::string profileToString(QSurfaceFormat::OpenGLContextProfile _profile)
8 if(_profile == QSurfaceFormat::CompatibilityProfile)
9 return "CompatibilityProfile";
11 if(_profile == QSurfaceFormat::CoreProfile)
14 if(_profile == QSurfaceFormat::NoProfile)
22bool verifySpecificContextFormat(QSurfaceFormat format, QSurfaceFormat* resultingFormat =
nullptr)
25 QSurfaceFormat::setDefaultFormat(format);
29 QApplication tempApp(tempArgC,
nullptr);
30 QOffscreenSurface *surface =
new QOffscreenSurface();
33 auto shareContext = QOpenGLContext::globalShareContext();
36 std::cerr <<
"Error: Apparently no GL context was created!" << std::endl;
41 shareContext->makeCurrent(surface);
45 auto resultFormat = QOpenGLContext::globalShareContext()->format();
48 if(resultingFormat !=
nullptr)
49 *resultingFormat = resultFormat;
51 auto curVersion = resultFormat.version();
54 auto reqProfileString = profileToString(format.profile());
57 auto curProfileString = profileToString(resultFormat.profile());
61 auto reqVersionInt = format.version().first * 10 + format.version().second;
62 auto curVersionInt = curVersion.first * 10 + curVersion.second;
70 if(curVersionInt < 32 && resultFormat.profile() == QSurfaceFormat::CoreProfile)
72 std::cerr <<
"Warning: Got an OpenGL core context with OpengGL version < 3.2 (" << curVersion.first <<
"." << curVersion.second <<
")! This should not be possible." << std::endl;
78 if(curVersionInt < reqVersionInt ||
79 format.profile()!= resultFormat.profile() )
81 std::cout <<
"[OpenGL context] Requested: "
82 << format.version().first <<
"." << format.version().second <<
" (" << reqProfileString <<
")"
83 <<
", Actually created: "
84 << curVersion.first <<
"." << curVersion.second <<
" (" << curProfileString <<
")"
89 std::cout <<
"[OpenGL context] Successfully created OpenGL context with version " << curVersion.first <<
"."
90 << curVersion.second <<
" (" << curProfileString <<
")." << std::endl;
92 if ( format.testOption(QSurfaceFormat::DebugContext) )
93 std::cout <<
"[OpenGL context] Created Debug Context" << std::endl;
99QSurfaceFormat createFormat(QSurfaceFormat::OpenGLContextProfile _profile,
int _glMajor,
int _glMinor,
int _multisamplingSamples,
bool _stereo,
bool _debugContext)
101 QSurfaceFormat format;
102 format.setVersion(_glMajor, _glMinor);
103 format.setProfile(_profile);
104 format.setSamples(_multisamplingSamples);
105 format.setStereo(_stereo);
106 if(_profile != QSurfaceFormat::CoreProfile)
107 format.setOption(QSurfaceFormat::DeprecatedFunctions);
109 format.setOption(QSurfaceFormat::DebugContext);
119QSurfaceFormat getContextFormat()
121 auto reqProfile = OpenFlipper::Options::coreProfile() ? QSurfaceFormat::CoreProfile : QSurfaceFormat::CompatibilityProfile;
122 QPair<int,int> reqVersion = OpenFlipper::Options::glVersion();
123 auto reqSamples = OpenFlipper::Options::samples();
124 auto reqStereo = OpenFlipper::Options::glStereo();
125 bool debugContext = OpenFlipper::Options::debug();
146 QSurfaceFormat resultFormat;
149 std::cout <<
"[OpenGL context] Trying to create a " << reqVersion.first <<
"." << reqVersion.second <<
" " << profileToString(reqProfile) <<
" context (default from settings)..." << std::endl;
150 bool success = verifySpecificContextFormat(createFormat(reqProfile, reqVersion.first, reqVersion.second, reqSamples, reqStereo, debugContext), &resultFormat);
155 std::cout <<
"[OpenGL context] Trying to create a 4.4 compat context..." << std::endl;
156 success = verifySpecificContextFormat(createFormat(QSurfaceFormat::CompatibilityProfile, 4, 4, reqSamples, reqStereo, debugContext), &resultFormat);
160 std::cout <<
"[OpenGL context] Trying to create a 3.2 core context..." << std::endl;
161 success = verifySpecificContextFormat(createFormat(QSurfaceFormat::CoreProfile, 3, 2, reqSamples, reqStereo, debugContext), &resultFormat);
164 std::cerr <<
"[OpenGL context] Warning: Could not create any of the requested GL contexts." << std::endl;
165 std::cerr <<
"[OpenGL context] The following context (proposed by the graphics driver) will be created:" << std::endl;
166 std::cerr <<
"[OpenGL context] Profile: " << profileToString(resultFormat.profile()) <<
", Version: "
167 << resultFormat.version().first <<
"." << resultFormat.version().second << std::endl;
168 std::cerr <<
"[OpenGL context] Please consider setting a supported OpenGL version and profile in the Options dialog." << std::endl;