[Interest] Sharing an OGL context with multiple QGLWidget using designer (or anything else)
Paulo Silva
paulo.jnkml at gmail.com
Tue Jun 19 19:50:32 CEST 2012
Just an add-on, I also tried to use the constructor
QGLWidget::QGLWidget ( QWidget * parent = 0, const QGLWidget *
shareWidget = 0, Qt::WindowFlags f = 0 )
and although I pass the first QGLWidget created to the preceding
widgets, the effect seems to be the same as passing "shareWidget = 0".
http://doc.qt.nokia.com/4.7-snapshot/qglwidget.html#QGLWidget
recommends looking at
http://doc.qt.nokia.com/4.7-snapshot/opengl-textures.html
But that is not very helpful since the glwidgets are created with
"shareWidget = 0" here:
http://doc.qt.nokia.com/4.7-snapshot/opengl-textures-window-cpp.html
glWidgets[i][j] = new GLWidget(0, 0);
and for each context we have the code:
void GLWidget::initializeGL()
{
makeObject();
(...)
}
which just loads every texture again for each widget:
void GLWidget::makeObject()
{
(...)
for (int j=0; j < 6; ++j) {
textures[j] = bindTexture
(QPixmap(QString(":/images/side%1.png").arg(j + 1)),
GL_TEXTURE_2D);
}
(...)
}
Please correct me if I'm wrong.
Thanks,
Paulo
On Tue, Jun 19, 2012 at 10:48 PM, Paulo Silva <paulo.jnkml at gmail.com> wrote:
> Hi everyone,
>
> can I share an OGL context between two or more QGLWidgets, when the
> interface is made using designer?.
> Since I'm not creating the widgets myself, how can I take the context
> of one of the widgets and share it with the other widgets?
>
> I tried to use static class members like:
>
> QGLContext* const MyClass::_shared_context(new QGLContext(QGLFormat()));
> QGLWidget* MyClass::_shared_widget(0); // initialized to the first
> widget created
>
> and tried to pass it to the constructor,
>
> MyClass(QWidget *parent):
> QGLWidget(_shared_context, parent, _shared_widget),
> {
> static bool once(false);
> if(not once) {
> once = true;
> _shared_widget = this;
> } else {
> assert(_shared_context == context());
> // assert(isSharing()); this always fails
> }
> }
>
> But it does not seem to work as isSharing() returns false for all widgets.
> Appart from that updateGL fails for all widgets but the first. The
> others are just painted with the background color.
> However they do share the same context, as the first assert holds.
>
> Is there a correct way of doing this? Any designer functionality?
>
> Thanks
> Paulo
More information about the Interest
mailing list