Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Using two QOpenGLWidgets with different formats inside one window
Forum Updated to NodeBB v4.3 + New Features

Using two QOpenGLWidgets with different formats inside one window

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 450 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    michalks
    wrote on last edited by michalks
    #1

    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
    1_1503740553624_map2.png
    secod:
    0_1503740553623_map1.png

    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();
    

    0_1503748011212_Screenshot 2017-08-26 13.40.22.png

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved