From b1792a4e1afc5f07e2ea829cbb6da5ff08571efb Mon Sep 17 00:00:00 2001 From: "kim..ng" Date: Tue, 14 Jun 2011 12:59:56 +0000 Subject: [PATCH] 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 --- .../jme3/renderer/android/TextureUtil.java | 106 +++++++++++------- .../com/jme3/system/android/OGLESContext.java | 70 ++++++------ 2 files changed, 102 insertions(+), 74 deletions(-) diff --git a/engine/src/android/com/jme3/renderer/android/TextureUtil.java b/engine/src/android/com/jme3/renderer/android/TextureUtil.java index ebd1b58c5..672fbc25f 100644 --- a/engine/src/android/com/jme3/renderer/android/TextureUtil.java +++ b/engine/src/android/com/jme3/renderer/android/TextureUtil.java @@ -1,10 +1,6 @@ package com.jme3.renderer.android; - import android.graphics.Bitmap; -import android.opengl.GLES10; -import android.opengl.GLES11; -import android.opengl.GLES11Ext; import android.opengl.GLES20; import android.opengl.GLUtils; import com.jme3.math.FastMath; @@ -12,7 +8,6 @@ import com.jme3.texture.Image; import com.jme3.texture.Image.Format; import java.nio.ByteBuffer; import javax.microedition.khronos.opengles.GL10; -import javax.microedition.khronos.opengles.GL10Ext; public class TextureUtil { @@ -37,6 +32,16 @@ public class TextureUtil { case RGBA16: case RGBA8: 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: throw new UnsupportedOperationException("Unsupported format: " + fmt); default: @@ -129,78 +134,97 @@ public class TextureUtil { int width = img.getWidth(); int height = img.getHeight(); -// int depth = img.getDepth(); + int depth = img.getDepth(); boolean compress = false; + int internalFormat = -1; int format = -1; int dataType = -1; switch (fmt){ case Alpha16: - format = GL10.GL_ALPHA; - dataType = GL10.GL_UNSIGNED_BYTE; - break; case Alpha8: - format = GL10.GL_ALPHA; - dataType = GL10.GL_UNSIGNED_BYTE; + format = GLES20.GL_ALPHA; + dataType = GLES20.GL_UNSIGNED_BYTE; break; case Luminance8: - format = GL10.GL_LUMINANCE; - dataType = GL10.GL_UNSIGNED_BYTE; + format = GLES20.GL_LUMINANCE; + dataType = GLES20.GL_UNSIGNED_BYTE; break; case Luminance8Alpha8: - format = GL10.GL_LUMINANCE_ALPHA; - dataType = GL10.GL_UNSIGNED_BYTE; + format = GLES20.GL_LUMINANCE_ALPHA; + dataType = GLES20.GL_UNSIGNED_BYTE; break; case Luminance16Alpha16: - format = GL10.GL_LUMINANCE_ALPHA; - dataType = GL10.GL_UNSIGNED_BYTE; + format = GLES20.GL_LUMINANCE_ALPHA; + dataType = GLES20.GL_UNSIGNED_BYTE; break; case Luminance16: - format = GL10.GL_LUMINANCE; - dataType = GL10.GL_UNSIGNED_BYTE; + format = GLES20.GL_LUMINANCE; + dataType = GLES20.GL_UNSIGNED_BYTE; break; case RGB565: - format = GL10.GL_RGB; - dataType = GL10.GL_UNSIGNED_SHORT_5_6_5; + format = GLES20.GL_RGB; + internalFormat = GLES20.GL_RGB565; + dataType = GLES20.GL_UNSIGNED_SHORT_5_6_5; break; case ARGB4444: - format = GL10.GL_RGBA; - dataType = GL10.GL_UNSIGNED_SHORT_4_4_4_4; + format = GLES20.GL_RGBA; + dataType = GLES20.GL_UNSIGNED_SHORT_4_4_4_4; break; case RGB10: - format = GL10.GL_RGB; - dataType = GL10.GL_UNSIGNED_BYTE; + format = GLES20.GL_RGB; + dataType = GLES20.GL_UNSIGNED_BYTE; break; case RGB16: - format = GL10.GL_RGB; - dataType = GL10.GL_UNSIGNED_BYTE; + format = GLES20.GL_RGB; + dataType = GLES20.GL_UNSIGNED_BYTE; break; case RGB5A1: - format = GL10.GL_RGBA; - dataType = GL10.GL_UNSIGNED_SHORT_5_5_5_1; + format = GLES20.GL_RGBA; + internalFormat = GLES20.GL_RGB5_A1; + dataType = GLES20.GL_UNSIGNED_SHORT_5_5_5_1; break; case RGB8: - format = GL10.GL_RGB; - dataType = GL10.GL_UNSIGNED_BYTE; + format = GLES20.GL_RGB; + dataType = GLES20.GL_UNSIGNED_BYTE; break; case BGR8: - format = GL10.GL_RGB; - dataType = GL10.GL_UNSIGNED_BYTE; + format = GLES20.GL_RGB; + dataType = GLES20.GL_UNSIGNED_BYTE; break; case RGBA16: - format = GL10.GL_RGBA; - dataType = GL10.GL_UNSIGNED_BYTE; + format = GLES20.GL_RGBA; + internalFormat = GLES20.GL_RGBA4; + dataType = GLES20.GL_UNSIGNED_BYTE; break; case RGBA8: - format = GL10.GL_RGBA; - dataType = GL10.GL_UNSIGNED_BYTE; + format = GLES20.GL_RGBA; + dataType = GLES20.GL_UNSIGNED_BYTE; break; case DXT1A: 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: - throw new UnsupportedOperationException("Unrecognized format: "+fmt); + throw new UnsupportedOperationException("Unrecognized format: " + fmt); + } + + if (internalFormat == -1) + { + internalFormat = format; } if (data != null) @@ -233,7 +257,7 @@ public class TextureUtil { for (int i = 0; i < mipSizes.length; i++){ int mipWidth = Math.max(1, width >> 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){ data.position(pos); @@ -252,7 +276,7 @@ public class TextureUtil { }else{ GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, i, - format, + internalFormat, mipWidth, mipHeight, 0, diff --git a/engine/src/android/com/jme3/system/android/OGLESContext.java b/engine/src/android/com/jme3/system/android/OGLESContext.java index 88a0e3f5c..a762a90c0 100644 --- a/engine/src/android/com/jme3/system/android/OGLESContext.java +++ b/engine/src/android/com/jme3/system/android/OGLESContext.java @@ -165,9 +165,8 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer if ((value[0] & EGL_OPENGL_ES2_BIT) != 0) { clientOpenGLESVersion = 2; // OpenGL ES 2.0 detected - } - - bestConfig = better(bestConfig, conf[i], egl, display); + bestConfig = better(bestConfig, conf[i], egl, display); + } } else { @@ -178,11 +177,7 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer if (clientOpenGLESVersion < 2) { 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 @@ -193,32 +188,41 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer * Requesting client version from GLSurfaceView which is extended by * AndroidInput. */ - 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]; + view.setEGLContextClientVersion(clientOpenGLESVersion); - 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); - + if (bestConfig != null) + { + logger.info("JME3 using best EGL configuration available here: "); + logEGLConfig(bestConfig, display, egl); + + // 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); + 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.setFocusable(true); view.getHolder().setType(SurfaceHolder.SURFACE_TYPE_GPU);