@ -2,7 +2,6 @@ package com.jme3.system.android;
import android.graphics.PixelFormat ;
import android.graphics.PixelFormat ;
import android.opengl.GLSurfaceView.EGLConfigChooser ;
import android.opengl.GLSurfaceView.EGLConfigChooser ;
import java.util.logging.Level ;
import java.util.logging.Logger ;
import java.util.logging.Logger ;
import javax.microedition.khronos.egl.EGL10 ;
import javax.microedition.khronos.egl.EGL10 ;
import javax.microedition.khronos.egl.EGLConfig ;
import javax.microedition.khronos.egl.EGLConfig ;
@ -217,6 +216,19 @@ public class AndroidConfigChooser implements EGLConfigChooser {
num_config ) ) {
num_config ) ) {
throw new IllegalArgumentException ( "eglChooseConfig#2 failed" ) ;
throw new IllegalArgumentException ( "eglChooseConfig#2 failed" ) ;
}
}
// logger.log(Level.INFO, "num_config: {0}", num_config[0]);
//
// logger.log(Level.INFO, "There are {0} configurations that match the configAttrs", num_config[0]);
// logger.log(Level.INFO, "All Matching Configs:");
// for (int i=0; i<configs.length; i++) {
// if (configs[i] != null) {
// logger.log(Level.INFO, "configs{0} is not null", i);
// logEGLConfig(configs[i], display, egl);
// } else {
// logger.log(Level.INFO, "configs{0} is null", i);
// }
// }
EGLConfig config = chooseConfig ( egl , display , configs ) ;
EGLConfig config = chooseConfig ( egl , display , configs ) ;
//if (config == null) {
//if (config == null) {
// throw new IllegalArgumentException("No config chosen");
// throw new IllegalArgumentException("No config chosen");
@ -287,6 +299,32 @@ public class AndroidConfigChooser implements EGLConfigChooser {
@Override
@Override
public EGLConfig chooseConfig ( EGL10 egl , EGLDisplay display , EGLConfig [ ] configs ) {
public EGLConfig chooseConfig ( EGL10 egl , EGLDisplay display , EGLConfig [ ] configs ) {
// first pass through config list. Try to find an exact match.
for ( EGLConfig config : configs ) {
int r = findConfigAttrib ( egl , display , config ,
EGL10 . EGL_RED_SIZE , 0 ) ;
int g = findConfigAttrib ( egl , display , config ,
EGL10 . EGL_GREEN_SIZE , 0 ) ;
int b = findConfigAttrib ( egl , display , config ,
EGL10 . EGL_BLUE_SIZE , 0 ) ;
int a = findConfigAttrib ( egl , display , config ,
EGL10 . EGL_ALPHA_SIZE , 0 ) ;
int d = findConfigAttrib ( egl , display , config ,
EGL10 . EGL_DEPTH_SIZE , 0 ) ;
int s = findConfigAttrib ( egl , display , config ,
EGL10 . EGL_STENCIL_SIZE , 0 ) ;
if ( (
r = = mRedSize ) & & ( g = = mGreenSize )
& & ( b = = mBlueSize ) & & ( a = = mAlphaSize )
& & ( d = = mDepthSize ) & & ( s = = mStencilSize )
) {
return config ;
}
}
// second pass through config list. Try to find an RGBA match.
for ( EGLConfig config : configs ) {
for ( EGLConfig config : configs ) {
int d = findConfigAttrib ( egl , display , config ,
int d = findConfigAttrib ( egl , display , config ,
EGL10 . EGL_DEPTH_SIZE , 0 ) ;
EGL10 . EGL_DEPTH_SIZE , 0 ) ;
@ -307,9 +345,16 @@ public class AndroidConfigChooser implements EGLConfigChooser {
}
}
}
}
}
}
// failsafe. pick the 1st config.
if ( configs . length > 0 ) {
return configs [ 0 ] ;
} else {
return null ;
return null ;
}
}
}
private int findConfigAttrib ( EGL10 egl , EGLDisplay display ,
private int findConfigAttrib ( EGL10 egl , EGLDisplay display ,
EGLConfig config , int attribute , int defaultValue ) {
EGLConfig config , int attribute , int defaultValue ) {