Random texture loading

I try to load all the game data at the same time into my game scene constructor. But it fails because texture loading only works in the opengl context, for example, if the loading method is called from a drawing frame or a surface change. But I think it is ugly to load textures when the shot is first called or something like that. So is it possible to somehow separate my boot part from the opengl functions?

+1
source share
2 answers

I have exactly the same problem. My solution uses proxy textures . This means that when you create textures using some data from memory or a file, you create a dummy texture containing a copy of the memory data or the path to the file (you can preload the data into memory for faster loading).

After that, the next time my handler calls bind () (something like glBindTexture), I check if there is data to load, and if it exists, I just create a new texture and load the data.

This approach suits me better, because in my case, textures can be created from any stream and at any time.

But if you want to preload all the textures, you can just do it in onSurfaceCreated or onSurfaceChanged

The same goes for buffers.

Another approach is to use your own activity (check out the NDK example). In this case, you can process the context manually, but it requires API level 9.

+3
source

But I think it is ugly to load textures when I first drew a drawframe or something like that.

In fact, deferred texture loading is the most elegant method. This is one of the key components for games that allow you to travel the world without interrupting the loading of screens. Just don't try to download the whole world right away, but download things as soon as they become visible. Use Pixel Buffer objects to do asynchronous work.

+1
source

Source: https://habr.com/ru/post/1310703/


All Articles