PDA

View Full Version : Qt5 texture upload in separate thread



tseval
17th March 2013, 19:03
Hi,

I'm trying to implement async loading of textures by using a shared GL context in a separate thread and uploading textures into it. In Qt4 this could be done by using a hidden QGLWidget. As described in the QGLWidget documentation:


Doing texture uploads in a thread may be very useful for applications handling large amounts of images that needs to be displayed, like for instance a photo gallery application. This is supported in Qt through the existing bindTexture() API. A simple way of doing this is to create two sharing QGLWidgets. One is made current in the main GUI thread, while the other is made current in the texture upload thread. The widget in the uploading thread is never shown, it is only used for sharing textures with the main thread. For each texture that is bound via bindTexture(), notify the main thread so that it can start using the texture.

Now, I'm trying to do this in Qt5 with QOpenGLContext and QSurface/QWindow, but I'm not quite sure how. According to the documentation I can't start rendering into a QWindow until it has been exposed.

Any ideas on how to do this?

wysota
17th March 2013, 19:08
According to the documentation I can't start rendering into a QWindow until it has been exposed.
What do you want to render there?

tseval
17th March 2013, 19:38
I don't want to render anything, I just need a shared context to upload my textures into :)

But, assuming that your answer was a rhetorical question it means that I can simply do something like this and it would work?



tex_upload_ctx_ = new QOpenGLContext();

QSurfaceFormat fmt;
tex_upload_ctx_->setFormat(fmt);
tex_upload_ctx_->setShareContext(main_ctx);
tex_upload_ctx_->create();

tex_upload_win_ = new QWindow();
tex_upload_ctx_->makeCurrent(tex_upload_win_);

wysota
17th March 2013, 20:47
Yes, I think you can do exactly that. It's the shared context you want/need, not another window.