diff --git a/engine/src/android/com/jme3/app/AndroidHarness.java b/engine/src/android/com/jme3/app/AndroidHarness.java index ad4e328ce..49886ead7 100644 --- a/engine/src/android/com/jme3/app/AndroidHarness.java +++ b/engine/src/android/com/jme3/app/AndroidHarness.java @@ -68,7 +68,7 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt /** * set to 2, 4 to enable multisampling. */ -// protected int antiAliasingSamples = 0; + protected int antiAliasingSamples = 0; /** * If true Android Sensors are used as simulated Joysticks Users can use the * Android sensor feedback through the RawInputListener or by registering @@ -193,7 +193,7 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt settings.setEmulateMouse(mouseEventsEnabled); settings.setEmulateMouseFlipAxis(mouseEventsInvertX, mouseEventsInvertY); settings.setUseJoysticks(joystickEventsEnabled); -// settings.setSamples(antiAliasingSamples); + settings.setSamples(antiAliasingSamples); settings.setResolution(disp.getWidth(), disp.getHeight()); settings.put(AndroidConfigChooser.SETTINGS_CONFIG_TYPE, eglConfigType); diff --git a/engine/src/android/com/jme3/system/android/AndroidConfigChooser.java b/engine/src/android/com/jme3/system/android/AndroidConfigChooser.java index 4b0115a92..fc1918b4c 100644 --- a/engine/src/android/com/jme3/system/android/AndroidConfigChooser.java +++ b/engine/src/android/com/jme3/system/android/AndroidConfigChooser.java @@ -34,9 +34,10 @@ public class AndroidConfigChooser implements EGLConfigChooser { */ FASTEST(5, 6, 5, 0, 16, 0, 5, 6, 5, 0, 16, 0), /** - * RGB???, 0 alpha, >=16 depth, 0 stencil + * min RGB888, 0 alpha, 16 depth, 0 stencil max RGB888, 0 alpha, 32 + * depth, 8 stencil */ - BEST(8, 8, 8, 0, 32, 0, 8, 8, 8, 0, 16, 0), + BEST(8, 8, 8, 0, 32, 8, 8, 8, 8, 0, 16, 0), /** * Turn off config chooser and use hardcoded * setEGLContextClientVersion(2); setEGLConfigChooser(5, 6, 5, 0, 16, @@ -44,17 +45,18 @@ public class AndroidConfigChooser implements EGLConfigChooser { */ LEGACY(5, 6, 5, 0, 16, 0, 5, 6, 5, 0, 16, 0), /** - * RGB???, 8 alpha, >=16 depth, 0 stencil + * min RGB888, 8 alpha, 16 depth, 0 stencil max RGB888, 8 alpha, 32 + * depth, 8 stencil */ - BEST_TRANSLUCENT(8, 8, 8, 8, 32, 0, 8, 8, 8, 8, 16, 0); + BEST_TRANSLUCENT(8, 8, 8, 8, 32, 8, 8, 8, 8, 8, 16, 0); /** - * red, green, blue, alpha, depth, stencil + * red, green, blue, alpha, depth, stencil (max values) */ int r, g, b, a, d, s; /** - * fallback + * minimal values */ - int fbr, fbg, fbb, fba, fbd, fbs; + int mr, mg, mb, ma, md, ms; private ConfigType(int r, int g, int b, int a, int d, int s, int fbr, int fbg, int fbb, int fba, int fbd, int fbs) { this.r = r; @@ -63,12 +65,12 @@ public class AndroidConfigChooser implements EGLConfigChooser { this.a = a; this.d = d; this.s = s; - this.fbr = fbr; - this.fbg = fbg; - this.fbb = fbb; - this.fba = fba; - this.fbd = fbd; - this.fbs = fbs; + this.mr = fbr; + this.mg = fbg; + this.mb = fbb; + this.ma = fba; + this.md = fbd; + this.ms = fbs; } } @@ -104,45 +106,15 @@ public class AndroidConfigChooser implements EGLConfigChooser { * @param display * @return true if successfull, false if no config was found */ - public boolean findConfig(EGL10 egl, EGLDisplay display) { + public boolean findConfig(EGL10 egl, EGLDisplay display) { ConfigType type = (ConfigType) settings.get(SETTINGS_CONFIG_TYPE); - ComponentSizeChooser compChooser = new ComponentSizeChooser(type.r, type.g, type.b, type.a, type.d, type.s, 4,1,2); + ComponentSizeChooser compChooser = new ComponentSizeChooser(type, settings.getSamples()); choosenConfig = compChooser.chooseConfig(egl, display); - if (choosenConfig == null) { - compChooser = new ComponentSizeChooser(type.fbr, type.fbg, type.fbb, type.fba, type.fbd, type.fbs); - choosenConfig = compChooser.chooseConfig(egl, display); - } logger.log(Level.FINE, "JME3 using {0} EGL configuration available here: ", type.name()); -// switch (type) { -// case BEST: -// compChooser = new ComponentSizeChooser(8, 8, 8, 0, 32, 0); -// choosenConfig = compChooser.chooseConfig(egl, display); -// if (choosenConfig == null) { -// compChooser = new ComponentSizeChooser(8, 8, 8, 0, 16, 0); -// choosenConfig = compChooser.chooseConfig(egl, display); -// } -// logger.fine("JME3 using best EGL configuration available here: "); -// break; -// case BEST_TRANSLUCENT: -// compChooser = new ComponentSizeChooser(8, 8, 8, 8, 32, 0); -// choosenConfig = compChooser.chooseConfig(egl, display); -// if (choosenConfig == null) { -// compChooser = new ComponentSizeChooser(8, 8, 8, 8, 16, 0); -// choosenConfig = compChooser.chooseConfig(egl, display); -// } -// logger.fine("JME3 using best EGL configuration available here with translucent pixels: "); -// break; -// case FASTEST: -// compChooser = new ComponentSizeChooser(5, 6, 5, 0, 16, 0); -// choosenConfig = compChooser.chooseConfig(egl, display); -// logger.fine("JME3 using fastest EGL configuration available here: "); -// break; -// -// } if (choosenConfig != null) { - logger.fine("JME3 using choosen config: "); + logger.info("JME3 using choosen config: "); logEGLConfig(choosenConfig, display, egl); pixelFormat = getPixelFormat(choosenConfig, display, egl); clientOpenGLESVersion = getOpenGLVersion(choosenConfig, display, egl); @@ -197,34 +169,34 @@ public class AndroidConfigChooser implements EGLConfigChooser { int[] value = new int[1]; egl.eglGetConfigAttrib(display, conf, EGL10.EGL_RED_SIZE, value); - logger.fine(String.format("EGL_RED_SIZE = %d", value[0])); + logger.info(String.format("EGL_RED_SIZE = %d", value[0])); egl.eglGetConfigAttrib(display, conf, EGL10.EGL_GREEN_SIZE, value); - logger.fine(String.format("EGL_GREEN_SIZE = %d", value[0])); + logger.info(String.format("EGL_GREEN_SIZE = %d", value[0])); egl.eglGetConfigAttrib(display, conf, EGL10.EGL_BLUE_SIZE, value); - logger.fine(String.format("EGL_BLUE_SIZE = %d", value[0])); + logger.info(String.format("EGL_BLUE_SIZE = %d", value[0])); egl.eglGetConfigAttrib(display, conf, EGL10.EGL_ALPHA_SIZE, value); - logger.fine(String.format("EGL_ALPHA_SIZE = %d", value[0])); + logger.info(String.format("EGL_ALPHA_SIZE = %d", value[0])); egl.eglGetConfigAttrib(display, conf, EGL10.EGL_DEPTH_SIZE, value); - logger.fine(String.format("EGL_DEPTH_SIZE = %d", value[0])); + logger.info(String.format("EGL_DEPTH_SIZE = %d", value[0])); egl.eglGetConfigAttrib(display, conf, EGL10.EGL_STENCIL_SIZE, value); - logger.fine(String.format("EGL_STENCIL_SIZE = %d", value[0])); + logger.info(String.format("EGL_STENCIL_SIZE = %d", value[0])); egl.eglGetConfigAttrib(display, conf, EGL10.EGL_RENDERABLE_TYPE, value); - logger.fine(String.format("EGL_RENDERABLE_TYPE = %d", value[0])); + logger.info(String.format("EGL_RENDERABLE_TYPE = %d", value[0])); egl.eglGetConfigAttrib(display, conf, EGL10.EGL_SURFACE_TYPE, value); - logger.fine(String.format("EGL_SURFACE_TYPE = %d", value[0])); + logger.info(String.format("EGL_SURFACE_TYPE = %d", value[0])); egl.eglGetConfigAttrib(display, conf, EGL10.EGL_SAMPLE_BUFFERS, value); - logger.fine(String.format("EGL_SAMPLE_BUFFERS = %d", value[0])); + logger.info(String.format("EGL_SAMPLE_BUFFERS = %d", value[0])); egl.eglGetConfigAttrib(display, conf, EGL10.EGL_SAMPLES, value); - logger.fine(String.format("EGL_SAMPLES = %d", value[0])); + logger.info(String.format("EGL_SAMPLES = %d", value[0])); } public int getClientOpenGLESVersion() { @@ -241,78 +213,34 @@ public class AndroidConfigChooser implements EGLConfigChooser { private abstract class BaseConfigChooser implements EGLConfigChooser { - private boolean bClientOpenGLESVersionSet; - - public BaseConfigChooser(int[] configSpec) { - bClientOpenGLESVersionSet = false; - mConfigSpec = filterConfigSpec(configSpec); + public BaseConfigChooser() { } + @Override public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) { - int[] num_config = new int[1]; - if (!egl.eglChooseConfig(display, mConfigSpec, null, 0, - num_config)) { - throw new IllegalArgumentException("eglChooseConfig failed"); - } - int numConfigs = num_config[0]; + int[] num_config = new int[1]; + int[] configSpec = new int[]{ + EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, + EGL10.EGL_NONE}; - if (numConfigs <= 0) { - //throw new IllegalArgumentException("No configs match configSpec"); - - return null; - } + egl.eglChooseConfig(display, configSpec, null, 0, num_config); + int numConfigs = num_config[0]; EGLConfig[] configs = new EGLConfig[numConfigs]; - if (!egl.eglChooseConfig(display, mConfigSpec, configs, numConfigs, - num_config)) { - throw new IllegalArgumentException("eglChooseConfig#2 failed"); - } -// logger.log(Level.FINE, "num_config: {0}", num_config[0]); -// -// logger.log(Level.FINE, "There are {0} configurations that match the configAttrs", num_config[0]); -// logger.log(Level.FINE, "All Matching Configs:"); -// for (int i=0; i= kd) { + kd = d; + keep = true; + } else { + keep = false; + } - if ((r == mRedSize) && (g == mGreenSize) - && (b == mBlueSize) && (a == mAlphaSize) - && (d == mDepthSize) && (s == mStencilSize)) { - return config; + if (mSamples != 0) { + if (nbMs >= knbMs && nbMs <= mSamples) { + knbMs = nbMs; + keep = true; + } else { + keep = false; + } + } + + if (keep) { + keptConfig = config; + } } } - // second pass through config list. Try to find an RGBA match. - for (EGLConfig config : configs) { - int d = findConfigAttrib(egl, display, config, - EGL10.EGL_DEPTH_SIZE, 0); - int s = findConfigAttrib(egl, display, config, - EGL10.EGL_STENCIL_SIZE, 0); - if ((d >= mDepthSize) && (s >= mStencilSize)) { - 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); - if ((r == mRedSize) && (g == mGreenSize) - && (b == mBlueSize) && (a == mAlphaSize)) { - return config; - } - } + if (keptConfig != null) { + return keptConfig; } + // failsafe. pick the 1st config. if (configs.length > 0) { return configs[0]; @@ -433,6 +355,10 @@ public class AndroidConfigChooser implements EGLConfigChooser { } + private boolean inRange(int val, int min, int max) { + return min <= val && val <= max; + } + private int findConfigAttrib(EGL10 egl, EGLDisplay display, EGLConfig config, int attribute, int defaultValue) {