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
This commit is contained in:
parent
8955f719b7
commit
b1792a4e1a
@ -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,80 +134,99 @@ 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)
|
||||||
GLES20.glPixelStorei(GLES20.GL_UNPACK_ALIGNMENT, 1);
|
GLES20.glPixelStorei(GLES20.GL_UNPACK_ALIGNMENT, 1);
|
||||||
|
|
||||||
@ -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,10 +165,9 @@ 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
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
@ -179,10 +178,6 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer
|
|||||||
{
|
{
|
||||||
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
|
||||||
|
|
||||||
|
|
||||||
@ -195,8 +190,10 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer
|
|||||||
*/
|
*/
|
||||||
view.setEGLContextClientVersion(clientOpenGLESVersion);
|
view.setEGLContextClientVersion(clientOpenGLESVersion);
|
||||||
|
|
||||||
//RGB565, Depth16
|
if (bestConfig != null)
|
||||||
//view.setEGLConfigChooser(5, 6, 5, 0, 16, 0);
|
{
|
||||||
|
logger.info("JME3 using best EGL configuration available here: ");
|
||||||
|
logEGLConfig(bestConfig, display, egl);
|
||||||
|
|
||||||
// Choose best config
|
// Choose best config
|
||||||
egl.eglGetConfigAttrib(display, bestConfig, EGL10.EGL_RED_SIZE, value);
|
egl.eglGetConfigAttrib(display, bestConfig, EGL10.EGL_RED_SIZE, value);
|
||||||
@ -218,6 +215,13 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer
|
|||||||
int stencilSize = value[0];
|
int stencilSize = value[0];
|
||||||
|
|
||||||
view.setEGLConfigChooser(redSize, greenSize, blueSize, alphaSize, depthSize, stencilSize);
|
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);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user