I ran into a problem that I'm afraid will be very difficult to solve, at least as the Google search showed me.
I have an Editor utility using Qt that creates several OpenGL contexts for different tools in the editor, their "World" editor, which hosts the QGLWidget of my game scene, and the material editor, which has a "preview" QGLWidget, which displays the current material .
I managed to work properly with contextual exchange, I use gDEBugger to view OpenGL contexts, and they use Textures, VBO, shaders, etc. But one condition: I wonder how this will work, you cannot share vertex feature objects between contexts. As I understand it, Vertex Array objects are now standard, and we really should use them, and not use VBO without VAO.
I thought of two ways around this, but I don't think they are perfect.
- Create a VAO before each render, but that seems to exceed the goal
- use std :: map to map the GL context to the VAO if the current context does not have this VAO, then generate one for the specified context, this seems bad and may not even work.
What other solutions do I see? I also looked at everything in one context and used separate viewports for each opengl widget I hoped would be possible, but I had no luck deciding to use Qt and QGLWidget.
Edit
Ok, so I tried to get this to work, but it gives me a lot of grief, I tried two different ways, and they both cause me errors.
1) I create a QGLContext and then pass it to my QGLWidgets when they are created.
QGLFormat fmt = QGLFormat(); QGLContext* pContext = new QGLContext(fmt); QGLWidget* pWidget1 = new QGLWidget(pContext); someLayout->addWidget(pWidget1); QGLWidget* pWidget2 = new QGLWidget(pContext); anotherLayout->addWidget(pWidget2);
The error here is that as soon as I add the widget to the layout or set it as the central widget for the main window, it will delete the context, really strange. If I then try to transfer in context from the first widget to the second
QGLFormat fmt = QGLFormat(); QGLContext* pContext = new QGLContext(fmt); QGLWidget* pWidget1 = new QGLWidget(pContext); someLayout->addWidget(pWidget1); pContext = (QGLContext*)pWidget1->context(); QGLWidget* pWidget2 = new QGLWidget(pContext); anotherLayout->addWidget(pWidget2);
I get a Qt error talking about QGLWidget :: setContext: The context should reference this widget
2) I create my first widget and use it for everyone else
QGLWidget* pWidget1 = new QGLWidget(); QGLContext* pContext = (QGLContext*)pWidget->context(); QGLWidget* pWidget2 = new QGLWidget(pContext);
This gives me the same error I got from the end of my first method, this says QGLWidget :: setContext: The context should reference this widget.
Something is wrong here, and I feel that something is missing.