Friday, May 24, 2013

Android OpenGL ES 2.0 - Emulator Configuration and GPU options



Consult me on Skype

GPU Option with Android Virtual Device. Exceptions cases and Solution

 

Android 4.2.2 ( API 17 )
Debugging with Android Virutal Device



FATAL EXCEPTION: GLThread 75
java.lang.IllegalArgumentException: No configs match configSpec
at android.opengl.GLSurfaceView$BaseConfigChooser.chooseConfig(GLSurfaceView.java:863)
at android.opengl.GLSurfaceView$EglHelper.start(GLSurfaceView.java:1024)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1401)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)

The above exception occurs for the following below casea . The code ( for the Category.LAUNCHER class ) + emulator configuration for each case is given below

CASE-1 # 

Code that throws the above exception 

Code:


public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.d(this.getClass().getName(), "Into onCreate Draw triangle");
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
       
        if (detectOpenGLES20()){

            Log.d("GLES20", "GL ES 2.0 Supported..............!");

          } else {

            Log.d("GLES20", "GL ES 2.0 Not Supported...............!");

          }
       
        view = new GLSurfaceView(this);
        view.setEGLContextClientVersion(2);
        view.setEGLConfigChooser(true);
        view.setRenderer(new TriangleRenderer(view));
        setContentView(view);
    }
   
Emulator configuration:
  
In the 'Edit Android Virtual Device' windoow
'Snapshot' is unchekced and 'Use Host GPU' are unchecked
  

CASE-2 #    

This is same as CASE-1# except 'Use Host GPU' checkbox is CHECKED
This option can be edited in the Eclipse --> 'Edit Android Virtual Device' windoow ---> 'Use Host GPU'

In this Case we still get an IllegalArgumentException but with a different error message ( 'No config chosen' ) and also from different part the andriod.opengl.GLSurfaceViewBaseConfigChooser class
       
         
                 
Exception:
          
java.lang.IllegalArgumentException: No config chosen
:     at Android.opengl.GLSurfaceView$BaseConfigChooser.chooseConfig(GLSurfaceView.java:874)

Code:
   
    public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            Log.d(this.getClass().getName(), "Into onCreate Draw triangle");
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
            requestWindowFeature(Window.FEATURE_NO_TITLE);
           
            if (detectOpenGLES20()){
   
                Log.d("GLES20", "GL ES 2.0 Supported..............!");
   
              } else {
   
                Log.d("GLES20", "GL ES 2.0 Not Supported...............!");
   
              }
           
            view = new GLSurfaceView(this);
            view.setEGLContextClientVersion(2);
            view.setEGLConfigChooser(true);
            view.setRenderer(new TriangleRenderer(view));
            setContentView(view);
        }
       
Emulator configuration: 
In the 'Edit Android Virtual Device' windoow
       
'Snapshot' and 'Use Host GPU' checkboxes is CHECKED     

 CASE-3 # 

This is same as CASE-2# except the an additional '-gpu on' is present in the Emulator Launch Command Line Options


This option can be edited in the Eclipse --> Run as ---> Target ---> Additional Emulator Command Line Options
             
In this Case we still get an IllegalArgumentException but with a different error message ( 'No config chosen' ) and also from different part the andriod.opengl.GLSurfaceViewBaseConfigChooser class
     
             
             
Exception:
      
: java.lang.IllegalArgumentException: No config chosen
:     at android.opengl.GLSurfaceView$BaseConfigChooser.chooseConfig(GLSurfaceView.java:874)
     
  Code:
       
 public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.d(this.getClass().getName(), "Into onCreate Draw triangle");
                 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
                requestWindowFeature(Window.FEATURE_NO_TITLE);
               
                if (detectOpenGLES20()){
       
                    Log.d("GLES20", "GL ES 2.0 Supported..............!");
       
                  } else {
       
                    Log.d("GLES20", "GL ES 2.0 Not Supported...............!");
       
                  }
               
                view = new GLSurfaceView(this);
                view.setEGLContextClientVersion(2);
                view.setEGLConfigChooser(true);
                view.setRenderer(new TriangleRenderer(view));
                setContentView(view);
            }
           
Emulator configuration:           
In the 'Edit Android Virtual Device' windoow
        
'Snapshot' and 'Use Host GPU' checkboxes is CHECKED
   
Emulator Launch Command line options:
-gpu on
   

SOLUTION   

None of the Above three CASES# solve the problem
The problem gets RESOLVED by two steps below
   
a.) Adding an extra line of code: view.setEGLConfigChooser(8 , 8, 8, 8, 16, 0);

b.) setting '-gpu on' via Eclipse --> Run as ---> Target ---> Additional Emulator Command Line Options
   
      
Code:
   
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.d(this.getClass().getName(), "Into onCreate Draw triangle");
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
            requestWindowFeature(Window.FEATURE_NO_TITLE);
           
            if (detectOpenGLES20()){
   
                Log.d("GLES20", "GL ES 2.0 Supported..............!");
   
              } else {
   
                Log.d("GLES20", "GL ES 2.0 Not Supported...............!");
   
              }
           
            view = new GLSurfaceView(this);
            view.setEGLContextClientVersion(2);
            view.setEGLConfigChooser(8 , 8, 8, 8, 16, 0);
            view.setRenderer(new TriangleRenderer(view));
            setContentView(view);
    }

-------------------------------------------------------------

Discussion also available are stackoverflow
http://stackoverflow.com/questions/13717470/opengl-es-2-0-support-for-android

4 comments:

  1. See Also:

    http://stackoverflow.com/questions/13717470/opengl-es-2-0-support-for-android

    ReplyDelete
  2. Hello, i read your post, and i have one question, the solution, where i should put it?
    i mean, this is a new class or is inside of another class?

    ReplyDelete
    Replies
    1. The above solution is for classes that extend 'android.app.Activity' class when overriding 'onCreate(Bundle savedInstanceState)' method.

      Like here is a sample code for DrawTriangle class that extends Activity class.

      public class DrawTriangle extends Activity {
      GLSurfaceView view;


      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      Log.d(this.getClass().getName(), "Into onCreate Draw triangle");
      getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
      requestWindowFeature(Window.FEATURE_NO_TITLE);

      if (detectOpenGLES20()){

      Log.d("GLES20", "GL ES 2.0 Supported..............!");

      } else {

      Log.d("GLES20", "GL ES 2.0 Not Supported...............!");

      }

      view = new GLSurfaceView(this);
      view.setEGLContextClientVersion(2);
      view.setEGLConfigChooser(8 , 8, 8, 8, 16, 0);
      view.setRenderer(new TriangleRenderer(this));
      setContentView(view);
      }

      private boolean detectOpenGLES20() {

      ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);

      ConfigurationInfo info = am.getDeviceConfigurationInfo();

      return (info.reqGlEsVersion >= 0x20000);

      }
      }

      Delete
  3. thx for this tutorial

    i try many hours to setup opengl on emulator and this one line helps....

    view.setEGLConfigChooser(8 , 8, 8, 8, 16, 0);

    unbelievable

    ReplyDelete