QOpenGLContext from GLFW Context

1.1k views Asked by At

We have a 3D rendering window created using GLFW and we want to use QWebkit for displaying a QWebPage inside the rendering (aka render the QWebPage to an OpenGL texture). Using only the CPU version is too slow and Qt supports rendering QWebkit into QOpenGLFramebufferObjects (using QOpenGLPaintDevice).

However, doing so requires the creation of a QOpenGLContext (which requires its own window and so on), eventually interfering with our whole application. (Switching between GLFW and Qt Context also causes an infinite amount of GL_INVALID_OPERATIONs)

Best case solution: we get Qt to use the GLFW Context.

Code example:

QOpenGLFramebufferObject qfbo(mWidth, mHeight); //< this crashes because he will implicitly try to get QOpenGLFunctions which gets the default context which is null
qfbo.bind();
QOpenGLPaintDevice paintdev(mWidth, mHeight);

QPainter painter(&paintdev);
painter.beginNativePainting();
mPage->mainFrame()->render( &painter );
painter.endNativePainting();

So here are some questions:

  • is it possible to get Qt to use the GLFW OpenGL context?
  • if not, how can we switch between GLFW context and Qt context? (using texture sharing for transferring the rendered QWebPage)
  • if all of this is impossible, is there a free Webkit project with 64bit, Windows/Linux/Mac support that can render using OpenGL?
1

There are 1 answers

1
Brian Tompsett - 汤莱恩 On

@Sebastian Cabot wrote:

You can't directly mix the two context objects using QT. QT is great but in order to keep itself portable it also has some limitations - mainly accessing the low level handles of the objects and manipulating them directly. So Even trying to use a QOpenGLContext from a different thread then the one it was created in will fail. And in order to use any of the QT OpenGL wrappers you will need a valid QOpenGLContext current. So what you want is not possible without hacking into the QT implementation.