English 中文(简体)
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 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)




相关问题
Qt: Do events get processed in order?

If I had a class A, where one of its functions does: void A::func() { emit first_signal(); emit second_signal(); } Assuming that a class B has 2 slots, one connected to first_signal, and the ...

How to determine how much free space on a drive in Qt?

I m using Qt and want a platform-independent way of getting the available free disk space. I know in Linux I can use statfs and in Windows I can use GetDiskFreeSpaceEx(). I know boost has a way, ...

Drag & drop with .ui files

I m having big troubles with drag & drop. I ve created a new Qt Designer Form Class in which I have one QListWidget and one QWidget. Now I want to enable dragging & dropping between these two ...

Link errors on Snow Leopard

I creating a small desktop application using Qt and Poco on Mac OS X Snow Leopard. Qt works fine, but once I started linking with Poco I get the following warning: ld: warning: in /Developer/SDKs/...

Showing two windows in Qt4

My friend and I have each created parts of a GUI using Qt 4. They both work independently and I am trying to integrate his form with the my main window. As of now this is the code I am using to try ...

Qt equivalent of .NET data binding?

Is there an equivalent of .NET s data binding in Qt? I want to populate some combo boxes and other widgets with QStrings that refer to specific entities in my database. However, it would be cleaner ...

热门标签