How can dynamically load textures in OpenGL?

I am currently loading the image into memory on the 2nd stream, and then during the display cycle (if texture loading is required), load the texture.

I found that I could not load the texture in the second thread because OpenGL did not like it; perhaps it is possible, but I did something wrong - so please correct me if it is really possible.

On the other hand, if my failure was valid - how to load the texture without breaking the rendering cycle? Currently, textures take about 1 second to load from memory, and although this is not a serious problem, it can be a bit annoying to the user.

+6
c ++ opengl textures
source share
2 answers

You can load a texture from disk into memory onto any stream you like using any tool you want to read.

However, when you bind it to OpenGL, it will need to be processed in the same thread as the rendering for this OpenGL context. However, this discussion suggests that using PBO in the second thread is an option and can speed up the process.

+4
source share

You can load a texture from disk to RAM in any number of threads that you like, but OpenGL will not load into VRAM in multiple threads for the reason mentioned in Reed's answer.

Given that booting from disk is the slowest part, this is a bit that you probably want to use. The boot thread creates a queue of loaded textures, then this queue is consumed by the thread that owns the GL context (pay attention to your access to this queue by various threads). You can also consider a non-threaded approach to loading N textures per frame, where N is a number that doesn't slow down the rendering too much.

+1
source share

All Articles