简体   繁体   English

屏幕旋转时Android OpenGL重新加载程序

[英]Android opengl reloading programs when screen rotated

It seems that in android with opengl when you rotate your screen, activity gets recreated. 似乎在带有opengl的android中,旋转屏幕时会重新创建活动。 Does thus cause all the opengl programs to be unloaded from the memory? 这样是否会导致所有opengl程序都从内存中卸载? When I use GLES20.glUseProgram(savedProgramId); 当我使用GLES20.glUseProgram(savedProgramId); It says that there is no such program. 它说没有这样的程序。 What do I do wrong? 我做错了什么? (By the way, I keep my program id in a static field) (顺便说一句,我将程序ID保留在一个静态字段中)

You can make changes to your manifest to indicate that you will handle changes in screen orientation yourself. 您可以对清单进行更改,以指示您将自己处理屏幕方向的更改。

See 'configchanges'+'orientation' here: http://developer.android.com/guide/topics/manifest/activity-element.html 请参阅此处的“ configchanges” +“方向”: http//developer.android.com/guide/topics/manifest/activity-element.html

However, you'll still have the problem that your OpenGL context will be lost when the user switches between apps. 但是,您仍然会遇到以下问题:当用户在应用之间切换时,OpenGL上下文将丢失。

The most correct thing to do is to fully handle loss and recreation of the OpenGL context and all associated resources. 最正确的做法是完全处理OpenGL上下文以及所有相关资源的丢失和重新创建。 In a large and complex project this can be very difficult. 在大型而复杂的项目中,这可能非常困难。

A reasonable alternative is to use setPreserveEGLContextOnPause ( http://developer.android.com/reference/android/opengl/GLSurfaceView.html#setPreserveEGLContextOnPause%28boolean%29 ) which is available on Android 4.0 and above. 合理的替代方法是使用setPreserveEGLContextOnPause( http://developer.android.com/reference/android/opengl/GLSurfaceView.html#setPreserveEGLContextOnPause%28boolean%29 ),该版本可在Android 4.0及更高版本上使用。

The documentation states that the OpenGL context might not always be preserved, but my opinion is that it works well enough to ship with and avoids a lot of complicated code. 该文档指出,OpenGL上下文可能并不总是被保留,但是我认为它可以很好地随行并避免了很多复杂的代码。 When your app is in the background, it might get terminated due to memory pressure anyway, so if it's terminated occasionally due to a device's limit on EGL contexts then that seems acceptable to me. 当您的应用程序在后台运行时,无论如何它都可能由于内存压力而终止,因此,如果由于设备对EGL上下文的限制而偶尔终止了该应用程序,那对我来说似乎可以接受。

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

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