From 02378b9ba2719fe5bb6c40c120871ea5002281c1 Mon Sep 17 00:00:00 2001 From: artdeell Date: Sat, 31 Jul 2021 14:58:58 +0300 Subject: [PATCH] Multi-context --- .../main/java/net/kdt/pojavlaunch/Tools.java | 2 +- .../main/java/org/lwjgl/opengl/ContextGL.java | 25 +++++++++++++------ .../main/java/org/lwjgl/opengl/Display.java | 2 +- .../main/java/org/lwjgl/opengl/GLContext.java | 11 +++++--- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Tools.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Tools.java index 83b95c7bd..7ef93a944 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Tools.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Tools.java @@ -96,7 +96,7 @@ public final class Tools { if(pvcConfig != null && pvcConfig.gamePath != null && !pvcConfig.gamePath.isEmpty()) gamedirPath = pvcConfig.gamePath; else gamedirPath = Tools.DIR_GAME_NEW; if(pvcConfig != null && pvcConfig.jvmArgs != null && !pvcConfig.jvmArgs.isEmpty()) LauncherPreferences.PREF_CUSTOM_JAVA_ARGS = pvcConfig.jvmArgs; - PojavLoginActivity.disableSplash(gamedirPath); + //PojavLoginActivity.disableSplash(gamedirPath); String[] launchArgs = getMinecraftArgs(profile, versionInfo, gamedirPath); // ctx.appendlnToLog("Minecraft Args: " + Arrays.toString(launchArgs)); diff --git a/jre_lwjgl3glfw/src/main/java/org/lwjgl/opengl/ContextGL.java b/jre_lwjgl3glfw/src/main/java/org/lwjgl/opengl/ContextGL.java index 9df0f9608..23193afda 100644 --- a/jre_lwjgl3glfw/src/main/java/org/lwjgl/opengl/ContextGL.java +++ b/jre_lwjgl3glfw/src/main/java/org/lwjgl/opengl/ContextGL.java @@ -63,7 +63,8 @@ final class ContextGL implements Context { private static final ThreadLocal current_context_local = new ThreadLocal(); /** Handle to the native GL rendering context */ - private final ByteBuffer handle; + //private final ByteBuffer handle; + private final long handle; private final PeerInfo peer_info; private final ContextAttribs contextAttribs; @@ -95,7 +96,13 @@ final class ContextGL implements Context { static ContextGL getCurrentContext() { return current_context_local.get(); } - + ContextGL(long handle) { + this.peer_info = null; + this.contextAttribs = null; + this.forwardCompatible = false; + this.handle = handle; + System.out.println("LWJGLX: ready-handle context created"); + } /** Create a context with the specified peer info and shared context */ ContextGL(PeerInfo peer_info, ContextAttribs attribs, ContextGL shared_context) throws LWJGLException { ContextGL context_lock = shared_context != null ? shared_context : this; @@ -120,8 +127,11 @@ final class ContextGL implements Context { */ forwardCompatible = false; - - this.handle = null; + long share = 0; + if(shared_context != null) { + share = shared_context.handle; + } + this.handle = GLFW.nativeEglCreateContext(share); // implementation.create(peer_info, attribList, shared_context != null ? shared_context.handle : null); /* } catch (LWJGLException e) { // GLContext.unloadOpenGLLibrary(); @@ -184,12 +194,13 @@ final class ContextGL implements Context { throw new IllegalStateException("Context is destroyed"); thread = Thread.currentThread(); current_context_local.set(this); - GLFW.glfwMakeContextCurrent(Display.Window.handle); + GLFW.glfwMakeContextCurrent(handle); + GLContext.initCapabilities(); isCurrent = true; } ByteBuffer getHandle() { - return handle; + return null; } /** Query whether the context is current */ @@ -208,7 +219,7 @@ final class ContextGL implements Context { destroyed = true; thread = null; // GLContext.unloadOpenGLLibrary(); - + Display.destroy(); } catch (LWJGLException e) { LWJGLUtil.log("Exception occurred while destroying context: " + e); diff --git a/jre_lwjgl3glfw/src/main/java/org/lwjgl/opengl/Display.java b/jre_lwjgl3glfw/src/main/java/org/lwjgl/opengl/Display.java index dd00be706..4fd855183 100644 --- a/jre_lwjgl3glfw/src/main/java/org/lwjgl/opengl/Display.java +++ b/jre_lwjgl3glfw/src/main/java/org/lwjgl/opengl/Display.java @@ -412,7 +412,7 @@ public class Display { } } }; - drawable.context = new ContextGL(null, null, null); + drawable.context = new ContextGL(Window.handle); drawable.context.makeCurrent(); Display.drawable = drawable; context = org.lwjgl.opengl.GLContext.createFromCurrent(); diff --git a/jre_lwjgl3glfw/src/main/java/org/lwjgl/opengl/GLContext.java b/jre_lwjgl3glfw/src/main/java/org/lwjgl/opengl/GLContext.java index d68aac1ed..913a83833 100644 --- a/jre_lwjgl3glfw/src/main/java/org/lwjgl/opengl/GLContext.java +++ b/jre_lwjgl3glfw/src/main/java/org/lwjgl/opengl/GLContext.java @@ -3,13 +3,18 @@ package org.lwjgl.opengl; public class GLContext { - private static ContextCapabilities contextCapabilities = new ContextCapabilities(); + private static ThreadLocal contextCapabilities = new ThreadLocal<>(); public static GLContext createFromCurrent() { return new GLContext(); } - + public static void initCapabilities() { + if(contextCapabilities.get() == null) { + System.out.println("LWJGLX: GL caps init"); + contextCapabilities.set(new ContextCapabilities()); + } + } public static ContextCapabilities getCapabilities() { - return contextCapabilities; + return contextCapabilities.get(); } }