简体   繁体   English

OpenGL ES 2.0异步加载场景(着色器和纹理)

[英]OpenGL ES 2.0 Load scene (shaders and textures) asynchronously

I write Android game that using OpenGL ES 2.0. 我写的Android游戏使用OpenGL ES 2.0。
For example, a some game scene is drawing. 例如,某个游戏场景正在绘制。 How I can load another scene in background and when it loaded switch them. 我如何在后台加载另一个场景以及加载时切换它们。 In background scene needs to load texture, generate their IDs and compile GL programs (shaders). 在后台场景中需要加载纹理,生成其ID并编译GL程序(着色器)。 But if I just create new Thread game crushes because game entities haven't access to GL context. 但是,如果我只是创建新的Thread游戏,那就是因为游戏实体无法访问GL上下文。 And if I try to make it in GLSurfaceView.queueEvent get same error. 而且,如果我尝试在GLSurfaceView.queueEvent中进行设置,则会得到相同的错误。
How I can do it? 我该怎么办? I found nothing by this theme. 我没有发现这个主题。
PS Sorry for my English. PS对不起,我的英语。

My advice is to keep the texture generation on the main thread. 我的建议是将纹理生成保留在主线程上。

Just do the image loading on a different thread. 只需在其他线程上加载图像即可。 Once the images are all loaded, notify the main thread, so that the main thread can do the actual creation of GL resources. 加载完所有映像后,通知主线程,以便主线程可以实际创建GL资源。

The file IO is probably slower than the actual gl texture creation anyway. 无论如何,文件IO可能比实际的gl纹理创建慢。

Also, for loading scenes, it pays to do the collision mesh generation on a helper thread, as that can be quite costly as well for large triangle meshes. 同样,对于加载场景,需要在辅助线程上生成碰撞网格物体,因为对于大型三角形网格物体而言,这同样会非常昂贵。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM