Skip to content

Feat[renderer]: Add MobileGlues renderer support #6751

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: v3_openjdk
Choose a base branch
from
Open
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "MobileGlues"]
path = MobileGlues
url = https://github.com/MobileGL-Dev/MobileGlues.git
1 change: 1 addition & 0 deletions MobileGlues
Submodule MobileGlues added at 3f1bb9
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ PojavLauncher is licensed under [GNU LGPLv3](https://github.com/PojavLauncherTea
* [Boardwalk](https://github.com/zhuowei/Boardwalk) (JVM Launcher): Unknown License/[Apache License 2.0](https://github.com/zhuowei/Boardwalk/blob/master/LICENSE) or GNU GPLv2.
* Android Support Libraries: [Apache License 2.0](https://android.googlesource.com/platform/prebuilts/maven_repo/android/+/master/NOTICE.txt).
* [GL4ES](https://github.com/PojavLauncherTeam/gl4es): [MIT License](https://github.com/ptitSeb/gl4es/blob/master/LICENSE).
* [MobileGlues](https://github.com/MobileGL-Dev/MobileGlues): [LGPL-2.1 License](https://github.com/MobileGL-Dev/MobileGlues/blob/dev-es/LICENSE).
* [ANGLE](https://chromium.googlesource.com/angle/angle): [All Rights Reserved](app_pojavlauncher/src/main/jniLibs/ANGLE_LICENSE).
* [OpenJDK](https://github.com/PojavLauncherTeam/openjdk-multiarch-jdk8u): [GNU GPLv2 License](https://openjdk.java.net/legal/gplv2+ce.html).
* [LWJGL3](https://github.com/PojavLauncherTeam/lwjgl3): [BSD-3 License](https://github.com/LWJGL/lwjgl3/blob/master/LICENSE.md).
* [LWJGLX](https://github.com/PojavLauncherTeam/lwjglx) (LWJGL2 API compatibility layer for LWJGL3): unknown license.
Expand Down
Empty file added Task
Empty file.
3 changes: 3 additions & 0 deletions app_pojavlauncher/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ android {
gplay {
initWith release
signingConfig signingConfigs.googlePlayBuild
matchingFallbacks = [ 'release' ]
}
}

Expand Down Expand Up @@ -228,4 +229,6 @@ dependencies {
// implementation 'net.sourceforge.streamsupport:streamsupport-cfuture:1.7.0'

implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])

implementation project(":MobileGlues")
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
98947f23d338012c5869dc13de31cb39dadba333
53f2f037cef9b7447a6abbdf82150ca8a2f2a587
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20230712
20240411
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
98947f23d338012c5869dc13de31cb39dadba333
d5fc862f0eba62565dee5b8e511544573c281ec1
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
98947f23d338012c5869dc13de31cb39dadba333
4903cfc8d3afd63918f59caf0a146efc2d837069
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
}

private void runCraft(String versionId, JMinecraftVersionList.Version version) throws Throwable {
LauncherPreferences.writeMGRendererSettings(); // No MG detection for you
if(Tools.LOCAL_RENDERER == null) {
Tools.LOCAL_RENDERER = LauncherPreferences.PREF_RENDERER;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package net.kdt.pojavlaunch.prefs;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.preference.ListPreference;
import androidx.preference.Preference;

public class CustomListSummaryProvider implements Preference.SummaryProvider {
@Nullable
public CharSequence provideSummary(@NonNull Preference preference) {
if (preference.hasKey())
preference.setSummary(preference.getKey());
else preference.setSummary("@string/mcl_setting_title_renderer_settings");
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@

import net.kdt.pojavlaunch.*;
import net.kdt.pojavlaunch.multirt.MultiRTUtils;
import net.kdt.pojavlaunch.utils.FileUtils;
import net.kdt.pojavlaunch.utils.JREUtils;

import java.io.File;
import java.io.IOException;
import java.util.LinkedHashMap;

public class LauncherPreferences {
public static final String PREF_KEY_CURRENT_PROFILE = "currentProfile";
Expand Down Expand Up @@ -216,4 +219,32 @@ public static void computeNotchSize(Activity activity) {
}
Tools.updateWindowSize(activity);
}
}
public static void writeMGRendererSettings() throws IOException {
LinkedHashMap<String, Object> MGConfigJson = new LinkedHashMap<>();
// Copying the defaultValues from pref_renderer.xml to use as defaults here too

// We need to get the string and convert it to int because the android:defaultValues only takes in string-arrays.
// Using .getInt() leads to a class cast exception and using integer-arrays will just crash the layout/fragment.
MGConfigJson.put("enableANGLE", Integer.parseInt(DEFAULT_PREF.getString("mg_renderer_setting_angle", "0")));
MGConfigJson.put("enableNoError", Integer.parseInt(DEFAULT_PREF.getString("mg_renderer_setting_errorSetting", "0")));

// These guys are SwitchPreferences so they get special treatment, they need to be converted to ints
int gl43emu = DEFAULT_PREF.getBoolean("mg_renderer_setting_gl43emu", false) ? 1 : 0;
int computeShaderemu = DEFAULT_PREF.getBoolean("mg_renderer_computeShaderemu", false) ? 1 : 0;
MGConfigJson.put("enableExtGL43", gl43emu);
MGConfigJson.put("enableExtComputeShader", computeShaderemu);

MGConfigJson.put("enableCompatibleMode", Integer.parseInt(DEFAULT_PREF.getString("", "0"))); // Placeholder, doesn't do anything on current MG
MGConfigJson.put("multidrawMode", Integer.parseInt(DEFAULT_PREF.getString("mg_renderer_setting_multidraw", "0")));
MGConfigJson.put("maxGlslCacheSize", Integer.parseInt(DEFAULT_PREF.getString("mg_renderer_setting_glsl_cache_size", "2048")));
File configFile = new File(Tools.DIR_DATA + "/MobileGlues", "config.json");
FileUtils.ensureParentDirectory(configFile);
try {
Tools.write(configFile.getAbsolutePath(),Tools.GLOBAL_GSON.toJson(MGConfigJson));
Logger.appendToLog("Writing MG configs to " + configFile.getAbsolutePath());
Logger.appendToLog("MG Config is " + Tools.GLOBAL_GSON.toJson(MGConfigJson));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package net.kdt.pojavlaunch.prefs.screens;

import static android.text.InputType.TYPE_CLASS_NUMBER;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;

import androidx.annotation.NonNull;
import androidx.preference.EditTextPreference;
import androidx.preference.ListPreference;
import androidx.preference.Preference;

import net.kdt.pojavlaunch.R;

import java.util.Objects;

public class LauncherPreferenceRendererSettingsFragment extends LauncherPreferenceFragment {
EditTextPreference GLSLCachePreference;
@Override
public void onCreatePreferences(Bundle b, String str) {
addPreferencesFromResource(R.xml.pref_renderer);
GLSLCachePreference = findPreference("mg_renderer_setting_glsl_cache_size");
GLSLCachePreference.setOnBindEditTextListener((editText) -> {
editText.setInputType(TYPE_CLASS_NUMBER);
editText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
// Nothing, its boilerplate
}
@Override
public void afterTextChanged(Editable editable) {
// Nothing, its boilerplate
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
// This is just to handle the summary not updating when its above max int value
// Horrible I know.
if (editText.getText().toString().isEmpty()){
editText.setText("0");
}
if (Long.parseLong(editText.getText().toString()) > Integer.MAX_VALUE){
editText.setError("Too big! Setting to maximum value");
editText.setText(String.valueOf(Integer.MAX_VALUE));
}

}
});
});
updateGLSLCacheSummary(); // Just updates the summary with the value when user opens the menu. Yes it's out of place.
}

@Override
public void onSharedPreferenceChanged(SharedPreferences p, String s) {
GLSLCachePreference = findPreference("mg_renderer_setting_glsl_cache_size");
updateGLSLCacheSummary();
}

private void updateGLSLCacheSummary() {
try {
if (Objects.equals(Objects.requireNonNull(this.GLSLCachePreference).getText(), "") || Integer.parseInt(Objects.requireNonNull(this.GLSLCachePreference.getText())) == 0) {
this.GLSLCachePreference.setSummary(getString(R.string.global_off));
} else this.GLSLCachePreference.setSummary(this.GLSLCachePreference.getText() + " MB");
} catch (Exception e){ e.printStackTrace(); }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ public static void setJavaEnvironment(Activity activity, String jreHome) throws
envMap.put("LIBGL_ES", "3");
envMap.put("POJAVEXEC_EGL","libltw.so"); // Use ANGLE EGL
}
if(LOCAL_RENDERER.equals("opengles_mobileglues")){
envMap.put("MG_DIR_PATH", Tools.DIR_DATA + "/MobileGlues");
}
}
if(LauncherPreferences.PREF_BIG_CORE_AFFINITY) envMap.put("POJAV_BIG_CORE_AFFINITY", "1");
envMap.put("AWTSTUB_WIDTH", Integer.toString(CallbackBridge.windowWidth > 0 ? CallbackBridge.windowWidth : CallbackBridge.physicalWidth));
Expand Down Expand Up @@ -469,6 +472,7 @@ public static String loadGraphicsLibrary(){
case "opengles3":
renderLibrary = "libgl4es_114.so"; break;
case "vulkan_zink": renderLibrary = "libOSMesa.so"; break;
case "opengles_mobileglues": renderLibrary = "libmobileglues.so"; break;
case "opengles3_ltw" : renderLibrary = "libltw.so"; break;
default:
Log.w("RENDER_LIBRARY", "No renderer selected, defaulting to opengles2");
Expand Down
2 changes: 1 addition & 1 deletion app_pojavlauncher/src/main/jni/Application.mk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# NDK_TOOLCHAIN_VERSION := 4.9
APP_PLATFORM := android-21
APP_STL := system
APP_STL := c++_shared
# APP_ABI := armeabi-v7a arm64-v8a x86 x86_64
5 changes: 4 additions & 1 deletion app_pojavlauncher/src/main/jni/ctxbridges/egl_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <stddef.h>
#include <stdlib.h>
#include <dlfcn.h>
#include <string.h>
#include "egl_loader.h"
#include "loader_dlopen.h"

Expand Down Expand Up @@ -32,7 +33,9 @@ EGLBoolean (*eglQuerySurface_p)( EGLDisplay display,
__eglMustCastToProperFunctionPointerType (*eglGetProcAddress_p) (const char *procname);

bool dlsym_EGL() {
void* dl_handle = loader_dlopen(getenv("POJAVEXEC_EGL"),"libEGL.so", RTLD_LOCAL|RTLD_LAZY);
char* gles = getenv("LIBGL_GLES");
char* eglName = (strncmp(gles ? gles : "", "libGLESv2_angle.so", 18) == 0) ? "libEGL_angle.so" : getenv("POJAVEXEC_EGL");
void* dl_handle = loader_dlopen(eglName,"libEGL.so", RTLD_LOCAL|RTLD_LAZY);
if(dl_handle == NULL) return false;
eglGetProcAddress_p = dlsym(dl_handle, "eglGetProcAddress");
if(eglGetProcAddress_p == NULL) {
Expand Down
2 changes: 1 addition & 1 deletion app_pojavlauncher/src/main/jni/egl_bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ int pojavInitOpenGL() {
load_vulkan();
setenv("GALLIUM_DRIVER","zink",1);
set_osm_bridge_tbl();
}
} else printf("EGLBridge: Renderer was not configured as a bridge. Consider adding \"opengles\" to the start of renderer name if it crashes");
if(br_init()) {
br_setup_window();
}
Expand Down
32 changes: 32 additions & 0 deletions app_pojavlauncher/src/main/jniLibs/ANGLE_LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2018 The ANGLE Project Authors.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// Neither the name of TransGaming Inc., Google Inc., 3DLabs Inc.
// Ltd., nor the names of their contributors may be used to endorse
// or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 44 additions & 2 deletions app_pojavlauncher/src/main/res/values/headings_array.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
<string-array name="renderer">
<item name="1">@string/mcl_setting_renderer_gles2_4</item>
<item name="2">@string/mcl_setting_renderer_vulkan_zink</item>
<item name="3">@string/mcl_setting_renderer_ltw</item>
<item name="2">@string/mcl_setting_renderer_mobileglues</item>
<item name="4">@string/mcl_setting_renderer_ltw</item>
</string-array>

<string-array name="menu_customcontrol">
Expand Down Expand Up @@ -37,6 +38,7 @@
<string-array name="renderer_values">
<item>opengles2</item> <!-- gl4es_extra 1.1.4 with OpenGL ES 2/"3" -->
<item>vulkan_zink</item> <!-- virglrenderer with OpenGL ES 3 -->
<item>opengles_mobileglues</item>
<item>opengles3_ltw</item>
</string-array>
<string-array name="download_source_names">
Expand All @@ -47,5 +49,45 @@
<item>default</item>
<item>bmclapi</item>
</string-array>

<!--TODO: Make this translatable-->
<string-array name="mg_renderer_names_angle">
<item>Disable if possible</item>
<item>Enable if possible</item>
<item>Disabled</item>
<item>Enabled</item>
</string-array>
<string-array name="mg_renderer_values_angle">
<item>0</item>
<item>1</item>
<item>2</item>
<item>3</item>
</string-array>
<!--TODO: Make this translatable-->
<string-array name="mg_renderer_names_multidraw">
<item>Auto</item>
<item>Prefer Indirect</item>
<item>Prefer BaseVertex</item>
<item>Prefer MultiDraw Indirect</item>
<item>Force DrawElements</item>
</string-array>
<string-array name="mg_renderer_values_multidraw">
<item>0</item>
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
</string-array>
<string-array name="mg_renderer_names_errorSetting">
<item>Auto</item>
<item>Don\'t ignore</item>
<item>Ignore shader/program errors</item>
<item>Ignore shader/program/framebuffer errors</item>
</string-array>
<string-array name="mg_renderer_values_errorSetting">
<item>0</item>
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
</string-array>
</resources>
16 changes: 15 additions & 1 deletion app_pojavlauncher/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,12 @@
<string name="mcl_setting_subtitle_mousescale">Change the size of the virtual mouse.</string>
<string name="mcl_setting_title_javaargs">JVM Launch arguments</string>
<string name="mcl_setting_subtitle_javaargs">Be careful, this may make game crash if modified without knowledge.</string>
<string name="mcl_setting_title_renderer_settings">Extra Renderer Settings</string>
<string name="mcl_setting_title_renderer_subtitle">Renderer specific settings</string>
<string name="mcl_setting_category_renderer">Renderer</string>
<string name="mcl_setting_renderer_gles2_4">Holy GL4ES - (all versions, fast)</string>
<string name="mcl_setting_renderer_vulkan_zink">Zink (Vulkan) - (all versions, mid)</string>
<string name="mcl_setting_renderer_mobileglues">MobileGlues (OpenGL ES) - (1.17+ only, fast)</string>
<string name="mcl_setting_renderer_ltw">LTW (OpenGL ES 3) - 1.17+ only</string>
<string name="mcl_setting_veroption_release">Release</string>
<string name="mcl_setting_veroption_snapshot">Snapshot</string>
Expand All @@ -90,6 +93,7 @@
<string name="global_select">Select</string>
<string name="global_retry">Retry</string>
<string name="global_default">Default</string>
<string name="global_off">Off</string>

<!-- MainActivity: strings -->
<string name="mcn_exit_title">Application/Game exited with code %d, check latestlog.txt for more details.</string>
Expand Down Expand Up @@ -431,4 +435,14 @@
<string name="bta_installer_nightly_versions">Nightly BTA versions</string>
<string name="newdl_extracting_native_libraries">Extracting native libraries (%d/%d)</string>
<string name="toast_not_available_demo">This is not available in demo mode</string>
</resources>

<string name="preference_renderer_mobileglues_settings">MobileGlues Renderer Settings</string>
<string name="mg_renderer_glsl_cache">Max GLSL cache size</string>
<string name="mg_renderer_angle">Use ANGLE as driver</string>
<string name="mg_renderer_multidraw">Multidraw emulation mode</string>
<string name="mg_renderer_title_gl43emu">Enable incomplete OpenGL 4.3 emulation</string>
<string name="mg_renderer_summary_gl43emu">May help with mod crashes. Disable if not needed, can cause crashes.</string>
<string name="mg_renderer_title_computeShaderemu">Enable Compute Shader emulation</string>
<string name="mg_renderer_summary_computeShaderemu">May help with shaderpack glitches. Disable if not needed, can cause crashes.</string>
<string name="mg_renderer_title_errorSetting">Error Filtering</string>
</resources>
1 change: 1 addition & 0 deletions app_pojavlauncher/src/main/res/xml/pref_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
android:icon="@drawable/ic_setting_video"
/>


<Preference
android:key="control_screen_setting"
android:title="@string/preference_control_title"
Expand Down
Loading