[Qt-interest] Loading OpenGL Textures In A Separate Thread

Karol Krizka kkrizka at gmail.com
Wed Apr 22 22:18:42 CEST 2009


Hi all,

I'm writing an Qt/OpenGL application that loads a lot of textures, which takes 
some time. So I would like to display some kind of an animation while the 
textures are loading in the background in a separate thread. 

After reading several articles, I learned that the best way to accomplish this 
is to create a new OpenGL context in the loader thread and have it share it's 
lists with the original OpenGL context. Now my question is, how can this be 
accomplished using QGLWidget and QGLContext? I tried the following code, in 
my loader thread:

  const QGLContext *original=glWIdget->context();
  QGLContext *myContext=new 
QGLContext(QGLFormat(QGL::SampleBuffers));
  qDebug() << myContext->create(original);
  myContext->makeCurrent();

Where glWidget is the QGLWidget being displayed. It was created using the 
same QGLFormat.

However the code outputs the following:
false
QGLContext::makeCurrent(): Cannot make invalid context current.

--
Cheers,
Karol Krizka
http://www.krizka.net




More information about the Qt-interest-old mailing list