I need to shared data (textures, vertex-buffers,... ) across all OpenGL widgets in a application.
The following code isn't working:
I've found some solutions that have one main QGLWidget
and other are constructed using this main widget. Unfortunately, I can't use this approach, because all my QGLWidgets are equal and almost certainly the first(main) created QGLWidget will be destroyed before others are.
Possible approach:
- single shared OpenGL context between all QGLWidgets
- not working: just one QGLWidget gets rendered correctly, others behave as they weren't rendered, corrupted/random data
error for each
QGLWidget
construction except first one:QGLWidget::setContext: Context must refer to this widget
Another approach:
- main OpenGL context and create sub-context for each QGLWidget
- not working:
context->isSharing()
returnsfalse
code that I use for context creation,
context1
andcontext2
are later passed to constructors of QGLWidgets:QGLContext *mainContext = new QGLContext(format), *context1, *context2; mainContext->create(); context1 = new QGLContext(format); context1->create(mainContext); context2 = new QGLContext(format); context2->create(mainContext); cout << mainContext->isSharing() << " " << context1->isSharing() << endl;
glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT )
wasn't performed – kravemirmakeCurrent
method that should address this issue. – Andon M. Coleman