Important: Please read the Qt Code of Conduct -

QGraphicsWebView in legacy GLUT application

  • I have a legacy application with a GLUT mainloop, where all rendering is done within a GLUT OpenGL context and no Qt whatsoever. I would now like to include a webpage in my application using QGraphicsWebView in order to enable WebGL drawings.

    I got this working by running the QApplication in a separate thread and rendering webkit to a QImage (as done in the samples) but the copy from gpu memory (the final wekit render layer) to cpu memory (QImage) to GL texture introduces too much latency. What I would like to do is render webkit into a texture (or fbo with an attached texture) and give this texture to my GLUT OpenGL context for rendering.

    The first thing I've got working (render webkit to gpu memory), but I am struggling with the second (texture sharing). It would be ideal to make QtWebkit use my GLUT context to render, but as far as I understood, the QtWebkit uses an OpenGL ES2.0 context while my GLUT context is a desktop OpenGL4.0x one. Using the Qt OpenGL context in the main application is not possible. So I would need to share gpu memory between these contexts, but how can I do this?

  • Found the solution to this. I did:

    • create QGLWidget (without forcing it to use a specific opengl version)
    • create QGraphicsWebView with this widget as viewport
    • qglwidget.makeCurrent()
    • wglShareLists(myGlutContext, wglGetCurrentContext())

    Using this I can now create textures in my GLUT context, render QGraphicsWebView in a (Qt)FBO with QPainter and then copy the contents of the FBO to my own texture. (Using the texture attached to the (Qt) FBO was problematic as repaints in the browser are still performed on this FBO)

    Performance is good, although it seems to be a bit slower than the sample browser.

Log in to reply