diff options
4 files changed, 39 insertions, 19 deletions
diff --git a/src/jogl/classes/javax/media/opengl/GLContext.java b/src/jogl/classes/javax/media/opengl/GLContext.java index 20930bd42..0727dad1b 100644 --- a/src/jogl/classes/javax/media/opengl/GLContext.java +++ b/src/jogl/classes/javax/media/opengl/GLContext.java @@ -756,6 +756,11 @@ public abstract class GLContext { } } } + + protected static void shutdown() { + deviceVersionAvailable.clear(); + deviceVersionsAvailableSet.clear(); + } /** * Called by {@link jogamp.opengl.GLContextImpl#createContextARBMapVersionsAvailable} not intended to be used by diff --git a/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java b/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java index 9bb9480c7..1282eb168 100644 --- a/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java +++ b/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java @@ -90,11 +90,13 @@ import javax.media.nativewindow.ProxySurface; public abstract class GLDrawableFactory { - private static final GLDrawableFactory eglFactory; - private static final GLDrawableFactory nativeOSFactory; private static final String nativeOSType; static final String macosxFactoryClassNameCGL = "jogamp.opengl.macosx.cgl.MacOSXCGLDrawableFactory"; static final String macosxFactoryClassNameAWTCGL = "jogamp.opengl.macosx.cgl.awt.MacOSXAWTCGLDrawableFactory"; + + private static volatile boolean initialized = false; + private static GLDrawableFactory eglFactory; + private static GLDrawableFactory nativeOSFactory; protected static ArrayList<GLDrawableFactory> glDrawableFactories = new ArrayList<GLDrawableFactory>(); @@ -106,15 +108,15 @@ public abstract class GLDrawableFactory { * Instantiate singleton factories if available, EGLES1, EGLES2 and the OS native ones. */ static { - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - registerFactoryShutdownHook(); - return null; - } - }); - nativeOSType = NativeWindowFactory.getNativeWindowType(true); + } + protected static final void initialize() { + if(initialized) { return; } + initialized = true; + + registerFactoryShutdownHook(); + GLDrawableFactory tmp = null; String factoryClassName = Debug.getProperty("jogl.gldrawablefactory.class.name", true, AccessController.getContext()); ClassLoader cl = GLDrawableFactory.class.getClassLoader(); @@ -205,17 +207,13 @@ public abstract class GLDrawableFactory { } protected static void shutdown() { - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - unregisterFactoryShutdownHook(); - return null; - } - }); + unregisterFactoryShutdownHook(); shutdownImpl(); + eglFactory = null; + nativeOSFactory = null; + initialized = false; } - private AbstractGraphicsDevice defaultSharedDevice = null; - protected GLDrawableFactory() { synchronized(glDrawableFactories) { glDrawableFactories.add(this); diff --git a/src/jogl/classes/javax/media/opengl/GLProfile.java b/src/jogl/classes/javax/media/opengl/GLProfile.java index 1fd699dfd..a7231efc8 100644 --- a/src/jogl/classes/javax/media/opengl/GLProfile.java +++ b/src/jogl/classes/javax/media/opengl/GLProfile.java @@ -137,6 +137,7 @@ public class GLProfile { if(initialized) { initialized = false; GLDrawableFactory.shutdown(); + GLContext.shutdown(); } } @@ -1194,6 +1195,8 @@ public class GLProfile { // - Instantiate GLDrawableFactory incl its shared dummy drawable/context, // which will register at GLContext .. // + GLDrawableFactory.initialize(); + Throwable t=null; // if successfull it has a shared dummy drawable and context created try { @@ -1318,7 +1321,7 @@ public class GLProfile { // System.err.println(msg); } if(isSet) { - return null != GLProfile.getDefault(device); + return GLProfile.isAvailable(device, GL_DEFAULT); } boolean addedDesktopProfile = false; diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLProfile01NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLProfile01NEWT.java index 6f044e3d3..7813482e1 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLProfile01NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLProfile01NEWT.java @@ -56,7 +56,7 @@ public class TestGLProfile01NEWT extends UITestCase { System.err.println(NewtVersion.getInstance()); GLDrawableFactory factory = GLDrawableFactory.getFactory(GLProfile.getDefault()); - List/*<GLCapabilitiesImmutable>*/ availCaps = factory.getAvailableCapabilities(null); + List<GLCapabilitiesImmutable> availCaps = factory.getAvailableCapabilities(null); for(int i=0; i<availCaps.size(); i++) { System.err.println(availCaps.get(i)); } @@ -65,6 +65,9 @@ public class TestGLProfile01NEWT extends UITestCase { @Test public void test01GLProfileDefault() throws InterruptedException { System.out.println("GLProfile "+GLProfile.glAvailabilityToString()); + System.out.println("GLProfile.getDefaultDesktopDevice(): "+GLProfile.getDefaultDesktopDevice()); + System.out.println("GLProfile.getDefaultEGLDevice(): "+GLProfile.getDefaultEGLDevice()); + System.out.println("GLProfile.getDefaultDevice(): "+GLProfile.getDefaultDevice()); GLProfile glp = GLProfile.getDefault(); System.out.println("GLProfile.getDefault(): "+glp); if(glp.getName().equals(GLProfile.GL4bc)) { @@ -133,6 +136,17 @@ public class TestGLProfile01NEWT extends UITestCase { System.out.println("GLProfile GL2ES2: "+glp); dumpVersion(glp); } + + @Test + public void test06GLProfileShutdownRecreate() throws InterruptedException { + GLProfile.shutdown(); + GLProfile.initSingleton(true); + System.out.println("GLProfile.getDefault(): "+GLProfile.getDefault()); + System.out.println("GLProfile.getDefaultDesktopDevice(): "+GLProfile.getDefaultDesktopDevice()); + System.out.println("GLProfile.getDefaultEGLDevice(): "+GLProfile.getDefaultEGLDevice()); + System.out.println("GLProfile.getDefaultDevice(): "+GLProfile.getDefaultDevice()); + } + protected void dumpVersion(GLProfile glp) throws InterruptedException { GLCapabilities caps = new GLCapabilities(glp); |