如何正确初始化,并在Android终止EGL [英] How to properly initialize and terminate EGL on Android

查看:311
本文介绍了如何正确初始化,并在Android终止EGL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然有很多样品约使用OpenGL ES在Android周围所有的人都似乎是不正确的(甚至是那些配备了Android的SDK / NDK)相对于EGL初始化/终止。和问题的根源就在Android应用程序模型使用EGL怪异而做出正确的。

While there are many samples around about using OpenGL ES on Android all of them seems to be incorrect (even ones come with Android SDK/NDK) in respect to initialization/termination of EGL. And source of problem is just in Android application model which make correct using of EGL weird.

每个OS的是EGL初始化的真正问题的处理,而所有Android的样品,甚至 GLSurfaceView (实际上大多数样品只需要使用它)涉及东瀛初始化/终止元的组件(活动或WallpaperService)。这是完全错误的,由于这一事实,即所有的部件都在同一个进程中运行!是没有问题的,如果应用由仅仅一个部件的,但,这是一个问题,如果有在应用程序的多个组件和它们正在使用的OpenGL ES每个

The real problem that EGL initialized per OS's process while all Android samples and even GLSurfaceView (actually most of samples just use it) involve the EGL initialization/termination per Component (Activity or WallpaperService). And this is completely wrong due to the fact that all components are running in same process! There is no problem if application consist of just one component but this is an issue if there are multiple components in application and they are using OpenGL ES each.

只是看看情况时,它使用OpenGL ES的两个应用的组件在同一时间运行,其中一人完成。在完成这样的组件将调用 eglTerminate()(看看 GLSurfaceView 源$ C ​​$ C,看看我说的),这将终止EGL是全< STRONG>过程!而且任何EGL从其他已经运行的组件调用将失败从这一刻开始!

Just consider the situation when two application's components which use the OpenGL ES runs at same time and one of them finished. On finishing such component will call the eglTerminate() (Look in GLSurfaceView source code to see what I am talking about) and this will terminate the EGL for whole process! And any EGL calls from another already running component will fail starting from this moment!

我有检查的例子吨,所有的人都初始化和每个组件的基础上(实际上没有人我见过做的东西比 GLSurfaceView 做,大多只是拷贝不同的 GLSurfaceView 内部)。

I have check for tons of examples and all of them initialize and terminate EGL per component basis (actually no one I have seen do something different than GLSurfaceView do, most of them just copy of GLSurfaceView internals).

和我现在有趣的发现的正确的的方式来获得工作(相对于初始化/终止)与EGL在Android上。

And now I am interesting in find a "proper" way to get working (with respect to initialization/termination) with EGL on Android.

正确的方式应提供:

  1. 在开始时使用EGL任第一部分EGL初始化
  2. 在东瀛终端在使用EGL最后一个组件结束
  3. 在多线程。这里不应该限制EGL操作只能从主应用程序线程。

请注意,(2)是必要的,以尽量减少系统资源的使用由应用程序时,有其使用EGL / OpenGL ES的无活性实体。

Please note that (2) is essential to minimize the system resources usage by application when there is no active entities which use the EGL/OpenGL ES.

任何想法?或者,也许我忽略了一些关于EGL在Android?

Any ideas? Or maybe I have overlooked something about the EGL on Android?

还有一个有趣的相关的问题:

There is another interesting related issue:

由于这一事实,即只有一个活动的呈现环境的每个线程允许的,只有一个在同一时间元器件可使用的OpenGL ES从主线程正常。有多个组件而使用的OpenGL ES在主线程在同一时间运行会导致问题,因为最后一个组件调用 eglMakeCurrent()会隐代替所有其他组件上下文由他自己一个人(这实际上将彻底打破了组件的逻辑)。

Due to the fact that only one active rendering context is allowed per thread, only one Component at same time may use OpenGL ES from main thread normally. Having more than one Component which use the OpenGL ES in main thread running at same time will lead to problems because last component calling eglMakeCurrent() will implicitly "substitute" all other Components' contexts by his own one (and this actually will completely broke the components logic).

据透露(感谢罗曼盖伊),该机器人实际上已经为EGL初始化/终止问题的一种形式,内部的解决办法明确(这是对EGL规格,在Android未提及文档)引用计数的 eglInitialize() eglTerminate()

It was revealed (thanks to Romain Guy) that Android actually has an internal workaround for EGL initialization/termination issue in a form of explicit (it is against the EGL specification and not mentioned in the Android documentation) "reference counting" inside the eglInitialize() and eglTerminate().

推荐答案

eglTerminate()和eglInitialize()的引用计数,因此没关系每个部件来调用它们。在Android 3.0尤其,这是非常常见的有几个的OpenGL上下文中相同的应用程序,并且是没有问题的任何使用EGL

eglTerminate() and eglInitialize() are reference counted so it's okay for each "component" to invoke them. On Android 3.0 in particular, it is very common to have several OpenGL contexts in the same app, and there is no problem whatsoever with EGL.

这篇关于如何正确初始化,并在Android终止EGL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆