diff options
Diffstat (limited to 'src/jogl/classes/javax')
6 files changed, 138 insertions, 145 deletions
diff --git a/src/jogl/classes/javax/media/opengl/GLContext.java b/src/jogl/classes/javax/media/opengl/GLContext.java index efc914de9..21c1b96a0 100644 --- a/src/jogl/classes/javax/media/opengl/GLContext.java +++ b/src/jogl/classes/javax/media/opengl/GLContext.java @@ -278,10 +278,17 @@ public abstract class GLContext { /** * Classname, GL, GLDrawable */ - public final String toString() { + public String toString() { StringBuffer sb = new StringBuffer(); sb.append(getClass().getName()); - sb.append(" [OpenGL "); + sb.append(" ["); + this.append(sb); + sb.append("] "); + return sb.toString(); + } + + public final StringBuffer append(StringBuffer sb) { + sb.append("OpenGL "); sb.append(getGLVersionMajor()); sb.append("."); sb.append(getGLVersionMinor()); @@ -289,6 +296,8 @@ public abstract class GLContext { sb.append(Integer.toHexString(ctxOptions)); sb.append(", "); sb.append(getGLVersion()); + sb.append(", handle "); + sb.append(toHexString(contextHandle)); sb.append(", "); sb.append(getGL()); if(getGLDrawable()!=getGLDrawableRead()) { @@ -300,8 +309,7 @@ public abstract class GLContext { sb.append(",\n\tDrawable Read/Write: "); sb.append(getGLDrawable()); } - sb.append("] "); - return sb.toString(); + return sb; } /** Returns a non-null (but possibly empty) string containing the diff --git a/src/jogl/classes/javax/media/opengl/GLDrawable.java b/src/jogl/classes/javax/media/opengl/GLDrawable.java index 469cc5170..46296ca52 100644 --- a/src/jogl/classes/javax/media/opengl/GLDrawable.java +++ b/src/jogl/classes/javax/media/opengl/GLDrawable.java @@ -157,6 +157,15 @@ public interface GLDrawable { public NativeWindow getNativeWindow(); + /** + * This is the GL/Windowing drawable handle.<br> + * It is usually the {@link javax.media.nativewindow.NativeWindow#getSurfaceHandle()}, + * ie the native surface handle of the underlying windowing toolkit.<br> + * However, on X11/GLX this reflects a GLXDrawable, which represents a GLXWindow, GLXPixmap, or GLXPbuffer.<br> + * On EGL, this represents the EGLSurface.<br> + */ + public long getHandle(); + public GLDrawableFactory getFactory(); public String toString(); diff --git a/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java b/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java index ca6bc7564..81c7d4b4a 100644 --- a/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java +++ b/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java @@ -95,20 +95,9 @@ public abstract class GLDrawableFactory { * Instantiate singleton factories if available, EGLES1, EGLES2 and the OS native ones. */ static { - GLDrawableFactory tmp = null; - try { - tmp = (GLDrawableFactory) ReflectionUtil.createInstance("com.jogamp.opengl.impl.egl.EGLDrawableFactory"); - } catch (JogampRuntimeException jre) { - if (GLProfile.DEBUG) { - System.err.println("GLDrawableFactory.static - EGLDrawableFactory - not available"); - jre.printStackTrace(); - } - } - eglFactory = tmp; - nativeOSType = NativeWindowFactory.getNativeWindowType(true); - tmp = null; + GLDrawableFactory tmp = null; String factoryClassName = Debug.getProperty("jogl.gldrawablefactory.class.name", true, AccessController.getContext()); if (null == factoryClassName) { if ( nativeOSType.equals(NativeWindowFactory.TYPE_X11) ) { @@ -142,6 +131,17 @@ public abstract class GLDrawableFactory { } } nativeOSFactory = tmp; + + tmp = null; + try { + tmp = (GLDrawableFactory) ReflectionUtil.createInstance("com.jogamp.opengl.impl.egl.EGLDrawableFactory"); + } catch (JogampRuntimeException jre) { + if (GLProfile.DEBUG) { + System.err.println("GLDrawableFactory.static - EGLDrawableFactory - not available"); + jre.printStackTrace(); + } + } + eglFactory = tmp; } /** diff --git a/src/jogl/classes/javax/media/opengl/GLProfile.java b/src/jogl/classes/javax/media/opengl/GLProfile.java index d746101ca..3d0f4a3ce 100644 --- a/src/jogl/classes/javax/media/opengl/GLProfile.java +++ b/src/jogl/classes/javax/media/opengl/GLProfile.java @@ -37,9 +37,13 @@ package javax.media.opengl; import com.jogamp.common.util.*; -import com.jogamp.opengl.impl.DRIHack; import com.jogamp.opengl.impl.Debug; import com.jogamp.opengl.impl.GLJNILibLoader; +import com.jogamp.opengl.impl.GLDrawableFactoryImpl; +import com.jogamp.opengl.impl.GLDynamicLookupHelper; +import com.jogamp.opengl.impl.GLDynamicLibraryBundleInfo; +import com.jogamp.opengl.impl.DesktopGLDynamicLookupHelper; +import com.jogamp.opengl.impl.DesktopGLDynamicLibraryBundleInfo; import com.jogamp.common.jvm.JVMUtil; import java.util.HashMap; import java.util.Iterator; @@ -858,102 +862,62 @@ public class GLProfile implements Cloneable { AccessController.doPrivileged(new PrivilegedAction() { public Object run() { - JVMUtil.initSingleton(); + NativeWindowFactory.initSingleton(); AccessControlContext acc = AccessController.getContext(); isAWTAvailable = NativeWindowFactory.isAWTAvailable() && ReflectionUtil.isClassAvailable("javax.media.opengl.awt.GLCanvas") ; // JOGL - boolean hasDesktopGL = false; - boolean hasDesktopGLES12 = false; - boolean hasNativeOSFactory = false; - Throwable t; - - // - // First iteration of desktop GL availability detection - // - native libs exist - // - class exists - // - t=null; - try { - // See DRIHack.java for an explanation of why this is necessary - DRIHack.begin(); - GLJNILibLoader.loadGLDesktop(); - DRIHack.end(); - hasDesktopGL = true; - } catch (UnsatisfiedLinkError ule) { - t=ule; - } catch (SecurityException se) { - t=se; - } catch (NullPointerException npe) { - t=npe; - } catch (RuntimeException re) { - t=re; - } - if(null!=t) { - if (DEBUG) { - System.err.println("GLProfile.static Desktop GL Library not available"); - t.printStackTrace(); - } - } - - t=null; - try { - // See DRIHack.java for an explanation of why this is necessary - DRIHack.begin(); - GLJNILibLoader.loadGLDesktopES12(); - DRIHack.end(); - hasDesktopGLES12 = true; - } catch (UnsatisfiedLinkError ule) { - t=ule; - } catch (SecurityException se) { - t=se; - } catch (NullPointerException npe) { - t=npe; - } catch (RuntimeException re) { - t=re; - } - if(DEBUG && null!=t) { - System.err.println("GLProfile.static Desktop GLES12 Library not available"); - t.printStackTrace(); - } - - - hasGL234Impl = hasDesktopGL && ReflectionUtil.isClassAvailable("com.jogamp.opengl.impl.gl4.GL4bcImpl"); + hasGL234Impl = ReflectionUtil.isClassAvailable("com.jogamp.opengl.impl.gl4.GL4bcImpl"); hasGL4bcImpl = hasGL234Impl; hasGL4Impl = hasGL234Impl; hasGL3bcImpl = hasGL234Impl; hasGL3Impl = hasGL234Impl; hasGL2Impl = hasGL234Impl; - hasGL2ES12Impl = hasDesktopGLES12 && ReflectionUtil.isClassAvailable("com.jogamp.opengl.impl.gl2es12.GL2ES12Impl"); + hasGL2ES12Impl = ReflectionUtil.isClassAvailable("com.jogamp.opengl.impl.gl2es12.GL2ES12Impl"); mappedProfiles = computeProfileMap(); + boolean hasDesktopGL = false; + boolean hasDesktopGLES12 = false; + boolean hasNativeOSFactory = false; + Throwable t; + // - // Second iteration of desktop GL availability detection + // Iteration of desktop GL availability detection // utilizing the detected GL version in the shared context. // // - Instantiate GLDrawableFactory incl its shared dummy drawable/context, // which will register at GLContext .. // - if(hasDesktopGL||hasDesktopGLES12) { - t=null; - // if successfull it has a shared dummy drawable and context created - try { - hasNativeOSFactory = null != GLDrawableFactory.getFactoryImpl(GL2); - } catch (LinkageError le) { - t=le; - } catch (RuntimeException re) { - t=re; + t=null; + // if successfull it has a shared dummy drawable and context created + try { + GLDrawableFactoryImpl factory = (GLDrawableFactoryImpl) GLDrawableFactory.getFactoryImpl(GL2); + hasNativeOSFactory = null != factory; + if(hasNativeOSFactory) { + DesktopGLDynamicLookupHelper glLookupHelper = (DesktopGLDynamicLookupHelper) factory.getGLDynamicLookupHelper(0); + if(null!=glLookupHelper) { + hasDesktopGL = glLookupHelper.hasGLBinding(); + hasDesktopGLES12 = glLookupHelper.hasGLES12Binding(); + } } - if(DEBUG && null!=t) { - System.err.println("GLProfile.static - Native platform GLDrawable factory not available"); + } catch (LinkageError le) { + t=le; + } catch (RuntimeException re) { + t=re; + } + if(DEBUG) { + if(null!=t) { t.printStackTrace(); } + if(!hasNativeOSFactory) { + System.err.println("GLProfile.static - Native platform GLDrawable factory not available"); + } } - if(hasNativeOSFactory && !GLContext.mappedVersionsAvailableSet) { + if(hasDesktopGL && !GLContext.mappedVersionsAvailableSet) { // nobody yet set the available desktop versions, see {@link GLContextImpl#makeCurrent}, // so we have to add the usual suspect GLContext.mapVersionAvailable(2, GLContext.CTX_PROFILE_COMPAT, 1, 5, GLContext.CTX_PROFILE_COMPAT|GLContext.CTX_OPTION_ANY); @@ -977,16 +941,20 @@ public class GLProfile implements Cloneable { hasGL2ES12Impl = hasGL2ES12Impl && GLContext.isGL2Available(); } - boolean hasEGLDynLookup = ReflectionUtil.isClassAvailable("com.jogamp.opengl.impl.egl.EGLDynamicLookupHelper"); - boolean hasEGLDrawableFactory = false; - boolean btest = false; - if(hasEGLDynLookup) { + if ( ReflectionUtil.isClassAvailable("com.jogamp.opengl.impl.egl.EGLDrawableFactory") ) { t=null; try { - hasEGLDrawableFactory = null!=GLDrawableFactory.getFactoryImpl(GLES2); - btest = hasEGLDrawableFactory && - ReflectionUtil.isClassAvailable("com.jogamp.opengl.impl.es2.GLES2Impl") && - null!=com.jogamp.opengl.impl.egl.EGLDynamicLookupHelper.getDynamicLookupHelper(2); + GLDrawableFactoryImpl factory = (GLDrawableFactoryImpl) GLDrawableFactory.getFactoryImpl(GLES2); + if(null != factory) { + GLDynamicLookupHelper eglLookupHelper = factory.getGLDynamicLookupHelper(2); + if(null!=eglLookupHelper) { + hasGLES2Impl = eglLookupHelper.isLibComplete(); + } + eglLookupHelper = factory.getGLDynamicLookupHelper(1); + if(null!=eglLookupHelper) { + hasGLES1Impl = eglLookupHelper.isLibComplete(); + } + } } catch (LinkageError le) { t=le; } catch (SecurityException se) { @@ -997,37 +965,12 @@ public class GLProfile implements Cloneable { t=re; } if(DEBUG && null!=t) { - System.err.println("GLProfile.static - GL ES2 Factory/Library not available"); t.printStackTrace(); } } - hasGLES2Impl = btest; if(hasGLES2Impl) { GLContext.mapVersionAvailable(2, GLContext.CTX_PROFILE_ES, 2, 0, GLContext.CTX_PROFILE_ES|GLContext.CTX_OPTION_ANY); } - - btest = false; - if(hasEGLDynLookup) { - t=null; - try { - btest = hasEGLDrawableFactory && - ReflectionUtil.isClassAvailable("com.jogamp.opengl.impl.es1.GLES1Impl") && - null!=com.jogamp.opengl.impl.egl.EGLDynamicLookupHelper.getDynamicLookupHelper(1); - } catch (LinkageError le) { - t=le; - } catch (SecurityException se) { - t=se; - } catch (NullPointerException npe) { - t=npe; - } catch (RuntimeException re) { - t=re; - } - if(DEBUG && null!=t) { - System.err.println("GLProfile.static - GL ES1 Factory/Library not available"); - t.printStackTrace(); - } - } - hasGLES1Impl = btest; if(hasGLES1Impl) { GLContext.mapVersionAvailable(1, GLContext.CTX_PROFILE_ES, 1, 0, GLContext.CTX_PROFILE_ES|GLContext.CTX_OPTION_ANY); } @@ -1039,8 +982,6 @@ public class GLProfile implements Cloneable { System.err.println("GLProfile.static hasNativeOSFactory "+hasNativeOSFactory); System.err.println("GLProfile.static hasDesktopGL "+hasDesktopGL); System.err.println("GLProfile.static hasDesktopGLES12 "+hasDesktopGLES12); - System.err.println("GLProfile.static hasEGLDynLookup "+hasEGLDynLookup); - System.err.println("GLProfile.static hasEGLDrawableFactory "+hasEGLDrawableFactory); System.err.println("GLProfile.static hasGL234Impl "+hasGL234Impl); System.err.println("GLProfile.static "+glAvailabilityToString()); } @@ -1054,6 +995,15 @@ public class GLProfile implements Cloneable { } } + /** + * It is mandatory to call this methods ASAP, before anything else.<br> + * You may issue the call in your main class static initializer block, or in the static main function.<br> + * This will kick off JOGL's static initialization.<br> + * It is essential to do this at the very beginning, so JOGL has a chance to initialize multithreading support.<br> + */ + public static void initSingleton() { + } + private static final String list2String(String[] list) { StringBuffer msg = new StringBuffer(); msg.append("["); diff --git a/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java b/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java index 9932f0cf9..77b8e45d3 100644 --- a/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java +++ b/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java @@ -44,6 +44,7 @@ import javax.media.nativewindow.*; import javax.media.nativewindow.awt.*; import com.jogamp.opengl.impl.*; +import com.jogamp.nativewindow.impl.jawt.JAWTUtil; import java.awt.Canvas; import java.awt.Color; @@ -73,9 +74,15 @@ import java.security.*; public class GLCanvas extends Canvas implements AWTGLAutoDrawable { - private static final boolean DEBUG = Debug.debug("GLCanvas"); + private static final boolean DEBUG; + private static final GLProfile defaultGLProfile; + + static { + NativeWindowFactory.initSingleton(); + defaultGLProfile = GLProfile.getDefault(); + DEBUG = Debug.debug("GLCanvas"); + } - static private GLProfile defaultGLProfile = GLProfile.getDefault(); private GLProfile glProfile; private GLDrawableHelper drawableHelper = new GLDrawableHelper(); private GraphicsConfiguration chosen; @@ -320,11 +327,13 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable { // The user really should not be invoking remove() from this // thread -- but since he/she is, we can not go over to the // EDT at this point. Try to destroy the context from here. - drawableHelper.invokeGL(drawable, context, disposeAction, null); - } else { + if(context.isCreated()) { + drawableHelper.invokeGL(drawable, context, disposeAction, null); + } + } else if(context.isCreated()) { Threading.invokeOnOpenGLThread(disposeOnEventDispatchThreadAction); } - } else { + } else if(context.isCreated()) { drawableHelper.invokeGL(drawable, context, disposeAction, null); } @@ -394,22 +403,27 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable { /* * Save the chosen capabilities for use in getGraphicsConfiguration(). */ - awtConfig = chooseGraphicsConfiguration(capabilities, chooser, device); - if(DEBUG) { - Exception e = new Exception("Created Config: "+awtConfig); - e.printStackTrace(); - } - if(null!=awtConfig) { - // update .. - chosen = awtConfig.getGraphicsConfiguration(); + JAWTUtil.lockToolkit(); + try { + awtConfig = chooseGraphicsConfiguration(capabilities, chooser, device); + if(DEBUG) { + Exception e = new Exception("Created Config: "+awtConfig); + e.printStackTrace(); + } + if(null!=awtConfig) { + // update .. + chosen = awtConfig.getGraphicsConfiguration(); + } + if(null==awtConfig) { + throw new GLException("Error: AWTGraphicsConfiguration is null"); + } + drawable = GLDrawableFactory.getFactory(glProfile).createGLDrawable(NativeWindowFactory.getNativeWindow(this, awtConfig)); + context = (GLContextImpl) drawable.createContext(shareWith); + context.setSynchronized(true); + } finally { + JAWTUtil.unlockToolkit(); } - if(null==awtConfig) { - throw new GLException("Error: AWTGraphicsConfiguration is null"); - } - drawable = GLDrawableFactory.getFactory(glProfile).createGLDrawable(NativeWindowFactory.getNativeWindow(this, awtConfig)); - context = (GLContextImpl) drawable.createContext(shareWith); - context.setSynchronized(true); if(DEBUG) { System.err.println("Created Drawable: "+drawable); @@ -536,6 +550,10 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable { return drawable.getNativeWindow(); } + public long getHandle() { + return drawable.getHandle(); + } + public GLDrawableFactory getFactory() { return drawable.getFactory(); } diff --git a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java index eb8c68263..955949415 100644 --- a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java +++ b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java @@ -137,6 +137,8 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable { private int viewportY; static { + NativeWindowFactory.initSingleton(); + // Force eager initialization of part of the Java2D class since // otherwise it's likely it will try to be initialized while on // the Queue Flusher Thread, which is not allowed @@ -227,11 +229,13 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable { // The user really should not be invoking remove() from this // thread -- but since he/she is, we can not go over to the // EDT at this point. Try to destroy the context from here. - drawableHelper.invokeGL(disposeDrawable, disposeContext, disposeAction, null); - } else { + if(disposeContext.isCreated()) { + drawableHelper.invokeGL(disposeDrawable, disposeContext, disposeAction, null); + } + } else if(disposeContext.isCreated()) { Threading.invokeOnOpenGLThread(disposeOnEventDispatchThreadAction); } - } else { + } else if(disposeContext.isCreated()) { drawableHelper.invokeGL(disposeDrawable, disposeContext, disposeAction, null); } @@ -467,6 +471,10 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable { throw new GLException("FIXME"); } + public long getHandle() { + throw new GLException("FIXME"); + } + public final GLDrawableFactory getFactory() { return factory; } |