diff --git a/OpenFlipper.cc b/OpenFlipper.cc index 8173659010871c391e51d7c812b52b1b085092be..19254deace9965253c86d05398f2df88d2cf9550 100644 --- a/OpenFlipper.cc +++ b/OpenFlipper.cc @@ -516,12 +516,33 @@ bool verifySpecificContextFormat(QSurfaceFormat format, QSurfaceFormat* resultin // Human-readable name of current profile auto curProfileString = profileToString(resultFormat.profile()); - // Check whether the actually applied OpenGL context profile matches the requested one - // and the current GL version is at least the requested one (but may be higher) + + // Example: OpenGL Version 4.6 -> 46 + auto reqVersionInt = format.version().first * 10 + format.version().second; + auto curVersionInt = curVersion.first * 10 + curVersion.second; + + + // Qt Docs say: Whenever "NoProfile" is returned, either the GL version is < 3.2 or (GL >= 3.2) it is actually a core profile + // Thus we set the following guidelines: + // 1. Whenever the actually received GL version is < than the requested one, the context is not the one requested + // 2. If the requested version is >= 3.2 and Compat, only Compat is allowed (as NoProfile is considered core) + // 3. If the requested version is >= 3.2 and Core or NoProfile is requested, Compat is not allowed + + + // For >= 3.2, treat Core and NoProfile equally + bool reqCoreOrNoProfile = format.profile() == QSurfaceFormat::NoProfile || format.profile() == QSurfaceFormat::CoreProfile; + bool curCoreOrNoProfile = resultFormat.profile() == QSurfaceFormat::NoProfile || resultFormat.profile() == QSurfaceFormat::CoreProfile; + + if(curVersionInt < 32 && resultFormat.profile() == QSurfaceFormat::CoreProfile) + { + std::cerr << "Warning: Got an OpenGL core context with OpengGL version < 3.2 (" << curVersion.first << "." << curVersion.second << ")! This should not be possible." << std::endl; + return false; + } + + // Check whether the conditions above are met. // If not, print some error to the console - if(curVersion.first < format.version().first || - ((curVersion.first == format.version().first) && (curVersion.second < format.version().second)) || - format.profile() != resultFormat.profile()) + if(curVersionInt < reqVersionInt || + (reqVersionInt >= 32 && reqCoreOrNoProfile != curCoreOrNoProfile)) { std::cout << "[OpenGL context] Requested: " << format.version().first << "." << format.version().second << " (" << reqProfileString << ")" @@ -533,6 +554,10 @@ bool verifySpecificContextFormat(QSurfaceFormat format, QSurfaceFormat* resultin std::cout << "[OpenGL context] Successfully created OpenGL context with version " << curVersion.first << "." << curVersion.second << " (" << curProfileString << ")." << std::endl; + if(resultFormat.profile() == QSurfaceFormat::NoProfile || curVersionInt < 32) + { + std::cout << "[OpenGL context] Note that 'NoProfile' is fine for OpenGL version < 3.2 as core profile was introduced in 3.2" << std::endl; + } return true; } @@ -596,6 +621,7 @@ QSurfaceFormat getContextFormat() { std::cout << "[OpenGL context] Trying to create a 4.4 compat context..." << std::endl; success = verifySpecificContextFormat(createFormat(QSurfaceFormat::CompatibilityProfile, 4, 4, reqSamples, reqStereo, debugContext), &resultFormat); + if(!success) { std::cout << "[OpenGL context] Trying to create a 3.2 core context..." << std::endl;