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

View File

@ -249,11 +249,11 @@ public class JREUtils
if(!envMap.containsKey("LIBGL_ES")) { if(!envMap.containsKey("LIBGL_ES")) {
int glesMajor = getDetectedVersion(); int glesMajor = getDetectedVersion();
Log.i("glesDetect","GLES version detected: "+glesMajor); 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 //fallback to 2 since it's the minimum for the entire app
envMap.put("LIBGL_ES","2"); envMap.put("LIBGL_ES","2");
}else{ } else {
envMap.put("LIBGL_ES",""+glesMajor); envMap.put("LIBGL_ES", Integer.toString(LauncherPreferences.PREF_RENDERER));
} }
} }
for (Map.Entry<String, String> env : envMap.entrySet()) { 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) { JNIEXPORT jlong JNICALL Java_org_lwjgl_glfw_GLFW_nativeEglGetCurrentContext(JNIEnv* env, jclass clazz) {
return (jlong) eglGetCurrentContext(); 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) { JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_GLFW_nativeEglInit(JNIEnv* env, jclass clazz) {
if (potatoBridge.eglDisplay == NULL || potatoBridge.eglDisplay == EGL_NO_DISPLAY) { if (potatoBridge.eglDisplay == NULL || potatoBridge.eglDisplay == EGL_NO_DISPLAY) {
potatoBridge.eglDisplay = eglGetDisplay(EGL_DEFAULT_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 //Obstruct the context on the current thread
eglMakeCurrent(potatoBridge.eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); eglMakeCurrent(potatoBridge.eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
} }
JNIEXPORT jlong JNICALL JNIEXPORT jlong JNICALL
Java_org_lwjgl_glfw_GLFW_nativeEglCreateContext(JNIEnv *env, jclass clazz, jlong contextSrc) { Java_org_lwjgl_glfw_GLFW_nativeEglCreateContext(JNIEnv *env, jclass clazz, jlong contextSrc) {
EGLContext* ctx = eglCreateContext(potatoBridge.eglDisplay,config,(void*)contextSrc,es3_ctx_attribs); const EGLint ctx_attribs[] = {
if (ctx == EGL_NO_CONTEXT) { EGL_CONTEXT_CLIENT_VERSION, atoi(getenv("LIBGL_ES", "2")),
printf("EGLBridge: Could not create ES3 context, fallbacking to ES2\n"); EGL_NONE
setenv("LIBGL_ES", "2", 1); };
ctx = eglCreateContext(potatoBridge.eglDisplay,config,(void*)contextSrc,es2_ctx_attribs); EGLContext* ctx = eglCreateContext(potatoBridge.eglDisplay, config, (void*)contextSrc, ctx_attribs);
} else {
setenv("LIBGL_ES", "3", 1);
}
if (potatoBridge.eglContext == NULL) potatoBridge.eglContext = ctx;
printf("EGLBridge: Created CTX pointer = %p\n",ctx); printf("EGLBridge: Created CTX pointer = %p\n",ctx);
//(*env)->ThrowNew(env,(*env)->FindClass(env,"java/lang/Exception"),"Trace exception"); //(*env)->ThrowNew(env,(*env)->FindClass(env,"java/lang/Exception"),"Trace exception");
return (long)ctx; return (long)ctx;
} }
JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_GLFW_nativeEglTerminate(JNIEnv* env, jclass clazz) { JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_GLFW_nativeEglTerminate(JNIEnv* env, jclass clazz) {
terminateEgl(); terminateEgl();
return JNI_TRUE; return JNI_TRUE;

View File

@ -6,4 +6,9 @@
<item>@string/mcl_option_customcontrol</item> <item>@string/mcl_option_customcontrol</item>
<item>@string/mcl_option_about</item> <item>@string/mcl_option_about</item>
</string-array> </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> </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_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_general">General settings</string>
<string name="mcl_setting_category_scaling">Scaling 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_category_veroption">Version type will be in version list</string>
<string name="mcl_setting_veroption_release">Release</string> <string name="mcl_setting_veroption_release">Release</string>
<string name="mcl_setting_veroption_snapshot">Snapshot</string> <string name="mcl_setting_veroption_snapshot">Snapshot</string>

View File

@ -10,6 +10,12 @@
android:summary="@string/mcl_setting_subtitle_uninstalljre" android:summary="@string/mcl_setting_subtitle_uninstalljre"
android:title="@string/mcl_setting_title_uninstalljre" android:title="@string/mcl_setting_title_uninstalljre"
app2:icon="@drawable/rm_jre" /> 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 <net.kdt.pojavlaunch.prefs.CustomSeekBarPreference
android:key="timeLongPressTrigger" android:key="timeLongPressTrigger"