This commit is contained in:
Duy Tran Khanh committed 2021-01-26 21:06:07 +07:00
1 parent 860a8105e1
commit 9eb4b74a10
6 files changed
+232 -162

No files matched your search

+82 -36
View File
@@ -24,6 +24,8 @@ import java.util.*;
public class GLFW
{
static FloatBuffer joystickData = (FloatBuffer)FloatBuffer.allocate(8).flip();
static ByteBuffer buttonData = (ByteBuffer)ByteBuffer.allocate(8).flip();
/** The major version number of the GLFW library. This is incremented when the API is changed in non-compatible ways. */
public static final int GLFW_VERSION_MAJOR = 3;
@@ -495,9 +497,10 @@ public class GLFW
private static ArrayMap<Long, GLFWWindowProperties> mGLFWWindowMap;
public static boolean mGLFWIsGrabbing, mGLFWIsInputReady, mGLFWIsUseStackQueue = false;
public static final byte[] keyDownBuffer = new byte[316];
public static final byte[] keyDownBuffer = new byte[316];
public static long mainContext = 0;
static {
// Minecraft triggers a glfwPollEvents() on splash screen, so update window size there.
CallbackBridge.receiveCallback(CallbackBridge.EVENT_TYPE_FRAMEBUFFER_SIZE, mGLFWWindowWidth, mGLFWWindowHeight, 0, 0);
CallbackBridge.receiveCallback(CallbackBridge.EVENT_TYPE_WINDOW_SIZE, mGLFWWindowWidth, mGLFWWindowHeight, 0, 0);
@@ -553,8 +556,10 @@ public class GLFW
}
private static native long nativeEglGetCurrentContext();
// private static native boolean nativeEglInit();
private static native boolean nativeEglInit();
public static native boolean nativeEglMakeCurrent(long window);
public static native void nativeEglDetachOnCurrentThread();
public static native long nativeEglCreateContext(long contextSrc);
private static native boolean nativeEglTerminate();
private static native boolean nativeEglSwapBuffers();
private static native boolean nativeEglSwapInterval(int inverval);
@@ -751,10 +756,14 @@ public class GLFW
public static GLFWWindowSizeCallback glfwSetWindowSizeCallback(@NativeType("GLFWwindow *") long window, @Nullable @NativeType("GLFWwindowsizefun") GLFWWindowSizeCallbackI cbfun) {
return mGLFWWindowSizeCallback = GLFWWindowSizeCallback.createSafe(nglfwSetWindowSizeCallback(window, memAddressSafe(cbfun)));
}
static boolean isGLFWReady;
public static boolean glfwInit() {
mGLFWInitialTime = (double) System.nanoTime();
return true; // nativeEglInit();
if (!isGLFWReady) {
CallbackBridge.nativeAttachThreadToOther(false, false);
mGLFWInitialTime = (double) System.nanoTime();
isGLFWReady = nativeEglInit();
}
return isGLFWReady;
}
public static void glfwTerminate() {
@@ -920,20 +929,10 @@ public class GLFW
mGLFWGammaRamp = ramp;
}
private static long mGLFWCurrentGLContextThread = -1;
public static void glfwMakeContextCurrent(long window) {
long currentGLThreadId = Thread.currentThread().getId();
// Long.parseLong(System.getProperty("glfwstub.internal.glthreadid", "-1"));
System.out.println("GLFW: glfwMakeContextCurrent() calling from thread ID " + currentGLThreadId + ", name: " + Thread.currentThread().getName());
if (currentGLThreadId != -1 && currentGLThreadId != mGLFWCurrentGLContextThread) {
System.out.println("GLFW: Current context is set, creating shared context");
if (!nativeEglMakeCurrent(window)) {
throw new RuntimeException("eglMakeCurrent() failed, check log file for more details");
}
mGLFWCurrentGLContextThread = currentGLThreadId;
} else {
System.out.println("GLFW: glfwMakeContextCurrent() request is skipped");
}
//Probably not the best idea to rely on program's internals to share the contexts...
// new Exception("Trace exception").printStackTrace();
nativeEglMakeCurrent(window);
}
public static void glfwSwapBuffers(long window) {
@@ -967,23 +966,23 @@ public class GLFW
// GLFW Window functions
public static long glfwCreateWindow(int width, int height, CharSequence title, long monitor, long share) {
EventLoop.OffScreen.check();
// Create an ACTUAL EGL context
long ptr = nativeEglCreateContext(share);
//nativeEglMakeCurrent(ptr);
GLFWWindowProperties win = new GLFWWindowProperties();
// win.width = width;
// win.height = height;
// A good idea to fake pointer
long ptr = System.currentTimeMillis();
GLFWWindowProperties win = new GLFWWindowProperties();
// win.width = width;
// win.height = height;
win.width = mGLFWWindowWidth;
win.height = mGLFWWindowHeight;
win.title = title;
mGLFWWindowMap.put(ptr, win);
win.width = mGLFWWindowWidth;
win.height = mGLFWWindowHeight;
win.title = title;
mGLFWWindowMap.put(ptr, win);
mainContext = ptr;
return ptr;
//Return our context
// Prevent NULL check
return ptr;
}
public static void glfwDestroyWindow(long window) {
@@ -1076,7 +1075,7 @@ public class GLFW
break;
case CallbackBridge.EVENT_TYPE_KEY:
if (mGLFWKeyCallback != null) {
keyDownBuffer[dataArr[1]-32]=(byte)(int)dataArr[3];
keyDownBuffer[dataArr[1]-32]=(byte)(int)dataArr[3];
mGLFWKeyCallback.invoke(ptr, dataArr[1], dataArr[2], dataArr[3], dataArr[4]);
}
break;
@@ -1210,4 +1209,51 @@ public class GLFW
public static String glfwGetClipboardString(@NativeType("GLFWwindow *") long window) {
return CallbackBridge.nativeClipboard(CallbackBridge.CLIPBOARD_PASTE, null);
}
}
public static boolean glfwJoystickPresent(int jid) {
if(jid == 0) {
return true;
}else return false;
}
public static String glfwGetJoystickName(int jid) {
if(jid == 0) {
return "AIC event bus controller";
}else return null;
}
public static FloatBuffer glfwGetJoystickAxes(int jid) {
if(jid == 0) {
return joystickData;
}else return null;
}
public static ByteBuffer glfwGetJoystickButtons(int jid) {
if(jid == 0) {
return buttonData;
}else return null;
}
public static ByteBuffer glfwGetjoystickHats(int jid) {
return null;
}
public static boolean glfwJoystickIsGamepad(int jid) {
if(jid == 0) return true;
else return false;
}
public static String glfwGetJoystickGUID(int jid) {
if(jid == 0) return "aio0";
else return null;
}
public static long glfwGetJoystickUserPointer(int jid) {
return 0;
}
public static void glfwSetJoystickUserPointer(int jid, long pointer) {
}
public static boolean glfwUpdateGamepadMappings(ByteBuffer string) {
return false;
}
public static String glfwGetGamepadName(int jid) {
return null;
}
public static boolean glfwGetGamepadState(int jid, GLFWGamepadState state) {
return false;
}
}