mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2026-04-22 15:57:15 +08:00
@@ -21,13 +21,53 @@ import android.os.Looper;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
|
||||
import javax.microedition.khronos.egl.EGL10;
|
||||
import javax.microedition.khronos.egl.EGLConfig;
|
||||
import javax.microedition.khronos.egl.EGLDisplay;
|
||||
import javax.microedition.khronos.opengles.GL10;
|
||||
|
||||
import $Placeholder_JavaPkg$.ebitenmobileview.Ebitenmobileview;
|
||||
import $Placeholder_JavaPkg$.ebitenmobileview.Renderer;
|
||||
import $Placeholder_JavaPkg$.$Placeholder_PrefixLower$.EbitenView;
|
||||
|
||||
class ConfigChooserWithFallback implements GLSurfaceView.EGLConfigChooser {
|
||||
// EGL_OPENGL_ES2_BIT is defined in EGL14, but not in EGL10.
|
||||
private static final int EGL_OPENGL_ES2_BIT = 4;
|
||||
|
||||
@Override
|
||||
public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) {
|
||||
int[] attribs = {
|
||||
EGL10.EGL_RED_SIZE, 8,
|
||||
EGL10.EGL_GREEN_SIZE, 8,
|
||||
EGL10.EGL_BLUE_SIZE, 8,
|
||||
EGL10.EGL_ALPHA_SIZE, 8,
|
||||
EGL10.EGL_DEPTH_SIZE, 0,
|
||||
EGL10.EGL_STENCIL_SIZE, 0,
|
||||
EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, // often compatible with ES3.
|
||||
EGL10.EGL_NONE
|
||||
};
|
||||
EGLConfig[] configs = new EGLConfig[1];
|
||||
int[] numConfig = new int[1];
|
||||
if (egl.eglChooseConfig(display, attribs, configs, 1, numConfig) && numConfig[0] > 0) {
|
||||
return configs[0];
|
||||
}
|
||||
|
||||
// Try the fallback config.
|
||||
attribs = new int[] {
|
||||
EGL10.EGL_RED_SIZE, 5,
|
||||
EGL10.EGL_GREEN_SIZE, 6,
|
||||
EGL10.EGL_BLUE_SIZE, 5,
|
||||
EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
||||
EGL10.EGL_NONE
|
||||
};
|
||||
if (egl.eglChooseConfig(display, attribs, configs, 1, numConfig) && numConfig[0] > 0) {
|
||||
return configs[0];
|
||||
}
|
||||
|
||||
throw new IllegalStateException("No suitable EGLConfig found; RGB8888 and RGB565 formats are not supported");
|
||||
}
|
||||
}
|
||||
|
||||
class EbitenSurfaceView extends GLSurfaceView implements Renderer {
|
||||
// As GLSurfaceView can be recreated, the states must be static (#3097).
|
||||
static private boolean errored_ = false;
|
||||
@@ -83,7 +123,7 @@ class EbitenSurfaceView extends GLSurfaceView implements Renderer {
|
||||
|
||||
private void initialize() {
|
||||
setEGLContextClientVersion(3);
|
||||
setEGLConfigChooser(8, 8, 8, 8, 0, 0);
|
||||
setEGLConfigChooser(new ConfigChooserWithFallback());
|
||||
setPreserveEGLContextOnPause(true);
|
||||
// setRenderer must be called before Ebitenmobileview.setRenderer.
|
||||
// Otherwise, setRenderMode in setExplicitRenderingMode will crash.
|
||||
|
||||
Reference in New Issue
Block a user