On Saturday 19 May 2007 01:11:07 Donald Ephraim Curtis wrote:
In working with the Painter class i found a few different things.
Benoit had suggested that it’s pretty memory intensive to cache all the
display lists for objects. However, it has come to my attention that
DisplayLists live in different GLContext’s. So, what i did was that
each view that gets created shares it’s context with all the other
GLWidgets in the same window.
I think that’s a good idea (use a single context shared across all GLWidgets)
and that’s also what Trolltech recommends to do when using QPainters on
QGLWidgets. So we’re not alone doing things this way
AFAICS, There’s no reason why the sharing should be limited to all GLWidgets
in the same window. I think we can share the context across all
Just FYI, it is in theory possible to let display lists be shared across
contexts, as explained in this page:
However it’s not clear to me if this can be done in a portable way. QtOpenGL
doesn’t seem to support that. But since we share a single context across all
GLWidgets, we don’t need that.
This way we can share the Painter
instances between all GLWidgets and thus the Display Lists. However, it
kinda seems like Painter should check to make sure the context’s are the
I don’t think that can be done easily; I’d rather suggest that libavogadro
itself makes sure that the context is shared. I.e. the GLWidget constructors
should make sure the same context is shared. This way, the rest of
libavogadro could safely assume that there’s only one context.
Also, there is some good information on OpenGL and threading:
Interesting. But there’s something I don’t understand. Looking at
GLThread::run(), this function does nothing to ensure it’s not interrupted by
another thread’s run() function. In their example, this is statistically
almost impossible because of the msleep(40) that thy put at the end. 40
milliseconds is much longer than the execution time of the rest of
GLThread::run(), so GLThread::run() spends most of its time sleeping after it
has completed rendering, and it doesn’t care if it’s interrupted then. As an
experiment, try putting the msleep call near the beginning run() (for
example, right after the makeCurrent() call) instead of at the end of it. I
suspect that rendering will be broken (when there are more than one thread).
And of course, in avogadro we don’t want our threads to sleep at all.
As I said on IRC, GL functions return almost immediately and leave OpenGL
actually execute them in the background (in a separate process). So there’s
not much to gain in threading GL calls. It’s more interesting to thread the
tasks that are computationally intensive for our process.