Unsolved Using two QOpenGLWidgets with different formats inside one window
-
Right now i am working on the desktop application that will use my own 3D engine (simple openGL) and QMapboxGL vector maps. I have two widgets that extends QOpenGLWidget, MyEngine and QMapboxGL.
My gues on the problem is that QMapboxGL has its shaders written in older version of GLSL and my is written for OpenGL 3.3+. Becouse there is shared context inside one window for both widgets its is not working properly when i put the together(for example QStackedWidget, and try to switch between them).Is there any solution to this besides having to reload whole window with only one widget active and switching between them?
QMapboxGLSettings settings; settings.setContextMode(QMapboxGLSettings::GLContextMode::UniqueGLContext); settings.setCacheDatabasePath("/tmp/mbgl-cache.db"); settings.setCacheDatabaseMaximumSize(20 * 1024 * 1024); settings.setAccessToken(); MapWindow *mapboxWindow = new MapWindow(settings); mapboxWindow->show(); <----this work QSurfaceFormat format = QSurfaceFormat::defaultFormat(); format.setDepthBufferSize(32); format.setProfile(QSurfaceFormat::CoreProfile); format.setVersion(4,1); QSurfaceFormat::setDefaultFormat(format); OGLWidget *openGlMap = new OGLWidget(); openGlMap->show(); <----this work
if i arrange it so mapbox will initialize after my
QSurfaceFormat format = QSurfaceFormat::defaultFormat(); format.setDepthBufferSize(32); format.setProfile(QSurfaceFormat::CoreProfile); format.setVersion(4,1); QSurfaceFormat::setDefaultFormat(format); OGLWidget *openGlMap = new OGLWidget(); openGlMap->show(); <----this work QMapboxGLSettings settings; settings.setCacheDatabasePath("/tmp/mbgl-cache.db"); settings.setCacheDatabaseMaximumSize(20 * 1024 * 1024); settings.setAccessToken(); MapWindow *mapboxWindow = new MapWindow(settings); mapboxWindow->show(); <----this will show black screen, also if i switch the order, black screen will be on the second one.
I am also getting error
QCocoaGLContext: Falling back to unshared context.
Strangly even with black screen rendering is working but not showing anything to the screen. If i render to the frame buffer and save the image everything is fine.
Main problem is with QSurfaceFormat,. if i dont set it, it will downgrade version of GLSL to 0x31 and then i cant use my shaders(#version 150, i would have to rewrite them into older version and rewrite all core code inside engine for it)
I think about having windows somehow hidden but working on the background, passing all the events from one window and then rendering Frame buffers from both to it, but this looks like ugly hack to me.My questing is if there is a way to run both widget inside one window without any problem and both of them beeing rendering correctly. Thanks for any suggestions.
EDIT:: this is how it looks for a rist example
secod:
I am using Qt 5.9.1 and right now developing on macOS 10.12.6.
EDIT:
Ok i tried to put them inside QHBoxLayout to see what happends and weird bug show up. If i set formats separatly and not global, then only mapbox is working, my is showing black window. But after few second it show weird text like something overflown to that buffer.QMapboxGLSettings settings; settings.setContextMode(QMapboxGLSettings::GLContextMode::UniqueGLContext); settings.setCacheDatabasePath("/tmp/mbgl-cache.db"); settings.setCacheDatabaseMaximumSize(20 * 1024 * 1024); settings.setAccessToken(; MapWindow *mapboxWindow = new MapWindow(settings); mapboxWindow->setFormat(QSurfaceFormat::defaultFormat()); QSurfaceFormat format = QSurfaceFormat::defaultFormat(); format.setDepthBufferSize(32); format.setProfile(QSurfaceFormat::CoreProfile); format.setVersion(3,3); OGLWidget *openGlMap = new OGLWidget(); openGlMap->setFormat(format); MainWindow w; w.addOGLWidget(openGlMap); w.addOGLWidget(mapboxWindow); w.show();