在AndroidNDK中的samples\hello-gl2下的实例,在Android的模拟器下运行,如果不该任何代码,会出现错误:
ERROR/AndroidRuntime(258): java.lang.IllegalArgumentException: No configs match configSpec
代码错误行数在:
chooseConfig方法的如下行:
if (numConfigs <= 0) {
throw new IllegalArgumentException("No configs match configSpec");
}
即当numConfigs小于0时,系统检测配置不匹配
修复该错误需要调整 init方法的如下代码
private void init(boolean translucent, int depth, int stencil) {
setEGLConfigChooser( translucent ?
new ConfigChooser(8, 8, 8, 8, depth, stencil) :
new ConfigChooser(5, 6, 5, 0, depth, stencil) );
修改为:
setEGLConfigChooser(5, 6, 5, 0, 0, 0);
就可以在模拟器运行。
变通版本:
if(translucent){
setEGLConfigChooser(8, 8, 8, 8, depth, stencil);
}else{
setEGLConfigChooser(5, 6, 5, 0, depth, stencil);
}
分析原因:
void android.opengl..setEGLConfigChooser(int redSize, int greenSize, int blueSize, int alphaSize, int depthSize, int stencilSize);
该API的6个参数表示设置的R,G,B,Alpha,depth,stencil的值
注意对应的重载版本
public void setEGLConfigChooser(EGLConfigChooser configChooser) {
checkRenderThreadState();
mEGLConfigChooser = configChooser;
}
public void setEGLConfigChooser(boolean needDepth) {
setEGLConfigChooser(new SimpleEGLConfigChooser(needDepth));
}
public void setEGLConfigChooser(int redSize, int greenSize, int blueSize,
int alphaSize, int depthSize, int stencilSize) {
setEGLConfigChooser(new ComponentSizeChooser(redSize, greenSize,
blueSize, alphaSize, depthSize, stencilSize));
}
两个方法对应的内部实现还是有些差别的
转帖:http://hi.baidu.com/huareal/item/f00ad3cf8d35ebd7ee183b83