问题描述
我在Samsung S4上遇到以下错误
I am getting the following error on Samsung S4
10-21 16:25:44.100: E/AndroidRuntime(29778): FATAL EXCEPTION: GLThread 11320
10-21 16:25:44.100: E/AndroidRuntime(29778): Process: <bundle ID>, PID: 29778
10-21 16:25:44.100: E/AndroidRuntime(29778): java.lang.RuntimeException: createContext failed: EGL_BAD_CONFIG
10-21 16:25:44.100: E/AndroidRuntime(29778): at android.opengl.GLSurfaceView$EglHelper.throwEglException(GLSurfaceView.java:1201)
10-21 16:25:44.100: E/AndroidRuntime(29778): at android.opengl.GLSurfaceView$EglHelper.throwEglException(GLSurfaceView.java:1192)
10-21 16:25:44.100: E/AndroidRuntime(29778): at android.opengl.GLSurfaceView$EglHelper.start(GLSurfaceView.java:1042)
10-21 16:25:44.100: E/AndroidRuntime(29778): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1409)
10-21 16:25:44.100: E/AndroidRuntime(29778): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1248)
该错误是由于:
this.setEGLContextFactory(new MyDefaultContextFactory());
this.setEGLConfigChooser(GL_RED_SIZE, GL_GREEN_SIZE, GL_BLUE_SIZE, GL_ALPHA_SIZE,
GL_DEPTH_SIZE, 0);//<-this line
this.setDebugFlags(GLSurfaceView.DEBUG_CHECK_GL_ERROR
| GLSurfaceView.DEBUG_LOG_GL_CALLS);
this.setPreserveEGLContextOnPause(true);
this.setEGLContextClientVersion(2);
通过的配置是:8,8,8,8,24
Where the configuration passed is : 8,8,8,8,24
最后移动上面的行是可行的.是什么原因呢?
Moving the above line at the end works though. Whats the reason for this?
PS:无论哪种情况,该代码都可以在Nexus5或MotoG上正常运行.所有运行Kitkat 4.4.2的设备
PS: The code works fine on Nexus5 or MotoG in either case.All devices running Kitkat 4.4.2
推荐答案
我没有看到它在文档,但查看,实际上似乎是setEGLContextClientVersion()
必须在之前被称为setEGLConfigChooser()
的情况
I don't see it clearly specified in the documentation, but from looking at the source code of GLSurfaceView
, it really appears to be the case that setEGLContextClientVersion()
must be called before setEGLConfigChooser()
.
不复制任何代码,因为我不确定这是否会侵犯版权,但是如果您拉出上面的代码链接,则可以继续进行以下操作:
Not copying any code because I'm not sure if that would violate copyrights, but you can follow along if you pull up the code link above:
- 代码中使用的
setEGLContextChooser()
重载会实例化一个新的ComponentSizeChoser
,并将指定的大小传递给构造函数. -
ComponentSizeChooser
的构造函数调用基类构造函数,将打包到配置规范中的指定大小传递给基本构造函数.基类是BaseConfigChooser
. -
BaseConfigChooser
的构造函数调用私有方法filterConfigSpec()
,并向其传递配置规范 -
filterConfigSpec()
查看mEGLContextClientVersion
成员变量的值,并使用它来确定EGL_RENDERABLE_TYPE
属性的值,并将其添加到配置规范中.然后,它将使用此附加属性返回配置规范. - 返回
BaseConfigChooser
构造函数,将修改后的配置规范分配给成员变量. - 稍后将在调用
chooseConfig()
方法时使用此成员变量中的配置规范,并在其中选择实际配置.
- The overload of
setEGLContextChooser()
used in your code instantiates a newComponentSizeChoser
, with the specified sizes passed to the constructor. - The constructor of
ComponentSizeChooser
invokes the base class constructor, passing the specified sizes packed into a config spec to the base constructor. The base class isBaseConfigChooser
. - The constructor of
BaseConfigChooser
invokes a private methodfilterConfigSpec()
, passing it the config spec, filterConfigSpec()
looks at the value of themEGLContextClientVersion
member variable, and uses it to determine the value of theEGL_RENDERABLE_TYPE
attribute, which it adds to the config spec. It then returns the config spec with this additional attribute.- Back in the
BaseConfigChooser
constructor, the modified config spec is assigned to a member variable. - The config spec in this member variable is used later when the
chooseConfig()
method is called, where the actual configuration is selected.
mEGLContextClientVersion
是setEGLContextClientVersion()
设置的值.因此,仅当在setEGLContextChooser()
之前调用setEGLContextClientVersion()
时,用此方法设置的值才包括在配置选择中.
mEGLContextClientVersion
is the value set by setEGLContextClientVersion()
. Therefore, the value set with this method will only be included in the configuration selection if setEGLContextClientVersion()
is called before setEGLContextChooser()
.
某些设备提供了同时支持ES 1.X和ES 2.0/3.0的配置,而其他设备则提供了针对1.X和2.0/3.0支持的单独配置.这很可能是为什么上下文创建在某些设备上以错误"顺序成功调用而在其他设备上却失败的原因.
Some devices provide configs that support both ES 1.X and ES 2.0/3.0, while others provide separate configs for 1.X and 2.0/3.0 support. This is most likely why the context creation succeeds with the calls in the "wrong" order on some devices, while it fails on others.
这篇关于在三星S4上打开GL错误的配置错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!