Multi-context

This commit is contained in:
artdeell 2021-07-31 14:58:58 +03:00
parent 55b31833c4
commit 02378b9ba2
4 changed files with 28 additions and 12 deletions

View File

@ -96,7 +96,7 @@ public final class Tools {
if(pvcConfig != null && pvcConfig.gamePath != null && !pvcConfig.gamePath.isEmpty()) gamedirPath = pvcConfig.gamePath; if(pvcConfig != null && pvcConfig.gamePath != null && !pvcConfig.gamePath.isEmpty()) gamedirPath = pvcConfig.gamePath;
else gamedirPath = Tools.DIR_GAME_NEW; else gamedirPath = Tools.DIR_GAME_NEW;
if(pvcConfig != null && pvcConfig.jvmArgs != null && !pvcConfig.jvmArgs.isEmpty()) LauncherPreferences.PREF_CUSTOM_JAVA_ARGS = pvcConfig.jvmArgs; 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); String[] launchArgs = getMinecraftArgs(profile, versionInfo, gamedirPath);
// ctx.appendlnToLog("Minecraft Args: " + Arrays.toString(launchArgs)); // ctx.appendlnToLog("Minecraft Args: " + Arrays.toString(launchArgs));

View File

@ -63,7 +63,8 @@ final class ContextGL implements Context {
private static final ThreadLocal<ContextGL> current_context_local = new ThreadLocal<ContextGL>(); private static final ThreadLocal<ContextGL> current_context_local = new ThreadLocal<ContextGL>();
/** Handle to the native GL rendering context */ /** 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 PeerInfo peer_info;
private final ContextAttribs contextAttribs; private final ContextAttribs contextAttribs;
@ -95,7 +96,13 @@ final class ContextGL implements Context {
static ContextGL getCurrentContext() { static ContextGL getCurrentContext() {
return current_context_local.get(); 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 */ /** Create a context with the specified peer info and shared context */
ContextGL(PeerInfo peer_info, ContextAttribs attribs, ContextGL shared_context) throws LWJGLException { ContextGL(PeerInfo peer_info, ContextAttribs attribs, ContextGL shared_context) throws LWJGLException {
ContextGL context_lock = shared_context != null ? shared_context : this; ContextGL context_lock = shared_context != null ? shared_context : this;
@ -120,8 +127,11 @@ final class ContextGL implements Context {
*/ */
forwardCompatible = false; forwardCompatible = false;
long share = 0;
this.handle = null; 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); // implementation.create(peer_info, attribList, shared_context != null ? shared_context.handle : null);
/* } catch (LWJGLException e) { /* } catch (LWJGLException e) {
// GLContext.unloadOpenGLLibrary(); // GLContext.unloadOpenGLLibrary();
@ -184,12 +194,13 @@ final class ContextGL implements Context {
throw new IllegalStateException("Context is destroyed"); throw new IllegalStateException("Context is destroyed");
thread = Thread.currentThread(); thread = Thread.currentThread();
current_context_local.set(this); current_context_local.set(this);
GLFW.glfwMakeContextCurrent(Display.Window.handle); GLFW.glfwMakeContextCurrent(handle);
GLContext.initCapabilities();
isCurrent = true; isCurrent = true;
} }
ByteBuffer getHandle() { ByteBuffer getHandle() {
return handle; return null;
} }
/** Query whether the context is current */ /** Query whether the context is current */
@ -208,7 +219,7 @@ final class ContextGL implements Context {
destroyed = true; destroyed = true;
thread = null; thread = null;
// GLContext.unloadOpenGLLibrary(); // GLContext.unloadOpenGLLibrary();
Display.destroy(); Display.destroy();
} catch (LWJGLException e) { } catch (LWJGLException e) {
LWJGLUtil.log("Exception occurred while destroying context: " + e); LWJGLUtil.log("Exception occurred while destroying context: " + e);

View File

@ -412,7 +412,7 @@ public class Display {
} }
} }
}; };
drawable.context = new ContextGL(null, null, null); drawable.context = new ContextGL(Window.handle);
drawable.context.makeCurrent(); drawable.context.makeCurrent();
Display.drawable = drawable; Display.drawable = drawable;
context = org.lwjgl.opengl.GLContext.createFromCurrent(); context = org.lwjgl.opengl.GLContext.createFromCurrent();

View File

@ -3,13 +3,18 @@ package org.lwjgl.opengl;
public class GLContext { public class GLContext {
private static ContextCapabilities contextCapabilities = new ContextCapabilities(); private static ThreadLocal<ContextCapabilities> contextCapabilities = new ThreadLocal<>();
public static GLContext createFromCurrent() { public static GLContext createFromCurrent() {
return new GLContext(); 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() { public static ContextCapabilities getCapabilities() {
return contextCapabilities; return contextCapabilities.get();
} }
} }