views:

419

answers:

1

Hi, 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 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.

+1  A: 

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.

ypnos
thank you for your suggestion, I will think about that and if it's possible to change my current implementation without major redesign of the whole application
penguinpower
is context change very slow? or has it any other major drawbacks?
penguinpower
Context change is indeed slow, because it results in a reset of the graphics pipeline at a low level. That's why concurrent GL applications became an important topic in hardware and driver design.The penalty of context switching however may be neglictible if context switches are done on a regular (well embedded) and low frequent basis.
ypnos
SO I drop context changes and just load the image from disk in a seperate thread (I need this to do a lot) and make it availiable to the Tile within the UI thread and actually fill the texture there with actual map image data.
penguinpower