2013-08-26 112 views
0

我正在使用下面的代碼進行MultiSampling以使光滑邊緣。下面的代碼正在處理一些移動和其他移動設備我收到異常'No configs match configSpec獲取例外:致命例外:GLThread沒有配置匹配configSpec

請幫我解決這個問題。

在此先感謝。

package com.amplimesh.renderer; 

import javax.microedition.khronos.egl.EGL10; 
import javax.microedition.khronos.egl.EGLConfig; 
import javax.microedition.khronos.egl.EGLDisplay; 

import android.opengl.GLSurfaceView; 
import android.util.Log; 

// This class shows how to use multisampling. To use this, call 
// myGLSurfaceView.setEGLConfigChooser(new MultisampleConfigChooser()); 
// before calling setRenderer(). Multisampling will probably slow down 
// your app -- measure performance carefully and decide if the vastly 
// improved visual quality is worth the cost. 
public class MultisampleConfigChooser implements GLSurfaceView.EGLConfigChooser { 
    static private final String kTag = "GDC11"; 
    @Override 
    public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) { 
     mValue = new int[1]; 

     // Try to find a normal multisample configuration first. 
     int[] configSpec = { 
       EGL10.EGL_RED_SIZE, 5, 
       EGL10.EGL_GREEN_SIZE, 6, 
       EGL10.EGL_BLUE_SIZE, 5, 
       EGL10.EGL_DEPTH_SIZE, 16, 
       // Requires that setEGLContextClientVersion(2) is called on the view. 
       EGL10.EGL_RENDERABLE_TYPE, 4 /* EGL_OPENGL_ES2_BIT */, 
       EGL10.EGL_SAMPLE_BUFFERS, 1 /* true */, 
       EGL10.EGL_SAMPLES, 2, 
       EGL10.EGL_NONE 
     }; 

     if (!egl.eglChooseConfig(display, configSpec, null, 0, 
       mValue)) { 
      throw new IllegalArgumentException("eglChooseConfig failed"); 
     } 
     int numConfigs = mValue[0]; 

     if (numConfigs <= 0) { 
      // No normal multisampling config was found. Try to create a 
      // converage multisampling configuration, for the nVidia Tegra2. 
      // See the EGL_NV_coverage_sample documentation. 

      final int EGL_COVERAGE_BUFFERS_NV = 0x30E0; 
      final int EGL_COVERAGE_SAMPLES_NV = 0x30E1; 

      configSpec = new int[]{ 
        EGL10.EGL_RED_SIZE, 5, 
        EGL10.EGL_GREEN_SIZE, 6, 
        EGL10.EGL_BLUE_SIZE, 5, 
        EGL10.EGL_DEPTH_SIZE, 16, 
        EGL10.EGL_RENDERABLE_TYPE, 4 /* EGL_OPENGL_ES2_BIT */, 
        EGL_COVERAGE_BUFFERS_NV, 1 /* true */, 
        EGL_COVERAGE_SAMPLES_NV, 2, // always 5 in practice on tegra 2 
        EGL10.EGL_NONE 
      }; 

      if (!egl.eglChooseConfig(display, configSpec, null, 0, 
        mValue)) { 
       throw new IllegalArgumentException("2nd eglChooseConfig failed"); 
      } 
      numConfigs = mValue[0]; 

      if (numConfigs <= 0) { 
       // Give up, try without multisampling. 
       configSpec = new int[]{ 
         EGL10.EGL_RED_SIZE, 5, 
         EGL10.EGL_GREEN_SIZE, 6, 
         EGL10.EGL_BLUE_SIZE, 5, 
         EGL10.EGL_DEPTH_SIZE, 16, 
         EGL10.EGL_RENDERABLE_TYPE, 4 /* EGL_OPENGL_ES2_BIT */, 
         EGL10.EGL_NONE 
       }; 

       if (!egl.eglChooseConfig(display, configSpec, null, 0, 
         mValue)) { 
        throw new IllegalArgumentException("3rd eglChooseConfig failed"); 
       } 
       numConfigs = mValue[0]; 

       if (numConfigs <= 0) { 
        throw new IllegalArgumentException("No configs match configSpec"); 
       } 
      } else { 
       mUsesCoverageAa = true; 
      } 
     } 

     // Get all matching configurations. 
     EGLConfig[] configs = new EGLConfig[numConfigs]; 
     if (!egl.eglChooseConfig(display, configSpec, configs, numConfigs, 
       mValue)) { 
      throw new IllegalArgumentException("data eglChooseConfig failed"); 
     } 

     // CAUTION! eglChooseConfigs returns configs with higher bit depth 
     // first: Even though we asked for rgb565 configurations, rgb888 
     // configurations are considered to be "better" and returned first. 
     // You need to explicitly filter the data returned by eglChooseConfig! 
     int index = -1; 
     for (int i = 0; i < configs.length; ++i) { 
      if (findConfigAttrib(egl, display, configs[i], EGL10.EGL_RED_SIZE, 0) == 5) { 
       index = i; 
       break; 
      } 
     } 
     if (index == -1) { 
      Log.w(kTag, "Did not find sane config, using first"); 
     } 
     EGLConfig config = configs.length > 0 ? configs[index] : null; 
     if (config == null) { 
      throw new IllegalArgumentException("No config chosen"); 
     } 
     return config; 
    } 

    private int findConfigAttrib(EGL10 egl, EGLDisplay display, 
      EGLConfig config, int attribute, int defaultValue) { 
     if (egl.eglGetConfigAttrib(display, config, attribute, mValue)) { 
      return mValue[0]; 
     } 
     return defaultValue; 
    } 

    public boolean usesCoverageAa() { 
     return mUsesCoverageAa; 
    } 

    private int[] mValue; 
    private boolean mUsesCoverageAa; 
} 
+0

@Andon M. Coleman請幫助我解決這個問題。我希望你能幫助我。我正在使用OpenGl 1 –

回答

0

看起來您正在請求您的測試設備不支持的EGL配置。並非所有實現都支持多重採樣,因此您可能希望回到最有可能在任何設備上受支持的格式。目前您的回退格式爲RGB565,我的猜測是它在某些目標設備上不受支持。你可以嘗試RGBA8888或RGBA4444代替,所以例如:

configSpec = new int[] { 
     EGL10.EGL_RED_SIZE,  8, 
     EGL10.EGL_GREEN_SIZE,  8, 
     EGL10.EGL_BLUE_SIZE,  8, 
     EGL10.EGL_ALPHA_SIZE,  8, 
     EGL10.EGL_DEPTH_SIZE,  16, 
     EGL10.EGL_RENDERABLE_TYPE, 4, /* EGL_OPENGL_ES2_BIT */ 
     EGL10.EGL_NONE 
}; 

據我所知,RGBA8888 16位深度緩衝應該是在大多數比較近GLES2設備可用。

+0

當我現在使用上述配置時,我得到'08-27 11:00:12.809:E/AndroidRuntime(5193):java.lang.IllegalArgumentException:沒有配置選擇 '異常。請仔細閱讀我的代碼 – user2695306

+0

哦,對,如果你做了這些改變,你還需要在這一行代替'8'的'5':if(findConfigAttrib(egl,display,configs [i] ,EGL10.EGL_RED_SIZE,0)== 5){'。儘管循環遍歷所有返回的格式不應該在這裏,但你可以使用第一種格式,除非你很挑剔。 –

+0

我根據你所說的設置了上面的和上面的RGB配置,但仍然沒有進入for循環for(int i = 0; i user2695306

0

這是一個很老的問題,但我找到了解決方案(至少在我的情況下)。所以也許有人能夠找到它有幫助。

問題是仿真器使用的是集成圖形,而不是專用的,它不支持OpenGLES 2.0。所以要解決它,我不得不強制我的模擬器使用專用圖形。只需去你的圖形驅動程序,並強制他們使用專用的GPU而不是集成的。

在我的情況下,問題解決了:)