Android : changed the way the glsurface's pixel format was chosen, allowing the surface to have a translucent background

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9507 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
rem..om 13 years ago
parent ca3f1d941a
commit 67712589e2
  1. 35
      engine/src/android/com/jme3/system/android/AndroidConfigChooser.java
  2. 6
      engine/src/android/com/jme3/system/android/OGLESContext.java

@ -31,12 +31,10 @@ public class AndroidConfigChooser implements EGLConfigChooser {
* RGB565, 0 alpha, 16 depth, 0 stencil * RGB565, 0 alpha, 16 depth, 0 stencil
*/ */
FASTEST, FASTEST,
/** /**
* RGB???, 0 alpha, >=16 depth, 0 stencil * RGB???, 0 alpha, >=16 depth, 0 stencil
*/ */
BEST, BEST,
/** /**
* Turn off config chooser and use hardcoded * Turn off config chooser and use hardcoded
* setEGLContextClientVersion(2); setEGLConfigChooser(5, 6, 5, 0, 16, * setEGLContextClientVersion(2); setEGLConfigChooser(5, 6, 5, 0, 16,
@ -106,29 +104,20 @@ public class AndroidConfigChooser implements EGLConfigChooser {
private int getPixelFormat(EGLConfig conf, EGLDisplay display, EGL10 egl) { private int getPixelFormat(EGLConfig conf, EGLDisplay display, EGL10 egl) {
int[] value = new int[1]; int[] value = new int[1];
int result = PixelFormat.RGB_565;
//Android Pixel format is not very well documented.
egl.eglGetConfigAttrib(display, conf, EGL10.EGL_RED_SIZE, value); //From what i gathered, the format is chosen automatically except for the alpha channel
if (value[0] == 8) { //if the alpha channel has 8 bit or more, e set the pixel format to Transluscent, as it allow transparent view background
result = PixelFormat.RGBA_8888; //if it's 0 bit, the format is OPAQUE otherwise it's TRANSPARENT
/* egl.eglGetConfigAttrib(display, conf, EGL10.EGL_ALPHA_SIZE, value);
egl.eglGetConfigAttrib(display, conf, EGL10.EGL_ALPHA_SIZE, value); if (value[0] >= 8) {
if (value[0] == 8) return PixelFormat.TRANSLUCENT;
{
result = PixelFormat.RGBA_8888;
}
else
{
result = PixelFormat.RGB_888;
}*/
} }
if (value[0] >= 1) {
if (verbose) { return PixelFormat.TRANSPARENT;
logger.log(Level.INFO, "Using PixelFormat {0}", result);
} }
//return result; TODO Test pixelformat return PixelFormat.OPAQUE;
return PixelFormat.TRANSPARENT;
} }
private int getOpenGLVersion(EGLConfig conf, EGLDisplay display, EGL10 egl) { private int getOpenGLVersion(EGLConfig conf, EGLDisplay display, EGL10 egl) {
@ -268,7 +257,7 @@ public class AndroidConfigChooser implements EGLConfigChooser {
protected int mAlphaSize; protected int mAlphaSize;
protected int mDepthSize; protected int mDepthSize;
protected int mStencilSize; protected int mStencilSize;
public ComponentSizeChooser(int redSize, int greenSize, int blueSize, public ComponentSizeChooser(int redSize, int greenSize, int blueSize,
int alphaSize, int depthSize, int stencilSize) { int alphaSize, int depthSize, int stencilSize) {
super(new int[]{ super(new int[]{

@ -33,6 +33,7 @@ package com.jme3.system.android;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.graphics.PixelFormat;
import android.opengl.GLSurfaceView; import android.opengl.GLSurfaceView;
import android.text.InputType; import android.text.InputType;
import android.view.Gravity; import android.view.Gravity;
@ -104,6 +105,7 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer, SoftTex
* @return GLSurfaceView The newly created view * @return GLSurfaceView The newly created view
*/ */
public GLSurfaceView createView(ConfigType configType, boolean eglConfigVerboseLogging) { public GLSurfaceView createView(ConfigType configType, boolean eglConfigVerboseLogging) {
// Start to set up the view // Start to set up the view
this.view = new AndroidInput(JmeAndroidSystem.getActivity()); this.view = new AndroidInput(JmeAndroidSystem.getActivity());
if (configType == ConfigType.LEGACY) { if (configType == ConfigType.LEGACY) {
@ -152,8 +154,10 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer, SoftTex
view.setFocusableInTouchMode(true); view.setFocusableInTouchMode(true);
view.setFocusable(true); view.setFocusable(true);
view.getHolder().setType(SurfaceHolder.SURFACE_TYPE_GPU); view.getHolder().setType(SurfaceHolder.SURFACE_TYPE_GPU);
//This is important to allow the GL surface to have a translucent background
view.setZOrderOnTop(true);
view.setRenderer(this); view.setRenderer(this);
return view; return view;
} }

Loading…
Cancel
Save