Add an option to switch between OpenGL ES renderers

This commit is contained in:
khanhduytran0 2021-03-06 14:25:59 +07:00
parent 213c37c779
commit 0602739102
6 changed files with 29 additions and 19 deletions

View File

@ -6,6 +6,7 @@ import net.kdt.pojavlaunch.*;
public class LauncherPreferences
{
public static SharedPreferences DEFAULT_PREF;
public static int PREF_RENDERER = 2;
public static boolean PREF_VERTYPE_RELEASE = true;
public static boolean PREF_VERTYPE_SNAPSHOT = false;
public static boolean PREF_VERTYPE_OLDALPHA = false;
@ -28,6 +29,7 @@ public class LauncherPreferences
public static boolean PREF_DISABLE_GESTURES = false;
public static float PREF_MOUSESPEED = 1f;
public static void loadPreferences() {
PREF_RENDERER = DEFAULT_PREF.getInt("renderer", 2);
PREF_BUTTONSIZE = DEFAULT_PREF.getInt("buttonscale", 100);
PREF_MOUSESCALE = DEFAULT_PREF.getInt("mousescale", 100);
PREF_MOUSESPEED = ((float)DEFAULT_PREF.getInt("mousespeed",100))/100f;

View File

@ -249,11 +249,11 @@ public class JREUtils
if(!envMap.containsKey("LIBGL_ES")) {
int glesMajor = getDetectedVersion();
Log.i("glesDetect","GLES version detected: "+glesMajor);
if(glesMajor < 2) {
if (glesMajor < 3) {
//fallback to 2 since it's the minimum for the entire app
envMap.put("LIBGL_ES","2");
}else{
envMap.put("LIBGL_ES",""+glesMajor);
} else {
envMap.put("LIBGL_ES", Integer.toString(LauncherPreferences.PREF_RENDERER));
}
}
for (Map.Entry<String, String> env : envMap.entrySet()) {

View File

@ -64,14 +64,7 @@ JNIEXPORT void JNICALL Java_net_kdt_pojavlaunch_utils_JREUtils_setupBridgeWindow
JNIEXPORT jlong JNICALL Java_org_lwjgl_glfw_GLFW_nativeEglGetCurrentContext(JNIEnv* env, jclass clazz) {
return (jlong) eglGetCurrentContext();
}
static const EGLint es3_ctx_attribs[] = {
EGL_CONTEXT_CLIENT_VERSION, 3,
EGL_NONE
};
static const EGLint es2_ctx_attribs[] = {
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE
};
JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_GLFW_nativeEglInit(JNIEnv* env, jclass clazz) {
if (potatoBridge.eglDisplay == NULL || potatoBridge.eglDisplay == EGL_NO_DISPLAY) {
potatoBridge.eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
@ -201,21 +194,22 @@ Java_org_lwjgl_glfw_GLFW_nativeEglDetachOnCurrentThread(JNIEnv *env, jclass claz
//Obstruct the context on the current thread
eglMakeCurrent(potatoBridge.eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
}
JNIEXPORT jlong JNICALL
Java_org_lwjgl_glfw_GLFW_nativeEglCreateContext(JNIEnv *env, jclass clazz, jlong contextSrc) {
EGLContext* ctx = eglCreateContext(potatoBridge.eglDisplay,config,(void*)contextSrc,es3_ctx_attribs);
if (ctx == EGL_NO_CONTEXT) {
printf("EGLBridge: Could not create ES3 context, fallbacking to ES2\n");
setenv("LIBGL_ES", "2", 1);
ctx = eglCreateContext(potatoBridge.eglDisplay,config,(void*)contextSrc,es2_ctx_attribs);
} else {
setenv("LIBGL_ES", "3", 1);
}
const EGLint ctx_attribs[] = {
EGL_CONTEXT_CLIENT_VERSION, atoi(getenv("LIBGL_ES", "2")),
EGL_NONE
};
EGLContext* ctx = eglCreateContext(potatoBridge.eglDisplay, config, (void*)contextSrc, ctx_attribs);
if (potatoBridge.eglContext == NULL) potatoBridge.eglContext = ctx;
printf("EGLBridge: Created CTX pointer = %p\n",ctx);
//(*env)->ThrowNew(env,(*env)->FindClass(env,"java/lang/Exception"),"Trace exception");
return (long)ctx;
}
JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_GLFW_nativeEglTerminate(JNIEnv* env, jclass clazz) {
terminateEgl();
return JNI_TRUE;

View File

@ -6,4 +6,9 @@
<item>@string/mcl_option_customcontrol</item>
<item>@string/mcl_option_about</item>
</string-array>
<string-array name="renderer">
<item name="2">@string/mcl_setting_renderer_gles2</item>
<item name="3">@string/mcl_setting_renderer_gles3</item>
</string-array>
</resources>

View File

@ -97,6 +97,9 @@
<string name="mcl_setting_subtitle_javaargs">Be careful, this may make game crash if modified without knowledge.</string>
<string name="mcl_setting_category_general">General settings</string>
<string name="mcl_setting_category_scaling">Scaling settings</string>
<string name="mcl_setting_category_renderer">Renderer</string>
<string name="mcl_setting_renderer_gles2">OpenGL ES 2</string>
<string name="mcl_setting_renderer_gles3">OpenGL ES 3</string>
<string name="mcl_setting_category_veroption">Version type will be in version list</string>
<string name="mcl_setting_veroption_release">Release</string>
<string name="mcl_setting_veroption_snapshot">Snapshot</string>

View File

@ -11,6 +11,12 @@
android:title="@string/mcl_setting_title_uninstalljre"
app2:icon="@drawable/rm_jre" />
<androidx.preference.ListPreference
android:title="@string/mcl_setting_category_renderer"
android:key="renderer"
android:defaultValue="2"
android:entries="@array/renderer" />
<net.kdt.pojavlaunch.prefs.CustomSeekBarPreference
android:key="timeLongPressTrigger"
android:summary="@string/mcl_setting_subtitle_longpresstrigger"