我正在实现我自己的EGLConfigChooser
以传递给setEGLConfigChooser()
,以便根据我对应用程序的需求为当前设备选择最佳可用配置。HTC Desire上的EGLConfig,可用的配置会挂起设备
更具体地说,我查询了所有可用的配置,并选择了具有最大深度缓冲区大小(以及具有相同深度缓冲区大小的那些深度缓冲区大小,我希望具有最大色彩深度的那些配置),代码墙如下:
@Override
public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display)
{
//Querying number of configurations
int[] num_conf = new int[1];
egl.eglGetConfigs(display, null, 0, num_conf); //if configuration array is null it still returns the number of configurations
int configurations = num_conf[0];
//Querying actual configurations
EGLConfig[] conf = new EGLConfig[configurations];
egl.eglGetConfigs(display, conf, configurations, num_conf);
EGLConfig result = null;
for(int i = 0; i < configurations; i++)
{
Log.v("EGLConfigChooser", "Configuration #" + i);
print(egl, display, conf[i]);
result = better(result, conf[i], egl, display);
}
Log.v("EGLConfigChooser", "Chosen EGLConfig:");
print(egl, display, result);
return result;
}
/**
* Returns the best of the two EGLConfig passed according to depth and colours
* @param a The first candidate
* @param b The second candidate
* @return The chosen candidate
*/
private EGLConfig better(EGLConfig a, EGLConfig b, EGL10 egl, EGLDisplay display)
{
if(a == null) return b;
EGLConfig result = null;
int[] value = new int[1];
egl.eglGetConfigAttrib(display, a, EGL10.EGL_DEPTH_SIZE, value);
int depthA = value[0];
egl.eglGetConfigAttrib(display, b, EGL10.EGL_DEPTH_SIZE, value);
int depthB = value[0];
if(depthA > depthB)
result = a;
else if(depthA < depthB)
result = b;
else //if depthA == depthB
{
egl.eglGetConfigAttrib(display, a, EGL10.EGL_RED_SIZE, value);
int redA = value[0];
egl.eglGetConfigAttrib(display, b, EGL10.EGL_RED_SIZE, value);
int redB = value[0];
if(redA > redB)
result = a;
else if(redA < redB)
result = b;
else //if redA == redB
{
//Don't care
result = a;
}
}
return result;
}
(打印方法打印一个EGLConfig值到记录仪)
现在,它似乎正常工作时,它选择如下配置:
01-30 18:57:04.424: VERBOSE/EGLConfigChooser(1093): Chosen EGLConfig:
01-30 18:57:04.424: VERBOSE/EGLConfigChooser(1093): EGL_RED_SIZE = 8
01-30 18:57:04.424: VERBOSE/EGLConfigChooser(1093): EGL_BLUE_SIZE = 8
01-30 18:57:04.424: VERBOSE/EGLConfigChooser(1093): EGL_GREEN_SIZE = 8
01-30 18:57:04.424: VERBOSE/EGLConfigChooser(1093): EGL_ALPHA_SIZE = 8
01-30 18:57:04.424: VERBOSE/EGLConfigChooser(1093): EGL_DEPTH_SIZE = 24
01-30 18:57:04.424: VERBOSE/EGLConfigChooser(1093): EGL_ALPHA_FORMAT = 24
01-30 18:57:04.424: VERBOSE/EGLConfigChooser(1093): EGL_ALPHA_MASK_SIZE = 0
01-30 18:57:04.424: VERBOSE/EGLConfigChooser(1093): EGL_STENCIL_SIZE = 8
问题是,当使用这种配置时,手机屏幕会变成绿色,带有紫色伪像(场景应该是黑色的木桌),它完全挂起并停止响应任何类型的输入,我所能做的就是通过调试器终止我的进程,当我这样做设备重新启动(?!!)。
为什么eglGetConfigs
返回导致这类问题的配置?有没有人遇到类似的问题,或者可以在我的代码中找到某种缺陷?我再次检查它,但它看起来对我来说很好(它的灵感来自于http://brandnewreality.com/blog/android-egl-querying-your-gl-driver)
感谢您的帮助。
链接for print()方法被破坏。这里是从backback机器:https://web.archive.org/web/20111230060315/http://brandnewreality.com/blog/android-egl-querying-your-gl-driver – kurtzmarc 2016-08-16 14:18:52