Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Retrive QML's QOpenGL context

Retrive QML's QOpenGL context

Scheduled Pinned Locked Moved Solved QML and Qt Quick
openglcontext-sharing
2 Posts 2 Posters 1.3k 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.
  • E Offline
    E Offline
    ebatsin
    wrote on last edited by
    #1

    Hi,

    I want to create a secondary OpenGL context shared with QML's QOpenGLContext to do background texture/mesh loading then rendering these assets in a QQuickFramebufferObject with QML's OpenGL context.

    Problem is I can't find a "clean" way to retrieve QML's OpenGL context.

    The only way I found right now is to have a BackgroundLoader class inherinting from QQuickPaintedItem, use it somewhere in QML, then wait for a paint call to retrieve the bound context using QOpenGLContext::currentContext(). After retrieving it, I can then create my secondary context. This feels like a hack and not the correct way to handle this (it does not work if my item is not rendered (size of 0)).

    Is there a way to retrieve QML's OpenGL context from C++ easily ? (I have access to the QQmlEngine and to a QQuickItem that I use to manage my 3D views). I don't need it to be bound. Just get a pointer to it to share it with my secondary context.

    Thanks

    GrecKoG 1 Reply Last reply
    0
    • E ebatsin

      Hi,

      I want to create a secondary OpenGL context shared with QML's QOpenGLContext to do background texture/mesh loading then rendering these assets in a QQuickFramebufferObject with QML's OpenGL context.

      Problem is I can't find a "clean" way to retrieve QML's OpenGL context.

      The only way I found right now is to have a BackgroundLoader class inherinting from QQuickPaintedItem, use it somewhere in QML, then wait for a paint call to retrieve the bound context using QOpenGLContext::currentContext(). After retrieving it, I can then create my secondary context. This feels like a hack and not the correct way to handle this (it does not work if my item is not rendered (size of 0)).

      Is there a way to retrieve QML's OpenGL context from C++ easily ? (I have access to the QQmlEngine and to a QQuickItem that I use to manage my 3D views). I don't need it to be bound. Just get a pointer to it to share it with my secondary context.

      Thanks

      GrecKoG Offline
      GrecKoG Offline
      GrecKo
      Qt Champions 2018
      wrote on last edited by
      #2

      @ebatsin is your QQuickItem in a QQuickWindow? I guess it is the case if you are not using a QQuickWidget.

      Calling QQuickWindow::openglContext() on your item's window should give you what you need.

      1 Reply Last reply
      2

      • Login

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