mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-17 00:29:50 -04:00
Check the ES version before launching, add a more proper way to detect the keyboard
This commit is contained in:
parent
06f1d58993
commit
315ad94100
@ -153,6 +153,8 @@ public class AndroidLWJGLKeycode {
|
||||
// androidToLwjglMap.put(KeyEvent.KEYCODE_YEN, LWJGLGLFWKeycode.GLFW_KEY_YEN);
|
||||
|
||||
// androidToLwjglMap.put(KeyEvent.KEYCODE_BUTTON_1, LWJGLGLFWKeycode.G
|
||||
androidToLwjglMap.put(KeyEvent.KEYCODE_AT,LWJGLGLFWKeycode.GLFW_KEY_2);
|
||||
androidToLwjglMap.put(KeyEvent.KEYCODE_POUND,LWJGLGLFWKeycode.GLFW_KEY_3);
|
||||
}
|
||||
|
||||
public static String[] generateKeyName() {
|
||||
@ -174,15 +176,23 @@ public class AndroidLWJGLKeycode {
|
||||
CallbackBridge.holdingShift = keyEvent.isShiftPressed();
|
||||
|
||||
try {
|
||||
//System.out.println(((int)keyEvent.getDisplayLabel()) + " " +keyEvent.getDisplayLabel());
|
||||
System.out.println(keyEvent.getKeyCode() + " " +keyEvent.getDisplayLabel());
|
||||
if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_BACK && LauncherPreferences.PREF_BACK_TO_RIGHT_MOUSE) {
|
||||
BaseMainActivity.sendMouseButton(LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_RIGHT, keyEvent.getAction() == KeyEvent.ACTION_DOWN);
|
||||
} else {
|
||||
if(keyEvent.getUnicodeChar() != 0) {
|
||||
char key = (char)keyEvent.getUnicodeChar();
|
||||
BaseMainActivity.sendKeyPress(androidToLwjglMap.get(keyEvent.getKeyCode()),key,0,CallbackBridge.getCurrentMods(),keyEvent.getAction() == KeyEvent.ACTION_DOWN);
|
||||
BaseMainActivity.sendKeyPress(
|
||||
androidToLwjglMap.get(keyEvent.getKeyCode()),
|
||||
key,
|
||||
0,
|
||||
CallbackBridge.getCurrentMods(),
|
||||
keyEvent.getAction() == KeyEvent.ACTION_DOWN);
|
||||
}else{
|
||||
BaseMainActivity.sendKeyPress(androidToLwjglMap.get(keyEvent.getKeyCode()),CallbackBridge.getCurrentMods(),keyEvent.getAction()==KeyEvent.ACTION_DOWN);
|
||||
BaseMainActivity.sendKeyPress(
|
||||
androidToLwjglMap.get(keyEvent.getKeyCode()),
|
||||
CallbackBridge.getCurrentMods(),
|
||||
keyEvent.getAction()==KeyEvent.ACTION_DOWN);
|
||||
}
|
||||
}
|
||||
} catch (Throwable th) {
|
||||
|
@ -775,9 +775,17 @@ public class BaseMainActivity extends LoggableActivity {
|
||||
}
|
||||
}
|
||||
}
|
||||
boolean isKeyboard(KeyEvent evt) {
|
||||
if((evt.getFlags() & KeyEvent.FLAG_SOFT_KEYBOARD) == KeyEvent.FLAG_SOFT_KEYBOARD) return true;
|
||||
if(evt.getSource() == InputDevice.SOURCE_KEYBOARD) return true;
|
||||
if(evt.getUnicodeChar() != 0) return true;
|
||||
if(AndroidLWJGLKeycode.androidToLwjglMap.containsKey(evt.getKeyCode())) return true;
|
||||
return false;
|
||||
}
|
||||
byte[] kevArray = new byte[8];
|
||||
@Override
|
||||
public boolean dispatchKeyEvent(KeyEvent event) {
|
||||
System.out.println(event.getSource() + " "+ event.getFlags());
|
||||
if(event.getSource() == InputDevice.SOURCE_CLASS_JOYSTICK) {
|
||||
switch(event.getKeyCode()) {
|
||||
case KeyEvent.KEYCODE_BUTTON_A:
|
||||
@ -799,9 +807,9 @@ public class BaseMainActivity extends LoggableActivity {
|
||||
}
|
||||
CallbackBridge.nativePutControllerButtons(ByteBuffer.wrap(kevArray));
|
||||
return true;
|
||||
}else if((event.getFlags() & KeyEvent.FLAG_SOFT_KEYBOARD) == KeyEvent.FLAG_SOFT_KEYBOARD || event.getSource() == InputDevice.SOURCE_KEYBOARD) {
|
||||
}else if(isKeyboard(event)) {
|
||||
AndroidLWJGLKeycode.execKey(event,event.getKeyCode(),event.getAction() == KeyEvent.ACTION_DOWN);
|
||||
return false;
|
||||
return true;
|
||||
}else return false;
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,9 @@ package net.kdt.pojavlaunch.utils;
|
||||
|
||||
import android.app.*;
|
||||
import android.content.*;
|
||||
import android.opengl.EGL14;
|
||||
import android.opengl.EGLExt;
|
||||
import android.opengl.GLES10;
|
||||
import android.system.*;
|
||||
import android.util.*;
|
||||
import android.widget.Toast;
|
||||
@ -15,6 +18,11 @@ import net.kdt.pojavlaunch.*;
|
||||
import net.kdt.pojavlaunch.prefs.*;
|
||||
import org.lwjgl.glfw.*;
|
||||
|
||||
import javax.microedition.khronos.egl.EGL10;
|
||||
import javax.microedition.khronos.egl.EGLConfig;
|
||||
import javax.microedition.khronos.egl.EGLContext;
|
||||
import javax.microedition.khronos.egl.EGLDisplay;
|
||||
|
||||
public class JREUtils
|
||||
{
|
||||
private JREUtils() {}
|
||||
@ -238,7 +246,16 @@ public class JREUtils
|
||||
}
|
||||
reader.close();
|
||||
}
|
||||
|
||||
if(!envMap.containsKey("LIBGL_ES")) {
|
||||
int glesMajor = getDetectedVersion();
|
||||
Log.i("glesDetect","GLES version detected: "+glesMajor);
|
||||
if(glesMajor < 2) {
|
||||
//fallback to 2 since it's the minimum for the entire app
|
||||
envMap.put("LIBGL_ES","2");
|
||||
}else{
|
||||
envMap.put("LIBGL_ES",""+glesMajor);
|
||||
}
|
||||
}
|
||||
for (Map.Entry<String, String> env : envMap.entrySet()) {
|
||||
try {
|
||||
if (shell == null) {
|
||||
@ -328,6 +345,78 @@ public class JREUtils
|
||||
}
|
||||
}
|
||||
}
|
||||
private static final int EGL_OPENGL_ES_BIT = 0x0001;
|
||||
private static final int EGL_OPENGL_ES2_BIT = 0x0004;
|
||||
private static final int EGL_OPENGL_ES3_BIT_KHR = 0x0040;
|
||||
private static boolean hasExtension(String extensions, String name) {
|
||||
int start = extensions.indexOf(name);
|
||||
while (start >= 0) {
|
||||
// check that we didn't find a prefix of a longer extension name
|
||||
int end = start + name.length();
|
||||
if (end == extensions.length() || extensions.charAt(end) == ' ') {
|
||||
return true;
|
||||
}
|
||||
start = extensions.indexOf(name, end);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private static int getDetectedVersion() {
|
||||
/*
|
||||
* Get all the device configurations and check the EGL_RENDERABLE_TYPE attribute
|
||||
* to determine the highest ES version supported by any config. The
|
||||
* EGL_KHR_create_context extension is required to check for ES3 support; if the
|
||||
* extension is not present this test will fail to detect ES3 support. This
|
||||
* effectively makes the extension mandatory for ES3-capable devices.
|
||||
*/
|
||||
EGL10 egl = (EGL10) EGLContext.getEGL();
|
||||
EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
|
||||
int[] numConfigs = new int[1];
|
||||
if (egl.eglInitialize(display, null)) {
|
||||
try {
|
||||
boolean checkES3 = hasExtension(egl.eglQueryString(display, EGL10.EGL_EXTENSIONS),
|
||||
"EGL_KHR_create_context");
|
||||
if (egl.eglGetConfigs(display, null, 0, numConfigs)) {
|
||||
EGLConfig[] configs = new EGLConfig[numConfigs[0]];
|
||||
if (egl.eglGetConfigs(display, configs, numConfigs[0], numConfigs)) {
|
||||
int highestEsVersion = 0;
|
||||
int[] value = new int[1];
|
||||
for (int i = 0; i < numConfigs[0]; i++) {
|
||||
if (egl.eglGetConfigAttrib(display, configs[i],
|
||||
EGL10.EGL_RENDERABLE_TYPE, value)) {
|
||||
if (checkES3 && ((value[0] & EGL_OPENGL_ES3_BIT_KHR) ==
|
||||
EGL_OPENGL_ES3_BIT_KHR)) {
|
||||
if (highestEsVersion < 3) highestEsVersion = 3;
|
||||
} else if ((value[0] & EGL_OPENGL_ES2_BIT) == EGL_OPENGL_ES2_BIT) {
|
||||
if (highestEsVersion < 2) highestEsVersion = 2;
|
||||
} else if ((value[0] & EGL_OPENGL_ES_BIT) == EGL_OPENGL_ES_BIT) {
|
||||
if (highestEsVersion < 1) highestEsVersion = 1;
|
||||
}
|
||||
} else {
|
||||
Log.w("glesDetect", "Getting config attribute with "
|
||||
+ "EGL10#eglGetConfigAttrib failed "
|
||||
+ "(" + i + "/" + numConfigs[0] + "): "
|
||||
+ egl.eglGetError());
|
||||
}
|
||||
}
|
||||
return highestEsVersion;
|
||||
} else {
|
||||
Log.e("glesDetect", "Getting configs with EGL10#eglGetConfigs failed: "
|
||||
+ egl.eglGetError());
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
Log.e("glesDetect", "Getting number of configs with EGL10#eglGetConfigs failed: "
|
||||
+ egl.eglGetError());
|
||||
return -2;
|
||||
}
|
||||
} finally {
|
||||
egl.eglTerminate(display);
|
||||
}
|
||||
} else {
|
||||
Log.e("glesDetect", "Couldn't initialize EGL.");
|
||||
return -3;
|
||||
}
|
||||
}
|
||||
public static native int chdir(String path);
|
||||
public static native boolean dlopen(String libPath);
|
||||
public static native void redirectLogcat();
|
||||
|
Loading…
x
Reference in New Issue
Block a user