If you think the Android project FxCameraApp listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.af.experiments.FxCameraApp.ogles;
//www.java2s.comimport android.opengl.GLSurfaceView;
import android.os.Build;
import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.egl.EGLDisplay;
importstatic javax.microedition.khronos.egl.EGL10.*;
publicclass DefaultConfigChooser implements GLSurfaceView.EGLConfigChooser {
privatefinalint[] mConfigSpec;
privatefinalint mRedSize;
privatefinalint mGreenSize;
privatefinalint mBlueSize;
privatefinalint mAlphaSize;
privatefinalint mDepthSize;
privatefinalint mStencilSize;
public DefaultConfigChooser(finalint version) {
this(true, version);
}
privatestaticfinalint JELLY_BEAN_MR1 = 17;
privatestaticfinalboolean USE_RGB_888 = Integer.parseInt(Build.VERSION.SDK) >= JELLY_BEAN_MR1;
public DefaultConfigChooser(finalboolean withDepthBuffer, finalint version) {
this(
USE_RGB_888 ? 8 : 5,
USE_RGB_888 ? 8 : 6,
USE_RGB_888 ? 8 : 5,
0,
withDepthBuffer ? 16 : 0,
0,
version
);
}
public DefaultConfigChooser(
finalint redSize,
finalint greenSize,
finalint blueSize,
finalint alphaSize,
finalint depthSize,
finalint stencilSize,
finalint version) {
mConfigSpec = filterConfigSpec(newint[]{
EGL_RED_SIZE, redSize,
EGL_GREEN_SIZE, greenSize,
EGL_BLUE_SIZE, blueSize,
EGL_ALPHA_SIZE, alphaSize,
EGL_DEPTH_SIZE, depthSize,
EGL_STENCIL_SIZE, stencilSize,
EGL_NONE
}, version);
mRedSize = redSize;
mGreenSize = greenSize;
mBlueSize = blueSize;
mAlphaSize = alphaSize;
mDepthSize = depthSize;
mStencilSize = stencilSize;
}
privatestaticfinalint EGL_OPENGL_ES2_BIT = 4;
privateint[] filterConfigSpec(finalint[] configSpec, finalint version) {
if (version != 2) {
return configSpec;
}
/*
* We know none of the subclasses define EGL_RENDERABLE_TYPE.
* And we know the configSpec is well formed.
*/finalint len = configSpec.length;
finalint[] newConfigSpec = newint[len + 2];
System.arraycopy(configSpec, 0, newConfigSpec, 0, len - 1);
newConfigSpec[len - 1] = EGL_RENDERABLE_TYPE;
newConfigSpec[len] = EGL_OPENGL_ES2_BIT;
newConfigSpec[len + 1] = EGL_NONE;
return newConfigSpec;
}
//////////////////////////////////////////////////////////////////////////
@Override
public EGLConfig chooseConfig(final EGL10 egl, final EGLDisplay display) {
// ?????????????????????????????????????????????????
finalint[] num_config = newint[1];
if (!egl.eglChooseConfig(display, mConfigSpec, null, 0, num_config)) {
thrownew IllegalArgumentException("eglChooseConfig failed");
}
finalint config_size = num_config[0];
if (config_size <= 0) {
thrownew IllegalArgumentException("No configs match configSpec");
}
// ?????????????????????
final EGLConfig[] configs = new EGLConfig[config_size];
if (!egl.eglChooseConfig(display, mConfigSpec, configs, config_size, num_config)) {
thrownew IllegalArgumentException("eglChooseConfig#2 failed");
}
final EGLConfig config = chooseConfig(egl, display, configs);
if (config == null) {
thrownew IllegalArgumentException("No config chosen");
}
return config;
}
EGLConfig chooseConfig(final EGL10 egl, final EGLDisplay display, final EGLConfig[] configs) {
for (final EGLConfig config : configs) {
finalint d = findConfigAttrib(egl, display, config, EGL_DEPTH_SIZE, 0);
finalint s = findConfigAttrib(egl, display, config, EGL_STENCIL_SIZE, 0);
if ((d >= mDepthSize) && (s >= mStencilSize)) {
finalint r = findConfigAttrib(egl, display, config, EGL_RED_SIZE, 0);
finalint g = findConfigAttrib(egl, display, config, EGL_GREEN_SIZE, 0);
finalint b = findConfigAttrib(egl, display, config, EGL_BLUE_SIZE, 0);
finalint a = findConfigAttrib(egl, display, config, EGL_ALPHA_SIZE, 0);
if ((r == mRedSize) && (g == mGreenSize) && (b == mBlueSize) && (a == mAlphaSize)) {
return config;
}
}
}
return null;
}
privateint findConfigAttrib(final EGL10 egl, final EGLDisplay display, final EGLConfig config, finalint attribute, finalint defaultValue) {
finalint[] value = newint[1];
if (egl.eglGetConfigAttrib(display, config, attribute, value)) {
return value[0];
}
return defaultValue;
}
}