HTC Desire上的EGLConfig,可用配置挂起设备

时间:2011-01-30 18:36:45

标签: android opengl-es

我正在实现自己的EGLConfigChooser传递给setEGLConfigChooser(),以便根据我对应用程序的需求为当前设备选择最佳可用配置。

更具体地说,我正在查询所有可用的配置并选择具有最大深度缓冲区大小的配置(以及具有相同深度缓冲区大小的那些之间我想要具有最大颜色深度的那个),代码墙如下:

 @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;
 }

(print方法将EGLConfig值打印到Logger中)

现在,它似乎工作正常,它选择以下配置:

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的启发)

感谢您的帮助。

1 个答案:

答案 0 :(得分:14)

尝试添加:

getHolder()。setFormat(PixelFormat.RGBA_8888);

在设置GL配置选择器之后,对于曲面构造函数。基本上我在选择格式8,8,8,0,0,0(R8,G8,B8,A0,Z0,Stencil0)时遇到了崩溃,直到我添加了该行......

史蒂夫