Android: Added depth textures and fixed best config chooser not to choose a high color, but OpenGL ES 1.0 config

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7624 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
kim..ng 14 years ago
parent 8955f719b7
commit b1792a4e1a
  1. 106
      engine/src/android/com/jme3/renderer/android/TextureUtil.java
  2. 70
      engine/src/android/com/jme3/system/android/OGLESContext.java

@ -1,10 +1,6 @@
package com.jme3.renderer.android; package com.jme3.renderer.android;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.opengl.GLES10;
import android.opengl.GLES11;
import android.opengl.GLES11Ext;
import android.opengl.GLES20; import android.opengl.GLES20;
import android.opengl.GLUtils; import android.opengl.GLUtils;
import com.jme3.math.FastMath; import com.jme3.math.FastMath;
@ -12,7 +8,6 @@ import com.jme3.texture.Image;
import com.jme3.texture.Image.Format; import com.jme3.texture.Image.Format;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import javax.microedition.khronos.opengles.GL10; import javax.microedition.khronos.opengles.GL10;
import javax.microedition.khronos.opengles.GL10Ext;
public class TextureUtil { public class TextureUtil {
@ -37,6 +32,16 @@ public class TextureUtil {
case RGBA16: case RGBA16:
case RGBA8: case RGBA8:
return GL10.GL_RGBA; return GL10.GL_RGBA;
case Depth:
return GLES20.GL_DEPTH_COMPONENT;
case Depth16:
return GLES20.GL_DEPTH_COMPONENT16;
case Depth24:
case Depth32:
case Depth32F:
throw new UnsupportedOperationException("Unsupported depth format: " + fmt);
case DXT1A: case DXT1A:
throw new UnsupportedOperationException("Unsupported format: " + fmt); throw new UnsupportedOperationException("Unsupported format: " + fmt);
default: default:
@ -129,78 +134,97 @@ public class TextureUtil {
int width = img.getWidth(); int width = img.getWidth();
int height = img.getHeight(); int height = img.getHeight();
// int depth = img.getDepth(); int depth = img.getDepth();
boolean compress = false; boolean compress = false;
int internalFormat = -1;
int format = -1; int format = -1;
int dataType = -1; int dataType = -1;
switch (fmt){ switch (fmt){
case Alpha16: case Alpha16:
format = GL10.GL_ALPHA;
dataType = GL10.GL_UNSIGNED_BYTE;
break;
case Alpha8: case Alpha8:
format = GL10.GL_ALPHA; format = GLES20.GL_ALPHA;
dataType = GL10.GL_UNSIGNED_BYTE; dataType = GLES20.GL_UNSIGNED_BYTE;
break; break;
case Luminance8: case Luminance8:
format = GL10.GL_LUMINANCE; format = GLES20.GL_LUMINANCE;
dataType = GL10.GL_UNSIGNED_BYTE; dataType = GLES20.GL_UNSIGNED_BYTE;
break; break;
case Luminance8Alpha8: case Luminance8Alpha8:
format = GL10.GL_LUMINANCE_ALPHA; format = GLES20.GL_LUMINANCE_ALPHA;
dataType = GL10.GL_UNSIGNED_BYTE; dataType = GLES20.GL_UNSIGNED_BYTE;
break; break;
case Luminance16Alpha16: case Luminance16Alpha16:
format = GL10.GL_LUMINANCE_ALPHA; format = GLES20.GL_LUMINANCE_ALPHA;
dataType = GL10.GL_UNSIGNED_BYTE; dataType = GLES20.GL_UNSIGNED_BYTE;
break; break;
case Luminance16: case Luminance16:
format = GL10.GL_LUMINANCE; format = GLES20.GL_LUMINANCE;
dataType = GL10.GL_UNSIGNED_BYTE; dataType = GLES20.GL_UNSIGNED_BYTE;
break; break;
case RGB565: case RGB565:
format = GL10.GL_RGB; format = GLES20.GL_RGB;
dataType = GL10.GL_UNSIGNED_SHORT_5_6_5; internalFormat = GLES20.GL_RGB565;
dataType = GLES20.GL_UNSIGNED_SHORT_5_6_5;
break; break;
case ARGB4444: case ARGB4444:
format = GL10.GL_RGBA; format = GLES20.GL_RGBA;
dataType = GL10.GL_UNSIGNED_SHORT_4_4_4_4; dataType = GLES20.GL_UNSIGNED_SHORT_4_4_4_4;
break; break;
case RGB10: case RGB10:
format = GL10.GL_RGB; format = GLES20.GL_RGB;
dataType = GL10.GL_UNSIGNED_BYTE; dataType = GLES20.GL_UNSIGNED_BYTE;
break; break;
case RGB16: case RGB16:
format = GL10.GL_RGB; format = GLES20.GL_RGB;
dataType = GL10.GL_UNSIGNED_BYTE; dataType = GLES20.GL_UNSIGNED_BYTE;
break; break;
case RGB5A1: case RGB5A1:
format = GL10.GL_RGBA; format = GLES20.GL_RGBA;
dataType = GL10.GL_UNSIGNED_SHORT_5_5_5_1; internalFormat = GLES20.GL_RGB5_A1;
dataType = GLES20.GL_UNSIGNED_SHORT_5_5_5_1;
break; break;
case RGB8: case RGB8:
format = GL10.GL_RGB; format = GLES20.GL_RGB;
dataType = GL10.GL_UNSIGNED_BYTE; dataType = GLES20.GL_UNSIGNED_BYTE;
break; break;
case BGR8: case BGR8:
format = GL10.GL_RGB; format = GLES20.GL_RGB;
dataType = GL10.GL_UNSIGNED_BYTE; dataType = GLES20.GL_UNSIGNED_BYTE;
break; break;
case RGBA16: case RGBA16:
format = GL10.GL_RGBA; format = GLES20.GL_RGBA;
dataType = GL10.GL_UNSIGNED_BYTE; internalFormat = GLES20.GL_RGBA4;
dataType = GLES20.GL_UNSIGNED_BYTE;
break; break;
case RGBA8: case RGBA8:
format = GL10.GL_RGBA; format = GLES20.GL_RGBA;
dataType = GL10.GL_UNSIGNED_BYTE; dataType = GLES20.GL_UNSIGNED_BYTE;
break; break;
case DXT1A: case DXT1A:
format = GLES20.GL_COMPRESSED_TEXTURE_FORMATS; format = GLES20.GL_COMPRESSED_TEXTURE_FORMATS;
dataType = GL10.GL_UNSIGNED_BYTE; dataType = GLES20.GL_UNSIGNED_BYTE;
case Depth:
format = GLES20.GL_DEPTH_COMPONENT;
dataType = GLES20.GL_UNSIGNED_BYTE;
break;
case Depth16:
format = GLES20.GL_DEPTH_COMPONENT;
internalFormat = GLES20.GL_DEPTH_COMPONENT16;
dataType = GLES20.GL_UNSIGNED_BYTE;
break;
case Depth24:
case Depth32:
case Depth32F:
throw new UnsupportedOperationException("Unsupported depth format: " + fmt);
default: default:
throw new UnsupportedOperationException("Unrecognized format: "+fmt); throw new UnsupportedOperationException("Unrecognized format: " + fmt);
}
if (internalFormat == -1)
{
internalFormat = format;
} }
if (data != null) if (data != null)
@ -233,7 +257,7 @@ public class TextureUtil {
for (int i = 0; i < mipSizes.length; i++){ for (int i = 0; i < mipSizes.length; i++){
int mipWidth = Math.max(1, width >> i); int mipWidth = Math.max(1, width >> i);
int mipHeight = Math.max(1, height >> i); int mipHeight = Math.max(1, height >> i);
// int mipDepth = Math.max(1, depth >> i); int mipDepth = Math.max(1, depth >> i);
if (data != null){ if (data != null){
data.position(pos); data.position(pos);
@ -252,7 +276,7 @@ public class TextureUtil {
}else{ }else{
GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D,
i, i,
format, internalFormat,
mipWidth, mipWidth,
mipHeight, mipHeight,
0, 0,

@ -165,9 +165,8 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer
if ((value[0] & EGL_OPENGL_ES2_BIT) != 0) if ((value[0] & EGL_OPENGL_ES2_BIT) != 0)
{ {
clientOpenGLESVersion = 2; // OpenGL ES 2.0 detected clientOpenGLESVersion = 2; // OpenGL ES 2.0 detected
} bestConfig = better(bestConfig, conf[i], egl, display);
}
bestConfig = better(bestConfig, conf[i], egl, display);
} }
else else
{ {
@ -178,11 +177,7 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer
if (clientOpenGLESVersion < 2) if (clientOpenGLESVersion < 2)
{ {
logger.severe("OpenGL ES 2.0 is not supported on this device"); logger.severe("OpenGL ES 2.0 is not supported on this device");
} }
logger.info("JME3 using best EGL configuration available here: ");
logEGLConfig(bestConfig, display, egl);
// Finished querying the configs // Finished querying the configs
@ -193,32 +188,41 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer
* Requesting client version from GLSurfaceView which is extended by * Requesting client version from GLSurfaceView which is extended by
* AndroidInput. * AndroidInput.
*/ */
view.setEGLContextClientVersion(clientOpenGLESVersion); view.setEGLContextClientVersion(clientOpenGLESVersion);
//RGB565, Depth16
//view.setEGLConfigChooser(5, 6, 5, 0, 16, 0);
// Choose best config
egl.eglGetConfigAttrib(display, bestConfig, EGL10.EGL_RED_SIZE, value);
int redSize = value[0];
egl.eglGetConfigAttrib(display, bestConfig, EGL10.EGL_GREEN_SIZE, value);
int greenSize = value[0];
egl.eglGetConfigAttrib(display, bestConfig, EGL10.EGL_BLUE_SIZE, value);
int blueSize = value[0];
egl.eglGetConfigAttrib(display, bestConfig, EGL10.EGL_ALPHA_SIZE, value); if (bestConfig != null)
int alphaSize = value[0]; {
logger.info("JME3 using best EGL configuration available here: ");
egl.eglGetConfigAttrib(display, bestConfig, EGL10.EGL_DEPTH_SIZE, value); logEGLConfig(bestConfig, display, egl);
int depthSize = value[0];
// Choose best config
egl.eglGetConfigAttrib(display, bestConfig, EGL10.EGL_STENCIL_SIZE, value); egl.eglGetConfigAttrib(display, bestConfig, EGL10.EGL_RED_SIZE, value);
int stencilSize = value[0]; int redSize = value[0];
view.setEGLConfigChooser(redSize, greenSize, blueSize, alphaSize, depthSize, stencilSize); egl.eglGetConfigAttrib(display, bestConfig, EGL10.EGL_GREEN_SIZE, value);
int greenSize = value[0];
egl.eglGetConfigAttrib(display, bestConfig, EGL10.EGL_BLUE_SIZE, value);
int blueSize = value[0];
egl.eglGetConfigAttrib(display, bestConfig, EGL10.EGL_ALPHA_SIZE, value);
int alphaSize = value[0];
egl.eglGetConfigAttrib(display, bestConfig, EGL10.EGL_DEPTH_SIZE, value);
int depthSize = value[0];
egl.eglGetConfigAttrib(display, bestConfig, EGL10.EGL_STENCIL_SIZE, value);
int stencilSize = value[0];
view.setEGLConfigChooser(redSize, greenSize, blueSize, alphaSize, depthSize, stencilSize);
}
else
{
//RGB565, Depth16
logger.info("JME3 best EGL configuration not found using default: RGB565, Depth16, Alpha0, Stencil0");
view.setEGLConfigChooser(5, 6, 5, 0, 16, 0);
}
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);

Loading…
Cancel
Save