Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
5.15, 6.x
-
None
Description
Hello,
I need to set the highest available GL version that I can detect on my users's computers (as they may submit their own shaders directly - which potentially use more recent features that I can expect, especially on app startup).
So, to detect what I can use, I would like to run more-or-less the following upon app startup, to try and make a context with the highest available version in descending order and stopping when I have something that works:
std::vector<std::pair<int, int>> versions_to_test = { { 4, 7 }, { 4, 6 }, { 4, 5 }, { 4, 4 }, { 4, 3 }, { 4, 2 }, { 4, 1 }, { 4, 0 }, { 3, 3 }, { 3, 2 }, { 3, 1 }, { 3, 0 }, { 2, 1 }, { 2, 0 } }; QOffscreenSurface surf; surf.create(); QSurfaceFormat fmt = QSurfaceFormat::defaultFormat(); for(auto [maj, min] : versions_to_test) { fmt.setMajorVersion(maj); fmt.setMinorVersion(min); QOpenGLContext ctx; ctx.setFormat(fmt); if(ctx.create()) { if(ctx.makeCurrent(&surf)) { break; } } } fmt.setDefaultFormat(fmt);
The problem that I encounter is:
- If I run this code before QApplication instantiation, then I get a crash because it's likely too early to create QOffscreenSurface.. makes sense.
- If I run this code after QApplication instantiation, with AA_ShareOpenGLContexts, then the shared context has already been created during QApp construction, thus it's too late.
In that case, what can I do (except resorting to platform-specific code...) ?