Loading textures at random place

匿名 (未验证) 提交于 2019-12-03 09:14:57

问题:

I'm trying to load all the game data at the same time, in my game scene's constructor. But it fails, because texture loading works only in an opengl context, like if load method called from draw frame or surfacechanged. But i think it's ugly to load textures when the drawframe first called or something similar. So is it possible somehow to separate my loading part from opengl functions?

回答1:

I have exactly the same problem. My solution is using the proxy textures. It means that when you're creating textures using some data from memory or file you're creating the dummy texture that holds the copy of that memory data or the file path (you can preload the data into memory for faster loading).

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

This approach fits best to me, because in my case textures could be created from any thread and any time.

But if you want to preload all textures you can just do that in onSurfaceCreated or onSurfaceChanged

The same applies to buffers.

Another approach is using the native activity (check the NDK example). In this case you can handle context manually but it requires API level 9.



回答2:

But i think it's ugly to load textures when the drawframe first called or something similar.

Actually deferred texture loading is the most elegant methods. It's one of the key ingredients for games that allow for traveling the world without interrupting loading screens. Just don't try to load the whole world at once, but load things, as soon they are about to become visible. Use Pixel Buffer Objects to do things asynchronously.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!