Android : changed the way the pixel config is passed to the OGLESContext. It's now passed in the appSettings.

This is a first step toward a generalization of the use of appSettings in the AndroidHarness.

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10458 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
rem..om 12 years ago
parent 1871a1831d
commit 9a28fed581
  1. 38
      engine/src/android/com/jme3/app/AndroidHarness.java
  2. 144
      engine/src/android/com/jme3/system/android/AndroidConfigChooser.java
  3. 39
      engine/src/android/com/jme3/system/android/OGLESContext.java

@ -25,6 +25,7 @@ import com.jme3.input.event.TouchEvent;
import com.jme3.renderer.android.AndroidGLSurfaceView;
import com.jme3.system.AppSettings;
import com.jme3.system.SystemListener;
import com.jme3.system.android.AndroidConfigChooser;
import com.jme3.system.android.AndroidConfigChooser.ConfigType;
import com.jme3.system.android.JmeAndroidSystem;
import com.jme3.system.android.OGLESContext;
@ -43,12 +44,10 @@ import java.util.logging.Logger;
public class AndroidHarness extends Activity implements TouchListener, DialogInterface.OnClickListener, SystemListener {
protected final static Logger logger = Logger.getLogger(AndroidHarness.class.getName());
/**
* The application class to start
*/
protected String appClass = "jme3test.android.Test";
/**
* The jme3 application object
*/
@ -59,55 +58,52 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt
* RGBA8888 or better if supported by the hardware
*/
protected ConfigType eglConfigType = ConfigType.FASTEST;
/**
* If true all valid and not valid egl configs are logged
* @deprecated this has no use
*/
@Deprecated
protected boolean eglConfigVerboseLogging = false;
/**
* If true Android Sensors are used as simulated Joysticks
* Users can use the Android sensor feedback through the RawInputListener
* or by registering JoyAxisTriggers.
* set to 2, 4 to enable multisampling.
*/
// 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
* JoyAxisTriggers.
*/
protected boolean joystickEventsEnabled = false;
/**
* If true MouseEvents are generated from TouchEvents
*/
protected boolean mouseEventsEnabled = true;
/**
* Flip X axis
*/
protected boolean mouseEventsInvertX = false;
/**
* Flip Y axis
*/
protected boolean mouseEventsInvertY = false;
/**
* if true finish this activity when the jme app is stopped
*/
protected boolean finishOnAppStop = true;
/**
* set to false if you don't want the harness to handle the exit hook
*/
protected boolean handleExitHook = true;
/**
* Title of the exit dialog, default is "Do you want to exit?"
*/
protected String exitDialogTitle = "Do you want to exit?";
/**
* Message of the exit dialog, default is "Use your home key to bring this
* app into the background or exit to terminate it."
*/
protected String exitDialogMessage = "Use your home key to bring this app into the background or exit to terminate it.";
/**
* Set the screen window mode. If screenFullSize is true, then the
* notification bar and title bar are removed and the screen covers the
@ -116,20 +112,17 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt
* false, then the title bar is also displayed under the notification bar.
*/
protected boolean screenFullScreen = true;
/**
* if screenShowTitle is true while screenFullScreen is false, then the
* title bar is also displayed under the notification bar
*/
protected boolean screenShowTitle = true;
/**
* Splash Screen picture Resource ID. If a Splash Screen is desired, set
* splashPicID to the value of the Resource ID (i.e. R.drawable.picname). If
* splashPicID = 0, then no splash screen will be displayed.
*/
protected int splashPicID = 0;
/**
* Set the screen orientation, default is SENSOR
* ActivityInfo.SCREEN_ORIENTATION_* constants package
@ -200,7 +193,10 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt
settings.setEmulateMouse(mouseEventsEnabled);
settings.setEmulateMouseFlipAxis(mouseEventsInvertX, mouseEventsInvertY);
settings.setUseJoysticks(joystickEventsEnabled);
// settings.setSamples(antiAliasingSamples);
settings.setResolution(disp.getWidth(), disp.getHeight());
settings.put(AndroidConfigChooser.SETTINGS_CONFIG_TYPE, eglConfigType);
// Create application instance
try {
@ -221,7 +217,7 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt
}
ctx = (OGLESContext) app.getContext();
view = ctx.createView(eglConfigType, eglConfigVerboseLogging);
view = ctx.createView();
// AndroidHarness wraps the app as a SystemListener.
ctx.setSystemListener(this);
layoutDisplay();
@ -401,7 +397,6 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt
switch (evt.getType()) {
case KEY_UP:
runOnUiThread(new Runnable() {
@Override
public void run() {
AlertDialog dialog = new AlertDialog.Builder(AndroidHarness.this) // .setIcon(R.drawable.alert_dialog_icon)
@ -438,12 +433,12 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt
}
if (view.getParent() != null) {
((ViewGroup)view.getParent()).removeView(view);
((ViewGroup) view.getParent()).removeView(view);
}
frameLayout.addView(view);
if (splashImageView.getParent() != null) {
((ViewGroup)splashImageView.getParent()).removeView(splashImageView);
((ViewGroup) splashImageView.getParent()).removeView(splashImageView);
}
frameLayout.addView(splashImageView, lp);
@ -461,7 +456,6 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt
if (frameLayout != null) {
if (splashImageView != null) {
this.runOnUiThread(new Runnable() {
@Override
public void run() {
splashImageView.setVisibility(View.INVISIBLE);

@ -2,6 +2,8 @@ package com.jme3.system.android;
import android.graphics.PixelFormat;
import android.opengl.GLSurfaceView.EGLConfigChooser;
import com.jme3.system.AppSettings;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGLConfig;
@ -15,11 +17,12 @@ import javax.microedition.khronos.egl.EGLDisplay;
public class AndroidConfigChooser implements EGLConfigChooser {
private static final Logger logger = Logger.getLogger(AndroidConfigChooser.class.getName());
public final static String SETTINGS_CONFIG_TYPE = "configType";
protected int clientOpenGLESVersion = 0;
protected EGLConfig bestConfig = null;
protected EGLConfig fastestConfig = null;
protected EGLConfig choosenConfig = null;
protected ConfigType type;
protected AppSettings settings;
protected int pixelFormat;
protected boolean verbose = false;
private final static int EGL_OPENGL_ES2_BIT = 4;
@ -29,24 +32,59 @@ public class AndroidConfigChooser implements EGLConfigChooser {
/**
* RGB565, 0 alpha, 16 depth, 0 stencil
*/
FASTEST,
FASTEST(5, 6, 5, 0, 16, 0, 5, 6, 5, 0, 16, 0),
/**
* RGB???, 0 alpha, >=16 depth, 0 stencil
*/
BEST,
BEST(8, 8, 8, 0, 32, 0, 8, 8, 8, 0, 16, 0),
/**
* Turn off config chooser and use hardcoded
* setEGLContextClientVersion(2); setEGLConfigChooser(5, 6, 5, 0, 16,
* 0);
*/
LEGACY,
LEGACY(5, 6, 5, 0, 16, 0, 5, 6, 5, 0, 16, 0),
/**
* RGB???, 8 alpha, >=16 depth, 0 stencil
*/
BEST_TRANSLUCENT,}
BEST_TRANSLUCENT(8, 8, 8, 8, 32, 0, 8, 8, 8, 8, 16, 0);
/**
* red, green, blue, alpha, depth, stencil
*/
int r, g, b, a, d, s;
/**
* fallback
*/
int fbr, fbg, fbb, fba, fbd, fbs;
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;
this.g = g;
this.b = b;
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;
}
}
/**
*
* @param type
* @deprecated use AndroidConfigChooser(AppSettings settings)
*/
@Deprecated
public AndroidConfigChooser(ConfigType type) {
this.type = type;
this.settings = new AppSettings(true);
settings.put(SETTINGS_CONFIG_TYPE, type);
}
public AndroidConfigChooser(AppSettings settings) {
this.settings = settings;
}
/**
@ -67,33 +105,41 @@ public class AndroidConfigChooser implements EGLConfigChooser {
* @return true if successfull, false if no config was found
*/
public boolean findConfig(EGL10 egl, EGLDisplay display) {
ComponentSizeChooser compChooser = null;
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);
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);
choosenConfig = compChooser.chooseConfig(egl, display);
if (choosenConfig == null) {
compChooser = new ComponentSizeChooser(8, 8, 8, 8, 16, 0);
compChooser = new ComponentSizeChooser(type.fbr, type.fbg, type.fbb, type.fba, type.fbd, type.fbs);
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;
}
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: ");
@ -173,6 +219,12 @@ public class AndroidConfigChooser implements EGLConfigChooser {
egl.eglGetConfigAttrib(display, conf, EGL10.EGL_SURFACE_TYPE, value);
logger.fine(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]));
egl.eglGetConfigAttrib(display, conf, EGL10.EGL_SAMPLES, value);
logger.fine(String.format("EGL_SAMPLES = %d", value[0]));
}
public int getClientOpenGLESVersion() {
@ -277,6 +329,9 @@ public class AndroidConfigChooser implements EGLConfigChooser {
protected int mAlphaSize;
protected int mDepthSize;
protected int mStencilSize;
protected int mRenderableType;
protected int mSampleBuffers;
protected int mSamples;
public ComponentSizeChooser(int redSize, int greenSize, int blueSize,
int alphaSize, int depthSize, int stencilSize) {
@ -297,6 +352,31 @@ public class AndroidConfigChooser implements EGLConfigChooser {
mStencilSize = stencilSize;
}
public ComponentSizeChooser(int redSize, int greenSize, int blueSize,
int alphaSize, int depthSize, int stencilSize, int renderableType, int sampleBuffers, int samples) {
super(new int[]{
EGL10.EGL_RED_SIZE, redSize,
EGL10.EGL_GREEN_SIZE, greenSize,
EGL10.EGL_BLUE_SIZE, blueSize,
EGL10.EGL_ALPHA_SIZE, alphaSize,
EGL10.EGL_DEPTH_SIZE, depthSize,
EGL10.EGL_STENCIL_SIZE, stencilSize,
EGL10.EGL_RENDERABLE_TYPE, renderableType,
EGL10.EGL_SAMPLE_BUFFERS, sampleBuffers,
EGL10.EGL_SAMPLES, samples,
EGL10.EGL_NONE});
mValue = new int[1];
mRedSize = redSize;
mGreenSize = greenSize;
mBlueSize = blueSize;
mAlphaSize = alphaSize;
mDepthSize = depthSize;
mStencilSize = stencilSize;
mRenderableType = renderableType;
mSampleBuffers = sampleBuffers;
mSamples = samples;
}
@Override
public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display, EGLConfig[] configs) {
@ -315,11 +395,9 @@ public class AndroidConfigChooser implements EGLConfigChooser {
int s = findConfigAttrib(egl, display, config,
EGL10.EGL_STENCIL_SIZE, 0);
if ((
r == mRedSize) && (g == mGreenSize)
if ((r == mRedSize) && (g == mGreenSize)
&& (b == mBlueSize) && (a == mAlphaSize)
&& (d == mDepthSize) && (s == mStencilSize)
) {
&& (d == mDepthSize) && (s == mStencilSize)) {
return config;
}
}

@ -66,7 +66,7 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer, SoftTex
protected final AtomicBoolean created = new AtomicBoolean(false);
protected final AtomicBoolean renderable = new AtomicBoolean(false);
protected final AtomicBoolean needClose = new AtomicBoolean(false);
protected final AppSettings settings = new AppSettings(true);
protected AppSettings settings = new AppSettings(true);
/*
* >= OpenGL ES 2.0 (Android 2.2+)
@ -93,22 +93,39 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer, SoftTex
}
/**
* <code>createView</code> creates the GLSurfaceView that the
* renderer will draw to.
* <p>
* The result GLSurfaceView will receive input events and forward
* them to the Application. Any rendering will be done into
* the GLSurfaceView. Only one GLSurfaceView can be created at this time.
* The given configType specifies how to determine the display configuration.
* <code>createView</code> creates the GLSurfaceView that the renderer will
* draw to. <p> The result GLSurfaceView will receive input events and
* forward them to the Application. Any rendering will be done into the
* GLSurfaceView. Only one GLSurfaceView can be created at this time. The
* given configType specifies how to determine the display configuration.
*
*
* @param configType ConfigType.FASTEST (Default) | ConfigType.LEGACY |
* ConfigType.BEST
* @param eglConfigVerboseLogging if true show all found configs
* @return GLSurfaceView The newly created view
* @deprecated AndroidGLSurfaceView createView()
* and put the configType in the appSettigs with the key AndroidConfigChoose.SETTINGS_CONFIG_TYPE
*/
@Deprecated
public AndroidGLSurfaceView createView(ConfigType configType, boolean eglConfigVerboseLogging) {
settings.put(AndroidConfigChooser.SETTINGS_CONFIG_TYPE, configType);
return this.createView();
}
/**
* <code>createView</code> creates the GLSurfaceView that the renderer will
* draw to. <p> The result GLSurfaceView will receive input events and
* forward them to the Application. Any rendering will be done into the
* GLSurfaceView. Only one GLSurfaceView can be created at this time. The
* given configType specifies how to determine the display configuration.
*
*
* @param eglConfigVerboseLogging if true show all found configs
* @return GLSurfaceView The newly created view
*/
public AndroidGLSurfaceView createView() {
AndroidGLSurfaceView view;
ConfigType configType = (ConfigType)settings.get(AndroidConfigChooser.SETTINGS_CONFIG_TYPE);
// Start to set up the view
view = new AndroidGLSurfaceView(JmeAndroidSystem.getActivity().getApplication());
@ -136,7 +153,7 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer, SoftTex
try {
// Create a config chooser
AndroidConfigChooser configChooser = new AndroidConfigChooser(configType);
AndroidConfigChooser configChooser = new AndroidConfigChooser(settings);
// Init chooser
if (!configChooser.findConfig(egl, display)) {
listener.handleError("Unable to find suitable EGL config", null);
@ -196,7 +213,6 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer, SoftTex
// Setup unhandled Exception Handler
Thread.currentThread().setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
public void uncaughtException(Thread thread, Throwable thrown) {
listener.handleError("Exception thrown in " + thread.toString(), thrown);
}
@ -399,7 +415,6 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer, SoftTex
final Activity activity = JmeAndroidSystem.getActivity();
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
@ -436,7 +451,6 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer, SoftTex
AlertDialog dialogTextInput = new AlertDialog.Builder(activity).setTitle(title).setView(layoutTextDialogInput).setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
/* User clicked OK, send COMPLETE action
* and text */
@ -444,7 +458,6 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer, SoftTex
}
}).setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
/* User clicked CANCEL, send CANCEL action
* and text */

Loading…
Cancel
Save