我们有一个使用 GLFW 创建的 3D 渲染窗口,我们希望使用 QWebkit 在渲染中显示 QWebPage(也称为将 QWebPage 渲染为 OpenGL 纹理)。只使用CPU版本太慢,Qt支持将QWebkit渲染成QOpenGLFramebufferObjects(使用QOpenGLPaintDevice)。
但是,这样做需要创建一个 QOpenGLContext(需要它自己的窗口等),最终会干扰我们的整个应用程序。 (GLFW和Qt Context之间切换也会导致无限量的GL_INVALID_OPERATION)
最佳案例解决方案:我们让 Qt 使用 GLFW 上下文。
代码示例:
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();
这里有一些问题:
- 是否可以让 Qt 使用 GLFW OpenGL 上下文?
- 如果没有,我们如何在 GLFW 上下文和 Qt 上下文之间切换? (使用纹理共享来传输渲染的QWebPage)
- 如果这一切都不可能,是否有一个免费的 Webkit 项目,支持 64 位、Windows/Linux/Mac,并且可以使用 OpenGL 进行渲染?
最佳答案
@Sebastian Cabot 写道:
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 validQOpenGLContext
current. So what you want is not possible without hacking into the QT implementation.
关于c++ - 来自 GLFW 上下文的 QOpenGLContext,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20570680/