开发者

OpenGL Threaded Tile Texture Loading with Qt 4.5 / 4.6

I am trying to develop am map application for scientific purposes at my university. Therefor I got access to a lot of tiles (256x256). I can access them and save them to an QImage in a seperate QThread. My Problem is, how can I actually manage to load the QImage into a texture within the seperate QThread (not the GUI main thread)? Or even better give me a Tipp how to approach this problem.

I though about multithreaded OpenGL but I also require OpenGL picking and I did not fall over anything usefull for that.#

Point me to any usefully example code if you feel like, I am thankfull for everything that compiles on Linux :)

Note1: I am using event based rendering, so开发者_Python百科 only if the scene changes it gets redrawn. Note2: OSG is NOT an option, it's far to heavy for that purpose, a leightweight approach is needed. Note3: The Application is entirely written in C++

Thanks for any reply. P.S. be patient, I am not that adavanced as this Topic may (or may not) suggest.


OpenGL is not thread-safe. You can only use one GL context in one thread at a time. Depending on OS you also have to explicitely give up on the context handle in one thread to use it in another.

You cannot speed up the texture loading by threading given that the bottleneck here is the bandwidth to the graphics card.

Let your delivery thread(s) that load the tiles fill up a ring buffer. The GL thread feeds from the ring buffer. With two mutexes it is easy to control the ring buffer to make this thread-safe operation.

That would be my suggestion.


Two tricks I use to speed things up:

  • pixel buffer objects: map GPU memory so the loading thread can write directly to gpu;
  • sync objects: with a sync object I know when the texture is really ready to be used (glTexImage2D with PBO is async so there is no guarantee the texture is ready to be binded, ie, when binding a texture, it blocks if DMA didn't finish updating texture data)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜