mirror of
https://github.com/shadowfacts/lwjgl2-arm64.git
synced 2026-04-05 06:25:46 +00:00
Implemented reference counted loading of gl library in java
This commit is contained in:
parent
b07143f400
commit
1827f0efd4
8 changed files with 82 additions and 49 deletions
|
|
@ -508,19 +508,29 @@ public final class Display {
|
|||
throw new IllegalStateException("Only one LWJGL context may be instantiated at any one time.");
|
||||
if (fullscreen)
|
||||
switchDisplayMode(current_mode);
|
||||
createContext(pixel_format);
|
||||
context = new Display();
|
||||
try {
|
||||
createWindow();
|
||||
GLContext.loadOpenGLLibrary();
|
||||
try {
|
||||
createContext(pixel_format);
|
||||
try {
|
||||
context = new Display();
|
||||
createWindow();
|
||||
makeCurrent();
|
||||
initContext();
|
||||
} catch (LWJGLException e) {
|
||||
destroyContext();
|
||||
context = null;
|
||||
throw e;
|
||||
}
|
||||
} catch (LWJGLException e) {
|
||||
GLContext.unloadOpenGLLibrary();
|
||||
throw e;
|
||||
}
|
||||
} catch (LWJGLException e) {
|
||||
destroyContext();
|
||||
context = null;
|
||||
if (fullscreen)
|
||||
resetDisplayMode();
|
||||
throw e;
|
||||
}
|
||||
makeCurrent();
|
||||
initContext();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -595,6 +605,7 @@ public final class Display {
|
|||
|
||||
destroyWindow();
|
||||
destroyContext();
|
||||
GLContext.unloadOpenGLLibrary();
|
||||
context = null;
|
||||
try {
|
||||
GLContext.useContext(null);
|
||||
|
|
|
|||
|
|
@ -183,6 +183,8 @@ public final class GLContext {
|
|||
|
||||
/** Map of classes that have native stubs loaded */
|
||||
private static Map exts;
|
||||
private static int gl_ref_count = 0;
|
||||
private static boolean did_auto_load = false;
|
||||
|
||||
static {
|
||||
Sys.initialize();
|
||||
|
|
@ -228,6 +230,8 @@ public final class GLContext {
|
|||
public static synchronized void useContext(Object context) throws LWJGLException {
|
||||
if (context == null) {
|
||||
unloadStubs();
|
||||
if (did_auto_load)
|
||||
unloadOpenGLLibrary();
|
||||
return;
|
||||
}
|
||||
// Is this the same as last time?
|
||||
|
|
@ -238,11 +242,19 @@ public final class GLContext {
|
|||
}
|
||||
|
||||
// Ok, now it's the current context.
|
||||
loadOpenGLLibrary();
|
||||
GL11.initNativeStubs();
|
||||
loadStubs();
|
||||
currentContext = new WeakReference(context);
|
||||
VBOTracker.setCurrent(currentContext);
|
||||
if (gl_ref_count == 0) {
|
||||
loadOpenGLLibrary();
|
||||
did_auto_load = true;
|
||||
}
|
||||
try {
|
||||
GL11.initNativeStubs();
|
||||
loadStubs();
|
||||
currentContext = new WeakReference(context);
|
||||
VBOTracker.setCurrent(currentContext);
|
||||
} catch (LWJGLException e) {
|
||||
if (did_auto_load)
|
||||
unloadOpenGLLibrary();
|
||||
}
|
||||
}
|
||||
|
||||
private static void getExtensionClassesAndNames(Map exts, Set exts_names) {
|
||||
|
|
@ -338,9 +350,28 @@ public final class GLContext {
|
|||
}
|
||||
|
||||
/**
|
||||
* Native method to load the OpenGL library
|
||||
* If the OpenGL reference count is 0, the library is loaded. The
|
||||
* reference count is then incremented.
|
||||
*/
|
||||
private static native void loadOpenGLLibrary();
|
||||
public static void loadOpenGLLibrary() throws LWJGLException {
|
||||
if (gl_ref_count == 0)
|
||||
nLoadOpenGLLibrary();
|
||||
gl_ref_count++;
|
||||
}
|
||||
|
||||
private static native void nLoadOpenGLLibrary() throws LWJGLException;
|
||||
|
||||
/**
|
||||
* The OpenGL library reference count is decremented, and if it
|
||||
* reaches 0, the library is unloaded.
|
||||
*/
|
||||
public static void unloadOpenGLLibrary() {
|
||||
gl_ref_count--;
|
||||
if (gl_ref_count == 0)
|
||||
nUnloadOpenGLLibrary();
|
||||
}
|
||||
|
||||
private static native void nUnloadOpenGLLibrary();
|
||||
|
||||
/**
|
||||
* Native method to clear native stub bindings
|
||||
|
|
|
|||
|
|
@ -97,6 +97,7 @@ public class PbufferTest {
|
|||
private void initialize() {
|
||||
try {
|
||||
//find displaymode
|
||||
pbuffer = new Pbuffer(512, 512, new PixelFormat(), null);
|
||||
mode = findDisplayMode(800, 600, 16);
|
||||
Display.setDisplayMode(mode);
|
||||
// start of in windowed mode
|
||||
|
|
@ -175,7 +176,12 @@ public class PbufferTest {
|
|||
if (pbuffer.isBufferLost()) {
|
||||
System.out.println("Buffer contents lost - will recreate the buffer");
|
||||
pbuffer.destroy();
|
||||
initPbuffer();
|
||||
try {
|
||||
pbuffer = new Pbuffer(512, 512, new PixelFormat(), null);
|
||||
initPbuffer();
|
||||
} catch (LWJGLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
try {
|
||||
pbuffer.makeCurrent();
|
||||
|
|
@ -235,7 +241,6 @@ public class PbufferTest {
|
|||
|
||||
private void initPbuffer() {
|
||||
try {
|
||||
pbuffer = new Pbuffer(512, 512, new PixelFormat(), null);
|
||||
pbuffer.makeCurrent();
|
||||
initGLState(256, 256, 0.5f);
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, tex_handle);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue