Android: OpenGL ES 2.0 default for performance / stability

This commit is contained in:
Emux 2019-10-25 10:52:14 +03:00
parent cb0109ba42
commit 644cf9dcb6
No known key found for this signature in database
GPG Key ID: 64ED9980896038C3
2 changed files with 43 additions and 35 deletions

View File

@ -65,9 +65,10 @@ public class MapView extends GLSurfaceView {
private static final Pattern GL_PATTERN = Pattern.compile("OpenGL ES (\\d(\\.\\d){0,2})"); private static final Pattern GL_PATTERN = Pattern.compile("OpenGL ES (\\d(\\.\\d){0,2})");
/** /**
* Target OpenGL ES version, if not available fall back to OpenGL ES 2.0 * OpenGL ES 2.0 default on Android for performance / stability.
* Any larger not available versions fall back to OpenGL ES 2.0.
*/ */
public static double targetGLESVersion = 3.0; public static double OPENGL_VERSION = 2.0;
private static void init() { private static void init() {
if (Parameters.THREADED_INIT) if (Parameters.THREADED_INIT)
@ -133,6 +134,9 @@ public class MapView extends GLSurfaceView {
mMap = new AndroidMap(this); mMap = new AndroidMap(this);
/* Initialize Renderer */ /* Initialize Renderer */
if (OPENGL_VERSION == 2.0)
setEGLContextClientVersion(2);
else {
// OpenGL ES 3.0 is supported with Android 4.3 (API level 18) and higher // OpenGL ES 3.0 is supported with Android 4.3 (API level 18) and higher
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
try { try {
@ -143,6 +147,7 @@ public class MapView extends GLSurfaceView {
} }
} else } else
setEGLContextClientVersion(2); setEGLContextClientVersion(2);
}
setEGLConfigChooser(new GlConfigChooser()); setEGLConfigChooser(new GlConfigChooser());
if (GLAdapter.debug) if (GLAdapter.debug)
@ -354,6 +359,9 @@ public class MapView extends GLSurfaceView {
@Override @Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) { public void onSurfaceCreated(GL10 gl, EGLConfig config) {
if (OPENGL_VERSION == 2.0)
GLAdapter.init(new AndroidGL());
else {
try { try {
// Create a minimum supported OpenGL ES context, then check: // Create a minimum supported OpenGL ES context, then check:
String versionString = gl.glGetString(GL10.GL_VERSION); String versionString = gl.glGetString(GL10.GL_VERSION);
@ -363,7 +371,7 @@ public class MapView extends GLSurfaceView {
// OpenGL<space>ES<space><version number><space><vendor-specific information>. // OpenGL<space>ES<space><version number><space><vendor-specific information>.
int[] version = extractVersion(versionString); int[] version = extractVersion(versionString);
int majorVersion = version[0]; int majorVersion = Math.min(version[0], (int) OPENGL_VERSION);
if (majorVersion >= 3) if (majorVersion >= 3)
GLAdapter.init(new AndroidGL30()); GLAdapter.init(new AndroidGL30());
else else
@ -372,6 +380,7 @@ public class MapView extends GLSurfaceView {
log.error("Falling back to GLES 2", t); log.error("Falling back to GLES 2", t);
GLAdapter.init(new AndroidGL()); GLAdapter.init(new AndroidGL());
} }
}
super.onSurfaceCreated(); super.onSurfaceCreated();
} }

View File

@ -28,7 +28,6 @@
package org.oscim.android.gl; package org.oscim.android.gl;
import android.opengl.GLSurfaceView; import android.opengl.GLSurfaceView;
import org.oscim.android.MapView; import org.oscim.android.MapView;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -51,18 +50,18 @@ public class GlContextFactory implements GLSurfaceView.EGLContextFactory {
@Override @Override
public EGLContext createContext(EGL10 egl, EGLDisplay display, EGLConfig eglConfig) { public EGLContext createContext(EGL10 egl, EGLDisplay display, EGLConfig eglConfig) {
log.info("creating OpenGL ES " + MapView.targetGLESVersion + " context"); log.info("creating OpenGL ES " + MapView.OPENGL_VERSION + " context");
checkEglError("Before eglCreateContext " + MapView.targetGLESVersion, egl); checkEglError("Before eglCreateContext " + MapView.OPENGL_VERSION, egl);
int[] attrib_list = {EGL_CONTEXT_CLIENT_VERSION, (int) MapView.targetGLESVersion, EGL10.EGL_NONE}; int[] attrib_list = {EGL_CONTEXT_CLIENT_VERSION, (int) MapView.OPENGL_VERSION, EGL10.EGL_NONE};
EGLContext context = egl.eglCreateContext(display, eglConfig, EGL10.EGL_NO_CONTEXT, attrib_list); EGLContext context = egl.eglCreateContext(display, eglConfig, EGL10.EGL_NO_CONTEXT, attrib_list);
boolean success = checkEglError("After eglCreateContext " + MapView.targetGLESVersion, egl); boolean success = checkEglError("After eglCreateContext " + MapView.OPENGL_VERSION, egl);
if ((!success || context == null) && MapView.targetGLESVersion > 2) { if ((!success || context == null) && MapView.OPENGL_VERSION > 2) {
log.warn("Falling back to GLES 2"); log.warn("Falling back to GLES 2");
MapView.targetGLESVersion = 2.0; MapView.OPENGL_VERSION = 2.0;
return createContext(egl, display, eglConfig); return createContext(egl, display, eglConfig);
} }
log.info("Returning a GLES " + MapView.targetGLESVersion + " context"); log.info("Returning a GLES " + MapView.OPENGL_VERSION + " context");
return context; return context;
} }