Qt-interest Archive, March 2007
multiple QGLWidgets
Pages: Prev | 1 | 2 | Next
Message 1 in thread
I am writing a program that has multiple QGLWidget's that display
different plots. Each QGLWidget contains an array of 256 display lists.
An interrupt occurs every 200ms that calls an addRow function for each
QGLWiget. Each plot adds a new row of data (display list), then redraws.
This sequence is run for each QGLWidget. My problem is that when I run
it, all of the displays show the same thing, a blend of all graphs. I
need them to display each plot separately. I know that I am getting the
correct data for each QGLWiget, so it must be some sort of opengl thing.
I have tried calling makeCurrent() and tried creating new contexts. I
also tried to directly draw the plots instead of using display lists.
Nothing seems to work. Any help would be greatly appreciated.
--
[ signature omitted ]
Message 2 in thread
El Jueves 15 Marzo 2007 09:57, Brett Behrens escribió:
> I am writing a program that has multiple QGLWidget's that display
> different plots. Each QGLWidget contains an array of 256 display lists.
> An interrupt occurs every 200ms that calls an addRow function for each
> QGLWiget. Each plot adds a new row of data (display list), then redraws.
> This sequence is run for each QGLWidget. My problem is that when I run
> it, all of the displays show the same thing, a blend of all graphs. I
> need them to display each plot separately. I know that I am getting the
> correct data for each QGLWiget, so it must be some sort of opengl thing.
> I have tried calling makeCurrent() and tried creating new contexts. I
> also tried to directly draw the plots instead of using display lists.
> Nothing seems to work. Any help would be greatly appreciated.
An idea: the displays lists IDs are being overwritten. Why? We could never
figure it out. All we could get was that the display lists IDs given by
glGenLists() were very often (but randomly) repited, and so the mess.
As I said, we could never find the problem, all we could guess was that it's a
Qt issue, as in a non-qt program with the same openGL code that would not
happen.
As "a solution", we changed everything to vertex arrays.
Regards, Lisandro.
--
[ signature omitted ]
Message 3 in thread
Lisandro Damián Nicanor Pérez Meyer wrote:
> El Jueves 15 Marzo 2007 09:57, Brett Behrens escribió:
>
>> ...
> As I said, we could never find the problem, all we could guess was that it's a
> Qt issue, as in a non-qt program with the same openGL code that would not
> happen.
Just a shot into the blue: Qt supports GL display lists sharing between
different GL contexts (QGLWidgets).
Maybe you could verify what QGLWidget::isSharing() returns? If it
returns true then the same display lists are used for some (or all) of
your widgets (which is not what you want).
To be honest I don't think this is the reason in your case, because
sharing has to be explicitly enabled, e.g. by passing a "shareWidget"
into the c'tor of QGLWidget, and you would have noticed this instantly...
Which Qt version are you using by the way? Qt 4.2.3?
Cheers, Oliver
--
[ signature omitted ]
Message 4 in thread
El Jueves 15 Marzo 2007 11:12, Till Oliver Knoll escribió:
> Lisandro Damián Nicanor Pérez Meyer wrote:
> > El Jueves 15 Marzo 2007 09:57, Brett Behrens escribió:
> >> ...
> >
> > As I said, we could never find the problem, all we could guess was that
> > it's a Qt issue, as in a non-qt program with the same openGL code that
> > would not happen.
>
> Just a shot into the blue: Qt supports GL display lists sharing between
> different GL contexts (QGLWidgets).
Well, that was not our problem, since we have just one context (indeed, all
what we have is a derivated clas of QGLWidget only used one time, we never
used contexts)
[snip]
> Which Qt version are you using by the way? Qt 4.2.3?
The problem, in my case, was from Qt 4.1.1 to 4.2.2
Brett: put a qDebug() after the call to glGenLists() and see if you have the
IDs reasignment problem. It will be helpfull to see if it's a Qt problem, at
least.
Regards, Lisandro.
--
[ signature omitted ]
Message 5 in thread
El Jueves 15 Marzo 2007 12:09, Lisandro Damián Nicanor Pérez Meyer escribió:
> El Jueves 15 Marzo 2007 11:12, Till Oliver Knoll escribió:
> > Lisandro Damián Nicanor Pérez Meyer wrote:
> > > El Jueves 15 Marzo 2007 09:57, Brett Behrens escribió:
> > >> ...
> > >
> > > As I said, we could never find the problem, all we could guess was that
> > > it's a Qt issue, as in a non-qt program with the same openGL code that
> > > would not happen.
> >
> > Just a shot into the blue: Qt supports GL display lists sharing between
> > different GL contexts (QGLWidgets).
>
> Well, that was not our problem, since we have just one context (indeed, all
> what we have is a derivated clas of QGLWidget only used one time, we never
> used contexts)
>
> [snip]
>
> > Which Qt version are you using by the way? Qt 4.2.3?
>
> The problem, in my case, was from Qt 4.1.1 to 4.2.2
Forgot to write: the same problem happens on Linux and on Windows.
Regards, Lisandro.
--
[ signature omitted ]
Message 6 in thread
On Mar 15, 2007, at 9:09 AM, Lisandro Damián Nicanor Pérez Meyer wrote:
> El Jueves 15 Marzo 2007 11:12, Till Oliver Knoll escribió:
>> Lisandro Damián Nicanor Pérez Meyer wrote:
>>> El Jueves 15 Marzo 2007 09:57, Brett Behrens escribió:
>>>> ...
>>>
>>> As I said, we could never find the problem, all we could guess
>>> was that
>>> it's a Qt issue, as in a non-qt program with the same openGL code
>>> that
>>> would not happen.
>>
>> Just a shot into the blue: Qt supports GL display lists sharing
>> between
>> different GL contexts (QGLWidgets).
>
> Well, that was not our problem, since we have just one context
> (indeed, all
> what we have is a derivated clas of QGLWidget only used one time,
> we never
> used contexts)
>
> [snip]
>
>> Which Qt version are you using by the way? Qt 4.2.3?
>
> The problem, in my case, was from Qt 4.1.1 to 4.2.2
>
> Brett: put a qDebug() after the call to glGenLists() and see if you
> have the
> IDs reasignment problem. It will be helpfull to see if it's a Qt
> problem, at
> least.
>
> Regards, Lisandro.
>
> --
Here is another shot in the dark. You must call QGLWidget::init()
prior to making _any_ OpenGL calls. If you try to create your
display lists before instantiating your the call list id that is
returned is undefined (I've seen both -1 and 0 for a 1 based list).
Typically, nothing gets drawn with this error.
Karl
--
[ signature omitted ]
Message 7 in thread
El Jueves 15 Marzo 2007 12:23, escribió:
> On Mar 15, 2007, at 9:09 AM, Lisandro Damián Nicanor Pérez Meyer wrote:
> > El Jueves 15 Marzo 2007 11:12, Till Oliver Knoll escribió:
> >> Lisandro Damián Nicanor Pérez Meyer wrote:
> >>> El Jueves 15 Marzo 2007 09:57, Brett Behrens escribió:
> >>>> ...
> >>>
> >>> As I said, we could never find the problem, all we could guess
> >>> was that
> >>> it's a Qt issue, as in a non-qt program with the same openGL code
> >>> that
> >>> would not happen.
> >>
> >> Just a shot into the blue: Qt supports GL display lists sharing
> >> between
> >> different GL contexts (QGLWidgets).
> >
> > Well, that was not our problem, since we have just one context
> > (indeed, all
> > what we have is a derivated clas of QGLWidget only used one time,
> > we never
> > used contexts)
> >
> > [snip]
> >
> >> Which Qt version are you using by the way? Qt 4.2.3?
> >
> > The problem, in my case, was from Qt 4.1.1 to 4.2.2
> >
> > Brett: put a qDebug() after the call to glGenLists() and see if you
> > have the
> > IDs reasignment problem. It will be helpfull to see if it's a Qt
> > problem, at
> > least.
> >
> > Regards, Lisandro.
> >
> > --
>
> Here is another shot in the dark. You must call QGLWidget::init()
> prior to making _any_ OpenGL calls. If you try to create your
> display lists before instantiating your the call list id that is
> returned is undefined (I've seen both -1 and 0 for a 1 based list).
> Typically, nothing gets drawn with this error.
Perhaps do you mean QGLWidget::initializeGL() ? If so, it is called. Else, I
could not find QGLWidget::init() in the doc.
Thanks for the shot! :-)
--
[ signature omitted ]
Message 8 in thread
El Jueves 15 Marzo 2007 12:36, escribió:
[snip]
> > Here is another shot in the dark.
[snip]
> Thanks for the shot! :-)
Funny enough, I'm hearing Skapara's version of "Shot in the dark" while
writing these mails :-)
--
[ signature omitted ]
Message 9 in thread
El Jueves 15 Marzo 2007 12:23, escribió:
> On Mar 15, 2007, at 9:09 AM, Lisandro Damián Nicanor Pérez Meyer wrote:
> > El Jueves 15 Marzo 2007 11:12, Till Oliver Knoll escribió:
> >> Lisandro Damián Nicanor Pérez Meyer wrote:
> >>> El Jueves 15 Marzo 2007 09:57, Brett Behrens escribió:
> >>>> ...
> >>>
> >>> As I said, we could never find the problem, all we could guess
> >>> was that
> >>> it's a Qt issue, as in a non-qt program with the same openGL code
> >>> that
> >>> would not happen.
> >>
> >> Just a shot into the blue: Qt supports GL display lists sharing
> >> between
> >> different GL contexts (QGLWidgets).
> >
> > Well, that was not our problem, since we have just one context
> > (indeed, all
> > what we have is a derivated clas of QGLWidget only used one time,
> > we never
> > used contexts)
> >
> > [snip]
> >
> >> Which Qt version are you using by the way? Qt 4.2.3?
> >
> > The problem, in my case, was from Qt 4.1.1 to 4.2.2
> >
> > Brett: put a qDebug() after the call to glGenLists() and see if you
> > have the
> > IDs reasignment problem. It will be helpfull to see if it's a Qt
> > problem, at
> > least.
More data: the display lists can not be created inside initializeGL() as the
doc says. So, we call QGLWidget::makeCurrent() before doing so. If, for some
reason, that's not enough, a method should be available to create lists
outside QGLWidget::makeCurrent().
Regards, Lisandro.
--
[ signature omitted ]
Message 10 in thread
El Jueves 15 Marzo 2007 13:01, escribió:
> I put the qDebug() after the genlist and for the first QGLWidget it makes
> the first list and assigns it ID = 1. Then the next QGLWidget goes
> through the same part and makes it's first list and it is also ID = 1. Is
> the display list numbering a local thing or if you call genLists from
> different classes, should there be no repeating numbers? Thanks.
There souldn't be repeated numbers.
Regards, Lisandro.
> > El Jueves 15 Marzo 2007 11:12, Till Oliver Knoll escribió:
> >> Lisandro Damián Nicanor Pérez Meyer wrote:
> >> > El Jueves 15 Marzo 2007 09:57, Brett Behrens escribió:
> >> >> ...
> >> >
> >> > As I said, we could never find the problem, all we could guess was
> >>
> >> that
> >>
> >> > it's a Qt issue, as in a non-qt program with the same openGL code that
> >> > would not happen.
> >>
> >> Just a shot into the blue: Qt supports GL display lists sharing between
> >> different GL contexts (QGLWidgets).
> >
> > Well, that was not our problem, since we have just one context (indeed,
> > all
> > what we have is a derivated clas of QGLWidget only used one time, we
> > never used contexts)
> >
> > [snip]
> >
> >> Which Qt version are you using by the way? Qt 4.2.3?
> >
> > The problem, in my case, was from Qt 4.1.1 to 4.2.2
> >
> > Brett: put a qDebug() after the call to glGenLists() and see if you have
> > the
> > IDs reasignment problem. It will be helpfull to see if it's a Qt problem,
> > at
> > least.
> >
> > Regards, Lisandro.
> >
> > --
> > Nearly all men can stand adversity, but if you want to test a man's
> > character, give him power.
> > Abraham Lincoln
> >
> > Lisandro Damián Nicanor Pérez Meyer
> > http://perezmeyer.com.ar/
> >
> > --
> > To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> > "unsubscribe" in the subject or the body.
> > List archive and information: http://lists.trolltech.com/qt-interest/
--
[ signature omitted ]
Message 11 in thread
Lisandro Damián Nicanor Pérez Meyer wrote:
> El Jueves 15 Marzo 2007 13:01, escribió:
>
>>I put the qDebug() after the genlist and for the first QGLWidget it makes
>>the first list and assigns it ID = 1. Then the next QGLWidget goes
>>through the same part and makes it's first list and it is also ID = 1. Is
>>the display list numbering a local thing or if you call genLists from
>>different classes, should there be no repeating numbers? Thanks.
>
>
> There souldn't be repeated numbers.
Well yes, there can be! Because each QGLWidget has by default its own
GLContext - the only requirement for GL display list IDs is that they be
unique *within their GL context*.
So if you call glGenLists(1) in different QGLWidgets (with no QGLContext
sharing and no display list sharing!) then you are very likely to obtain
the same ID.
Cheers, Oliver
--
[ signature omitted ]
Message 12 in thread
El Jueves 15 Marzo 2007 13:29, Till Oliver Knoll escribió:
> Lisandro Damián Nicanor Pérez Meyer wrote:
> > El Jueves 15 Marzo 2007 13:01, escribió:
> >>I put the qDebug() after the genlist and for the first QGLWidget it makes
> >>the first list and assigns it ID = 1. Then the next QGLWidget goes
> >>through the same part and makes it's first list and it is also ID = 1.
> >> Is the display list numbering a local thing or if you call genLists from
> >> different classes, should there be no repeating numbers? Thanks.
> >
> > There souldn't be repeated numbers.
>
> Well yes, there can be! Because each QGLWidget has by default its own
> GLContext - the only requirement for GL display list IDs is that they be
> unique *within their GL context*.
>
> So if you call glGenLists(1) in different QGLWidgets (with no QGLContext
> sharing and no display list sharing!) then you are very likely to obtain
> the same ID.
In this case, Brett ¿can you check that a display list that it is supposed to
be in, let's say, context 1, it's displayed in context 2? That, of course,
taking into account what Till has wrote.
More than that, if possible, check that the second list generated with a
repeated ID _but_ in a different context is only displayed in it's correct
context.
Regards, Lisandro.
--
[ signature omitted ]
Message 13 in thread
Just forwarding Brett's mail
El Jueves 15 Marzo 2007 14:06, escribió:
> Right now I have two QGLWidgets and they both have different contexts and
> different lists. The lists are created in their respective contexts and
> also called in the correct contexts. They do repeat numbers, but if they
> are in different contexts, I guess that doesn't matter. I am really at a
> loss. Thanks.
>
> Brett
>
> > El Jueves 15 Marzo 2007 13:29, Till Oliver Knoll escribió:
> >> Lisandro Damián Nicanor Pérez Meyer wrote:
> >> > El Jueves 15 Marzo 2007 13:01, escribió:
> >> >>I put the qDebug() after the genlist and for the first QGLWidget it
> >>
> >> makes
> >>
> >> >>the first list and assigns it ID = 1. Then the next QGLWidget goes
> >> >>through the same part and makes it's first list and it is also ID = 1.
> >> >> Is the display list numbering a local thing or if you call genLists
> >>
> >> from
> >>
> >> >> different classes, should there be no repeating numbers? Thanks.
> >> >
> >> > There souldn't be repeated numbers.
> >>
> >> Well yes, there can be! Because each QGLWidget has by default its own
> >> GLContext - the only requirement for GL display list IDs is that they be
> >> unique *within their GL context*.
> >>
> >> So if you call glGenLists(1) in different QGLWidgets (with no QGLContext
> >> sharing and no display list sharing!) then you are very likely to obtain
> >> the same ID.
> >
> > In this case, Brett ¿can you check that a display list that it is
> > supposed to
> > be in, let's say, context 1, it's displayed in context 2? That, of
> > course, taking into account what Till has wrote.
> >
> > More than that, if possible, check that the second list generated with a
> > repeated ID _but_ in a different context is only displayed in it's
> > correct context.
> >
> > Regards, Lisandro.
> >
> > --
> > Sobre Argentina: "sé que es uno de los países
> > mas hospitalarios del mundo"
> > Albert Einstein
> >
> > Lisandro Damián Nicanor Pérez Meyer
> > http://perezmeyer.com.ar/
> >
> > --
> > To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> > "unsubscribe" in the subject or the body.
> > List archive and information: http://lists.trolltech.com/qt-interest/
--
[ signature omitted ]
Message 14 in thread
Brett Behrens wrote:
> Oliver,
>
> So if I am getting the same numbers for the lists, then I guess I do have
> different contexts for each QGLWidget. Then why would they all display
> the same blended thing? Is there something else I need to be doing?
> Thanks.
As long as you create your QGLWidget based widgets w1, w2 like this:
// this: some parent widget
MyQGLWidget *w1 = new MyQGLWidget(this);
MyQGLWidget *w2 = new MyQGLWidget(this);
that is with no display list sharing and no QGLContext sharing, and you
have:
MyQGLWidget::MyQGLWidget()
{
m_listId = GL_INVALID_VALUE;
...
}
// public
void MyQGLWidget::setData (Array of points)
{
// copy the data points (or whatever is the most performant here)
m_pointArray = array of points;
// create the display list for this QGLWidget
this->createObject();
...
}
void MyQGLWidget::initializeGL()
{
m_pointArray = some default data to draw;
this->createObject();
// setup camera position, clear colour, ...
...
}
void MyQGLWidget::paintGL()
{
// should also work with GL_INVALID_DATA, but maybe an explicit
// if (...) would be better here (and better programming practice ;)
glCallList(m_listId);
...
}
void MyQGLWidget::createObject()
{
// we NEED to call makeCurrent() here, because this method can be
// called from the "outside API", too (via setData())!
this->makeCurrent();
// delete the previous display list (if any)
if (m_listId != GL_INVALID_VALUE)
{
glDeleteLists(m_listId, 1);
}
// re-create the display list
m_listId = glGenLists(1);
glNewList (m_listId, GL_COMPILE);
{
glBegin();
{
// create your object with the 'm_pointArray' (glVertex etc.)
...
}
glEnd();
}
glEndList();
}
Now if you have:
w1->setData (dataSet1);
w1->update();
w2->setData (dataSet2); // different that dataSet1
w2->update();
If my pseudo-code above is correct then IMHO w1 should now display only
the 'dataSet1' and w2 should only display 'dataSet2'. In both cases I
would expect that m_listId is the *same* value, but since it is unique
in its respective GL context (the one of w1 and w2) and no display list
sharing is enabled this should be fine when calling it with glCallList!
Also note that you don't need to call makeCurrent() in any *GL method
(or in any other private method which is (exclusively!) called from
there), because Qt does this already for you.
BUT (and this is a typical mistake I have also done some times) in any
other method which is (indirectly) accessible via the "public API" of
your QGLWidget you *have* to call makeCurrent(), so the display lists,
textures etc. are updated in the correct GL context!
So if all the above is clear to you and you have more or less the same
code logic and you still see a "merged display lists" image in every of
your QGLWidgets, then it might indeed be a bug in Qt 4.2.x. Or we are
both missing the very obvious ;)
Cheers, Oliver
p.s. Please write to the list instead
--
[ signature omitted ]
Message 15 in thread
Oliver,
Your code looks almost exactly like mine. I create the two QGLWidgets,
and then call a function on the first one, which calls makeCurrent(),
creates the new list, then calls update. Then do the same for the next
one. Still shows a blended scene on both widgets. Thanks.
Brett
> Brett Behrens wrote:
>> Oliver,
>>
>> So if I am getting the same numbers for the lists, then I guess I do
>> have
>> different contexts for each QGLWidget. Then why would they all display
>> the same blended thing? Is there something else I need to be doing?
>> Thanks.
>
> As long as you create your QGLWidget based widgets w1, w2 like this:
>
> // this: some parent widget
> MyQGLWidget *w1 = new MyQGLWidget(this);
> MyQGLWidget *w2 = new MyQGLWidget(this);
>
>
> that is with no display list sharing and no QGLContext sharing, and you
> have:
>
> MyQGLWidget::MyQGLWidget()
> {
> m_listId = GL_INVALID_VALUE;
> ...
> }
>
> // public
> void MyQGLWidget::setData (Array of points)
> {
> // copy the data points (or whatever is the most performant here)
> m_pointArray = array of points;
>
> // create the display list for this QGLWidget
> this->createObject();
> ...
> }
>
> void MyQGLWidget::initializeGL()
> {
> m_pointArray = some default data to draw;
> this->createObject();
>
> // setup camera position, clear colour, ...
> ...
> }
>
> void MyQGLWidget::paintGL()
> {
> // should also work with GL_INVALID_DATA, but maybe an explicit
> // if (...) would be better here (and better programming practice ;)
> glCallList(m_listId);
> ...
> }
>
> void MyQGLWidget::createObject()
> {
>
> // we NEED to call makeCurrent() here, because this method can be
> // called from the "outside API", too (via setData())!
> this->makeCurrent();
>
> // delete the previous display list (if any)
> if (m_listId != GL_INVALID_VALUE)
> {
> glDeleteLists(m_listId, 1);
> }
>
> // re-create the display list
> m_listId = glGenLists(1);
>
> glNewList (m_listId, GL_COMPILE);
> {
> glBegin();
> {
> // create your object with the 'm_pointArray' (glVertex etc.)
> ...
> }
> glEnd();
> }
> glEndList();
> }
>
>
> Now if you have:
>
> w1->setData (dataSet1);
> w1->update();
> w2->setData (dataSet2); // different that dataSet1
> w2->update();
>
> If my pseudo-code above is correct then IMHO w1 should now display only
> the 'dataSet1' and w2 should only display 'dataSet2'. In both cases I
> would expect that m_listId is the *same* value, but since it is unique
> in its respective GL context (the one of w1 and w2) and no display list
> sharing is enabled this should be fine when calling it with glCallList!
>
> Also note that you don't need to call makeCurrent() in any *GL method
> (or in any other private method which is (exclusively!) called from
> there), because Qt does this already for you.
>
> BUT (and this is a typical mistake I have also done some times) in any
> other method which is (indirectly) accessible via the "public API" of
> your QGLWidget you *have* to call makeCurrent(), so the display lists,
> textures etc. are updated in the correct GL context!
>
>
> So if all the above is clear to you and you have more or less the same
> code logic and you still see a "merged display lists" image in every of
> your QGLWidgets, then it might indeed be a bug in Qt 4.2.x. Or we are
> both missing the very obvious ;)
>
> Cheers, Oliver
>
> p.s. Please write to the list instead
>
>
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
--
[ signature omitted ]
Pages: Prev | 1 | 2 | Next