user1298416
user1298416

Reputation: 341

OpenGL - add multithreading for texture loading from the web

I have an OpenGL program that loads a big amount of textures from the web. Only part of these textures is displayed at first. Then a user can navigate and more textures are displayed. If I load all the textures before displaying anything - it takes a long time to load, but extremely quick to navigate. If I'm loading in chunks - quicker to load, but a bit slower to navigate. Would adding a separate thread that continues to load images from the web help in this case? What are other ways that can help to speed it up?

Upvotes: 3

Views: 858

Answers (1)

datenwolf
datenwolf

Reputation: 162164

The main problem with OpenGL and multithreading is, that while it is possible, it has certain pitfalls that one must be aware of.

The usual approach is to create multiple OpenGL contexts (one per thread) which are setup to share their "lists" (which also includes textures, among other things).

However before you even go down this road, it would be wise to check, if you actually have to multithread the OpenGL part at all. For example on the OpenGL renderer thread side, you could create a bunch of buffer objects and map those into the process address space, to be filled by the texture fetcher thread.

Or you would just have the texture fetcher thread load and prepare everything and then send the OpenGL thread a message (for example by putting it into a std::queue or such), containing a reference to the prepared texture data; the OpenGL thread then could implement asynchronous loading of that data via buffer object streaming.

Upvotes: 4

Related Questions