diff --git a/.travis.yml b/.travis.yml
index 68668735c4..0eadda7688 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -6,7 +6,7 @@ language: java
# Configure the build to use Oracle JDK 9
jdk:
- - oraclejdk11
+ - openjdk11
# Install the Ant JUnit package, which is missing from the Travis CI environment. See the Travis documentation: https://docs.travis-ci.com/user/installing-dependencies/#Adding-APT-Packages
addons:
@@ -17,17 +17,11 @@ addons:
services:
- xvfb
-# Use xvfb to run tests that require a GUI and give it some time to start
-# before_script:
-# - "export DISPLAY=:99.0"
-# - "sh -e /etc/init.d/xvfb start"
-# - sleep 3
-
# Build the project
script:
- ant -f release-build.xml
-# Deployment has been disabled in preparation for the WorldWind project suspension on April 5, 2019
+# Deployment to be re-instated when WWJ is released.
#deploy:
# # Publish API documentation to GitHub Pages
# - provider: pages
diff --git a/gluegen-rt-natives-linux-amd64.jar b/gluegen-rt-natives-linux-amd64.jar
index e6df392ece..70716d0229 100644
Binary files a/gluegen-rt-natives-linux-amd64.jar and b/gluegen-rt-natives-linux-amd64.jar differ
diff --git a/gluegen-rt-natives-macosx-universal.jar b/gluegen-rt-natives-macosx-universal.jar
index 668a065c7f..38fd2e7df4 100644
Binary files a/gluegen-rt-natives-macosx-universal.jar and b/gluegen-rt-natives-macosx-universal.jar differ
diff --git a/gluegen-rt-natives-windows-amd64.jar b/gluegen-rt-natives-windows-amd64.jar
index 1d4e1c9d77..c2d949926d 100644
Binary files a/gluegen-rt-natives-windows-amd64.jar and b/gluegen-rt-natives-windows-amd64.jar differ
diff --git a/gluegen-rt.jar b/gluegen-rt.jar
index 2ab5d0488e..ac720c3e6b 100644
Binary files a/gluegen-rt.jar and b/gluegen-rt.jar differ
diff --git a/gluegen.LICENSE.txt b/gluegen.LICENSE.txt
index 1b21c36ecd..4ab32a1f75 100644
--- a/gluegen.LICENSE.txt
+++ b/gluegen.LICENSE.txt
@@ -23,7 +23,7 @@ by the generated and deployed GlueGen binaries.
L.1) The GlueGen source tree contains code from the JogAmp Community
which is covered by the Simplified BSD 2-clause license:
- Copyright 2010 JogAmp Community. All rights reserved.
+ Copyright 2010 - 2019 JogAmp Community. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are
permitted provided that the following conditions are met:
diff --git a/jogl-all-natives-linux-amd64.jar b/jogl-all-natives-linux-amd64.jar
index cbaf44c96e..f76fca8228 100644
Binary files a/jogl-all-natives-linux-amd64.jar and b/jogl-all-natives-linux-amd64.jar differ
diff --git a/jogl-all-natives-macosx-universal.jar b/jogl-all-natives-macosx-universal.jar
index 4614d08a14..198f4a16b2 100644
Binary files a/jogl-all-natives-macosx-universal.jar and b/jogl-all-natives-macosx-universal.jar differ
diff --git a/jogl-all-natives-windows-amd64.jar b/jogl-all-natives-windows-amd64.jar
index 64f4f27606..efd0264a22 100644
Binary files a/jogl-all-natives-windows-amd64.jar and b/jogl-all-natives-windows-amd64.jar differ
diff --git a/jogl-all.jar b/jogl-all.jar
index 4d27b9626f..28f2f87a76 100644
Binary files a/jogl-all.jar and b/jogl-all.jar differ
diff --git a/lib-external/jogl-gluegen/build-jogl.sh b/lib-external/jogl-gluegen/build-jogl.sh
index 3ba736bb55..75dc73ee5e 100755
--- a/lib-external/jogl-gluegen/build-jogl.sh
+++ b/lib-external/jogl-gluegen/build-jogl.sh
@@ -1,12 +1,6 @@
set -x
-cp patch/MacOSXJAWTWindow.java jogl/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx
-cp patch/MacOSXCGLContext.java jogl/src/jogl/classes/jogamp/opengl/macosx/cgl
-cp patch/GLCanvas.java jogl/src/jogl/classes/com/jogamp/opengl/awt
-
cd jogl/make
ant -Dtarget.sourcelevel=1.8 -Dtarget.targetlevel=1.8 -Dtarget.rt.jar=dummy.jar
-./jogl/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java
-
diff --git a/lib-external/jogl-gluegen/linux-copy-jogl.sh b/lib-external/jogl-gluegen/linux-copy-jogl.sh
index 2c5fbe85b5..0930845c10 100755
--- a/lib-external/jogl-gluegen/linux-copy-jogl.sh
+++ b/lib-external/jogl-gluegen/linux-copy-jogl.sh
@@ -2,7 +2,10 @@ set -x
cp gluegen/build/gluegen-rt-natives-linux-amd64.jar ../..
cp gluegen/build/gluegen-rt.jar ../..
+cp gluegen/LICENSE.txt ../../gluegen.LICENSE.txt
+
cp jogl/build/jar/jogl-all.jar ../..
cp jogl/build/jar/jogl-all-natives-linux-amd64.jar ../..
+cp jogl/LICENSE.txt ../../jogl.LICENSE.txt
diff --git a/lib-external/jogl-gluegen/osx-copy-jogl.sh b/lib-external/jogl-gluegen/osx-copy-jogl.sh
index e821ce9ea5..6c9461370b 100755
--- a/lib-external/jogl-gluegen/osx-copy-jogl.sh
+++ b/lib-external/jogl-gluegen/osx-copy-jogl.sh
@@ -1,8 +1,9 @@
set -x
cp gluegen/build/gluegen-rt-natives-macosx-universal.jar ../..
-cp gluegen/build/gluegen-rt.jar ../..
-cp jogl/build/jar/jogl-all.jar ../..
+# The other artifacts are copied by the Linux build.
+# cp gluegen/build/gluegen-rt.jar ../..
+# cp jogl/build/jar/jogl-all.jar ../..
cp jogl/build/jar/jogl-all-natives-macosx-universal.jar ../..
diff --git a/lib-external/jogl-gluegen/patch/GLCanvas.java b/lib-external/jogl-gluegen/patch/GLCanvas.java
deleted file mode 100644
index ff52527d41..0000000000
--- a/lib-external/jogl-gluegen/patch/GLCanvas.java
+++ /dev/null
@@ -1,1646 +0,0 @@
-/*
- * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
- * Copyright (c) 2010 JogAmp Community. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * - Redistribution of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistribution in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * Neither the name of Sun Microsystems, Inc. or the names of
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * This software is provided "AS IS," without a warranty of any kind. ALL
- * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
- * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
- * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
- * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
- * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
- * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
- * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
- * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
- * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
- * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
- * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
- *
- * You acknowledge that this software is not designed or intended for use
- * in the design, construction, operation or maintenance of any nuclear
- * facility.
- *
- * Sun gratefully acknowledges that this software was originally authored
- * and developed by Kenneth Bradley Russell and Christopher John Kline.
- */
-
-package com.jogamp.opengl.awt;
-
-import java.beans.Beans;
-import java.lang.reflect.Method;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.awt.Canvas;
-import java.awt.Color;
-import java.awt.FontMetrics;
-import java.awt.Frame;
-import java.awt.Graphics;
-import java.awt.Graphics2D;
-import java.awt.GraphicsConfiguration;
-import java.awt.GraphicsDevice;
-import java.awt.event.HierarchyEvent;
-import java.awt.event.HierarchyListener;
-import java.awt.geom.NoninvertibleTransformException;
-import java.awt.geom.Rectangle2D;
-import java.awt.EventQueue;
-import java.lang.reflect.InvocationTargetException;
-import java.util.ArrayList;
-import java.util.List;
-
-import com.jogamp.nativewindow.AbstractGraphicsConfiguration;
-import com.jogamp.nativewindow.OffscreenLayerOption;
-import com.jogamp.nativewindow.ScalableSurface;
-import com.jogamp.nativewindow.VisualIDHolder;
-import com.jogamp.nativewindow.WindowClosingProtocol;
-import com.jogamp.nativewindow.AbstractGraphicsDevice;
-import com.jogamp.nativewindow.AbstractGraphicsScreen;
-import com.jogamp.nativewindow.GraphicsConfigurationFactory;
-import com.jogamp.nativewindow.NativeSurface;
-import com.jogamp.nativewindow.NativeWindowFactory;
-import com.jogamp.opengl.GL;
-import com.jogamp.opengl.GLAnimatorControl;
-import com.jogamp.opengl.GLAutoDrawable;
-import com.jogamp.opengl.GLCapabilities;
-import com.jogamp.opengl.GLCapabilitiesChooser;
-import com.jogamp.opengl.GLCapabilitiesImmutable;
-import com.jogamp.opengl.GLContext;
-import com.jogamp.opengl.GLDrawable;
-import com.jogamp.opengl.GLDrawableFactory;
-import com.jogamp.opengl.GLEventListener;
-import com.jogamp.opengl.GLException;
-import com.jogamp.opengl.GLOffscreenAutoDrawable;
-import com.jogamp.opengl.GLProfile;
-import com.jogamp.opengl.GLRunnable;
-import com.jogamp.opengl.GLSharedContextSetter;
-import com.jogamp.opengl.Threading;
-
-import com.jogamp.common.GlueGenVersion;
-import com.jogamp.common.util.VersionUtil;
-import com.jogamp.common.util.awt.AWTEDTExecutor;
-import com.jogamp.common.util.locks.LockFactory;
-import com.jogamp.common.util.locks.RecursiveLock;
-import com.jogamp.nativewindow.awt.AWTGraphicsConfiguration;
-import com.jogamp.nativewindow.awt.AWTGraphicsDevice;
-import com.jogamp.nativewindow.awt.AWTGraphicsScreen;
-import com.jogamp.nativewindow.awt.AWTPrintLifecycle;
-import com.jogamp.nativewindow.awt.AWTWindowClosingProtocol;
-import com.jogamp.nativewindow.awt.JAWTWindow;
-import com.jogamp.opengl.JoglVersion;
-import com.jogamp.opengl.util.GLDrawableUtil;
-import com.jogamp.opengl.util.TileRenderer;
-
-import jogamp.nativewindow.SurfaceScaleUtils;
-import jogamp.opengl.Debug;
-import jogamp.opengl.GLContextImpl;
-import jogamp.opengl.GLDrawableHelper;
-import jogamp.opengl.GLDrawableImpl;
-import jogamp.opengl.awt.AWTTilePainter;
-
-// FIXME: Subclasses need to call resetGLFunctionAvailability() on their
-// context whenever the displayChanged() function is called on our
-// GLEventListeners
-
-/** A heavyweight AWT component which provides OpenGL rendering
- support. This is the primary implementation of an AWT {@link GLDrawable};
- {@link GLJPanel} is provided for compatibility with Swing user
- interfaces when adding a heavyweight doesn't work either because
- of Z-ordering or LayoutManager problems.
- *
- *
- *
- * {@link OffscreenLayerOption#setShallUseOffscreenLayer(boolean) setShallUseOffscreenLayer(true)}
- * maybe called to use an offscreen drawable (FBO or PBuffer) allowing
- * the underlying JAWT mechanism to composite the image, if supported.
- *
- * {@link OffscreenLayerOption#setShallUseOffscreenLayer(boolean) setShallUseOffscreenLayer(true)}
- * is being called if {@link GLCapabilitiesImmutable#isOnscreen()} is false
.
- *
- *
- *
- *
- * To avoid any conflicts with a potential Java2D OpenGL context,
- * you shall consider setting the following JVM properties:
- *
- * sun.java2d.opengl=false
- * sun.java2d.noddraw=true
- *
- * This is especially true in case you want to utilize a GLProfile other than
- * {@link GLProfile#GL2}, eg. using {@link GLProfile#getMaxFixedFunc()}.
- * On the other hand, if you like to experiment with GLJPanel's utilization
- * of Java2D's OpenGL pipeline, you have to set them to
- *
- * sun.java2d.opengl=true
- * sun.java2d.noddraw=true
- *
- *
- *
- *
- * GLCanvas tries to disable background erase for the AWT Canvas
- * before native peer creation (X11) and after it (Windows),
- * utilizing the optional {@link java.awt.Toolkit} method disableBeackgroundErase(java.awt.Canvas)
.
- * However if this does not give you the desired results, you may want to disable AWT background erase in general:
- *
- *
- *
- *
- * To share a {@link GLContext} see the following note in the documentation overview:
- * context sharing
- * as well as {@link GLSharedContextSetter}.
- *
- */
-
-@SuppressWarnings("serial")
-public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosingProtocol, OffscreenLayerOption,
- AWTPrintLifecycle, GLSharedContextSetter, ScalableSurface {
-
- private static final boolean DEBUG = Debug.debug("GLCanvas");
-
- private final RecursiveLock lock = LockFactory.createRecursiveLock();
- private final GLDrawableHelper helper = new GLDrawableHelper();
- private volatile GLDrawableImpl drawable; // volatile: avoid locking for read-only access
- private volatile JAWTWindow jawtWindow; // the JAWTWindow presentation of this AWT Canvas, bound to the 'drawable' lifecycle
- private volatile GLContextImpl context; // volatile: avoid locking for read-only access
- private volatile boolean sendReshape = false; // volatile: maybe written by EDT w/o locking
- private final float[] minPixelScale = new float[] { ScalableSurface.IDENTITY_PIXELSCALE, ScalableSurface.IDENTITY_PIXELSCALE };
- private final float[] maxPixelScale = new float[] { ScalableSurface.IDENTITY_PIXELSCALE, ScalableSurface.IDENTITY_PIXELSCALE };
- private final float[] hasPixelScale = new float[] { ScalableSurface.IDENTITY_PIXELSCALE, ScalableSurface.IDENTITY_PIXELSCALE };
- final float[] reqPixelScale = new float[] { ScalableSurface.AUTOMAX_PIXELSCALE, ScalableSurface.AUTOMAX_PIXELSCALE };
-
- // copy of the cstr args, mainly for recreation
- private final GLCapabilitiesImmutable capsReqUser;
- private final GLCapabilitiesChooser chooser;
- private int additionalCtxCreationFlags = 0;
- private boolean shallUseOffscreenLayer = false;
-
- private volatile GraphicsDevice awtDeviceReq; // one time user req.
- private volatile AWTGraphicsConfiguration awtConfig;
- private volatile boolean isShowing;
- private final HierarchyListener hierarchyListener = new HierarchyListener() {
- @Override
- public void hierarchyChanged(final HierarchyEvent e) {
- isShowing = GLCanvas.this.isShowing();
- }
- };
-
- private final AWTWindowClosingProtocol awtWindowClosingProtocol =
- new AWTWindowClosingProtocol(this, new Runnable() {
- @Override
- public void run() {
- GLCanvas.this.destroyImpl( true );
- }
- }, null);
-
- /** Creates a new GLCanvas component with a default set of OpenGL
- capabilities, using the default OpenGL capabilities selection
- mechanism, on the default screen device.
-
- See details about OpenGL context sharing .
-
- * @throws GLException if no default profile is available for the default desktop device.
- */
- public GLCanvas() throws GLException {
- this(null);
- }
-
- /** Creates a new GLCanvas component with the requested set of
- OpenGL capabilities, using the default OpenGL capabilities
- selection mechanism, on the default screen device.
-
- See details about OpenGL context sharing .
-
- * @throws GLException if no GLCapabilities are given and no default profile is available for the default desktop device.
- * @see GLCanvas#GLCanvas(com.jogamp.opengl.GLCapabilitiesImmutable, com.jogamp.opengl.GLCapabilitiesChooser, com.jogamp.opengl.GLContext, java.awt.GraphicsDevice)
- */
- public GLCanvas(final GLCapabilitiesImmutable capsReqUser) throws GLException {
- this(capsReqUser, null, null);
- }
-
- /** Creates a new GLCanvas component. The passed GLCapabilities
- specifies the OpenGL capabilities for the component; if null, a
- default set of capabilities is used. The GLCapabilitiesChooser
- specifies the algorithm for selecting one of the available
- GLCapabilities for the component; a DefaultGLCapabilitesChooser
- is used if null is passed for this argument.
- The passed GraphicsDevice indicates the screen on
- which to create the GLCanvas; the GLDrawableFactory uses the
- default screen device of the local GraphicsEnvironment if null
- is passed for this argument.
-
- See details about OpenGL context sharing .
-
- * @throws GLException if no GLCapabilities are given and no default profile is available for the default desktop device.
- */
- public GLCanvas(final GLCapabilitiesImmutable capsReqUser,
- final GLCapabilitiesChooser chooser,
- final GraphicsDevice device)
- throws GLException
- {
- /*
- * Determination of the native window is made in 'super.addNotify()',
- * which creates the native peer using AWT's GraphicsConfiguration.
- * GraphicsConfiguration is returned by this class overwritten
- * 'getGraphicsConfiguration()', which returns our OpenGL compatible
- * 'chosen' GraphicsConfiguration.
- */
- super();
-
- if(null==capsReqUser) {
- this.capsReqUser = new GLCapabilities(GLProfile.getDefault(GLProfile.getDefaultDevice()));
- } else {
- // don't allow the user to change data
- this.capsReqUser = (GLCapabilitiesImmutable) capsReqUser.cloneMutable();
- }
- if( !this.capsReqUser.isOnscreen() ) {
- setShallUseOffscreenLayer(true); // trigger offscreen layer - if supported
- }
-
- // One time user AWT GraphicsDevice request
- awtDeviceReq = device;
-
- // instantiation will be issued in addNotify()
- this.chooser = chooser;
-
- this.addHierarchyListener(hierarchyListener);
- this.isShowing = isShowing();
- }
-
- @Override
- public final void setSharedContext(final GLContext sharedContext) throws IllegalStateException {
- helper.setSharedContext(this.context, sharedContext);
- }
-
- @Override
- public final void setSharedAutoDrawable(final GLAutoDrawable sharedAutoDrawable) throws IllegalStateException {
- helper.setSharedAutoDrawable(this, sharedAutoDrawable);
- }
-
- @Override
- public final Object getUpstreamWidget() {
- return this;
- }
-
- @Override
- public final RecursiveLock getUpstreamLock() { return lock; }
-
- @Override
- public final boolean isThreadGLCapable() { return Threading.isOpenGLThread(); }
-
- @Override
- public void setShallUseOffscreenLayer(final boolean v) {
- shallUseOffscreenLayer = v;
- }
-
- @Override
- public final boolean getShallUseOffscreenLayer() {
- return shallUseOffscreenLayer;
- }
-
- @Override
- public final boolean isOffscreenLayerSurfaceEnabled() {
- final JAWTWindow _jawtWindow = jawtWindow;
- if(null != _jawtWindow) {
- return _jawtWindow.isOffscreenLayerSurfaceEnabled();
- }
- return false;
- }
-
-
- /**
- * {@inheritDoc}
- *
- * Overridden to choose a {@link GraphicsConfiguration} from a parent container's
- * {@link GraphicsDevice}.
- *
- *
- * Method also intercepts {@link GraphicsConfiguration} changes regarding to
- * its capabilities and its {@link GraphicsDevice}. This may happen in case
- * the display changes its configuration or the component is moved to another screen.
- *
- */
- @Override
- public GraphicsConfiguration getGraphicsConfiguration() {
- /**
- * parentGC will be null unless:
- * - A native peer has assigned it. This means we have a native
- * peer, and are already committed to a graphics configuration.
- * - This canvas has been added to a component hierarchy and has
- * an ancestor with a non-null GC, but the native peer has not
- * yet been created. This means we can still choose the GC on
- * all platforms since the peer hasn't been created.
- */
- final GraphicsConfiguration parentGC = super.getGraphicsConfiguration();
-
- if( Beans.isDesignTime() ) {
- return parentGC;
- }
- final GraphicsConfiguration oldGC = null != awtConfig ? awtConfig.getAWTGraphicsConfiguration() : null;
-
- if ( null != parentGC && null != oldGC && !oldGC.equals(parentGC) ) {
- // Previous oldGC != parentGC of native peer
-
- if ( !oldGC.getDevice().getIDstring().equals(parentGC.getDevice().getIDstring()) ) {
- // Previous oldGC's GraphicsDevice != parentGC's GraphicsDevice of native peer
-
- /**
- * Here we select a GraphicsConfiguration on the alternate device.
- * In case the new configuration differs (-> !equalCaps),
- * we might need a reconfiguration,
- */
- final AWTGraphicsConfiguration newConfig = chooseGraphicsConfiguration( (GLCapabilitiesImmutable)awtConfig.getChosenCapabilities(),
- (GLCapabilitiesImmutable)awtConfig.getRequestedCapabilities(),
- chooser, parentGC.getDevice());
- final GraphicsConfiguration newGC = newConfig.getAWTGraphicsConfiguration();
- final boolean equalCaps = newConfig.getChosenCapabilities().equals(awtConfig.getChosenCapabilities());
- if(DEBUG) {
- System.err.println(getThreadName()+": getGraphicsConfiguration() Info: Changed GC and GD");
- System.err.println("Created Config (n): Old GC "+oldGC);
- System.err.println("Created Config (n): Old GD "+oldGC.getDevice().getIDstring());
- System.err.println("Created Config (n): Parent GC "+parentGC);
- System.err.println("Created Config (n): Parent GD "+parentGC.getDevice().getIDstring());
- System.err.println("Created Config (n): New GC "+newGC);
- System.err.println("Created Config (n): New GD "+newGC.getDevice().getIDstring());
- System.err.println("Created Config (n): Old CF "+awtConfig);
- System.err.println("Created Config (n): New CF "+newConfig);
- System.err.println("Created Config (n): EQUALS CAPS "+equalCaps);
- // Thread.dumpStack();
- }
- if ( null != newGC ) {
- if( !equalCaps && GLAutoDrawable.SCREEN_CHANGE_ACTION_ENABLED ) {
- // complete destruction!
- destroyImpl( true );
- // recreation!
- setAWTGraphicsConfiguration(newConfig);
- createJAWTDrawableAndContext();
- validateGLDrawable();
- } else {
- setAWTGraphicsConfiguration(newConfig);
- }
- /**
- * Return the newGC, which covers the desired capabilities and is compatible
- * with the available GC's of its devices.
- */
- if(DEBUG) {
- System.err.println(getThreadName()+": Info: getGraphicsConfiguration - end.01: newGC "+newGC);
- }
- return newGC;
- } else {
- if(DEBUG) {
- System.err.println(getThreadName()+": Info: getGraphicsConfiguration - end.00: oldGC "+oldGC);
- }
- }
- }
- /**
- * If a new GC was _not_ found/defined above,
- * method returns oldGC as selected in the constructor or first addNotify().
- * This may cause an exception in Component.checkGD when adding to a
- * container, and is the desired behavior.
- */
- return oldGC;
- } else if (null == parentGC) {
- /**
- * The parentGC is null, which means we have no native peer, and are not
- * part of a (realized) component hierarchy. So we return the
- * desired visual that was selected in the constructor (possibly
- * null).
- */
- return oldGC;
- } else {
- /**
- * Otherwise we have not explicitly selected a GC in the constructor, so
- * just return what Canvas would have.
- */
- return parentGC;
- }
- }
-
- @Override
- public GLContext createContext(final GLContext shareWith) {
- final RecursiveLock _lock = lock;
- _lock.lock();
- try {
- if(drawable != null) {
- final GLContext _ctx = drawable.createContext(shareWith);
- _ctx.setContextCreationFlags(additionalCtxCreationFlags);
- return _ctx;
- }
- return null;
- } finally {
- _lock.unlock();
- }
- }
-
- private final void setRealizedImpl(final boolean realized) {
- final RecursiveLock _lock = lock;
- _lock.lock();
- try {
- final GLDrawable _drawable = drawable;
- if( null == _drawable || realized == _drawable.isRealized() ||
- realized && ( 0 >= _drawable.getSurfaceWidth() || 0 >= _drawable.getSurfaceHeight() ) ) {
- return;
- }
- _drawable.setRealized(realized);
- if( realized && _drawable.isRealized() ) {
- sendReshape=true; // ensure a reshape is being send ..
- }
- } finally {
- _lock.unlock();
- }
- }
- private final Runnable realizeOnEDTAction = new Runnable() {
- @Override
- public void run() { setRealizedImpl(true); }
- };
- private final Runnable unrealizeOnEDTAction = new Runnable() {
- @Override
- public void run() { setRealizedImpl(false); }
- };
-
- @Override
- public final void setRealized(final boolean realized) {
- // Make sure drawable realization happens on AWT-EDT and only there. Consider the AWTTree lock!
- AWTEDTExecutor.singleton.invoke(getTreeLock(), false /* allowOnNonEDT */, true /* wait */, realized ? realizeOnEDTAction : unrealizeOnEDTAction);
- }
-
- @Override
- public boolean isRealized() {
- final GLDrawable _drawable = drawable;
- return ( null != _drawable ) ? _drawable.isRealized() : false;
- }
-
- @Override
- public WindowClosingMode getDefaultCloseOperation() {
- return awtWindowClosingProtocol.getDefaultCloseOperation();
- }
-
- @Override
- public WindowClosingMode setDefaultCloseOperation(final WindowClosingMode op) {
- return awtWindowClosingProtocol.setDefaultCloseOperation(op);
- }
-
- @Override
- public void display() {
- if( !validateGLDrawable() ) {
- if(DEBUG) {
- System.err.println(getThreadName()+": Info: GLCanvas display - skipped GL render, drawable not valid yet");
- }
- return; // not yet available ..
- }
- if( isShowing && !printActive ) {
- Threading.invoke(true, displayOnEDTAction, getTreeLock());
- }
- }
-
- /**
- * {@inheritDoc}
- *
- *
- * This impl. only destroys all GL related resources.
- *
- *
- * This impl. does not remove the GLCanvas from it's parent AWT container
- * so this class's {@link #removeNotify()} AWT override won't get called.
- * To do so, remove this component from it's parent AWT container.
- *
- */
- @Override
- public void destroy() {
- destroyImpl( false );
- }
-
- protected void destroyImpl(final boolean destroyJAWTWindowAndAWTDevice) {
- Threading.invoke(true, destroyOnEDTAction, getTreeLock());
- if( destroyJAWTWindowAndAWTDevice ) {
- AWTEDTExecutor.singleton.invoke(getTreeLock(), true /* allowOnNonEDT */, true /* wait */, disposeJAWTWindowAndAWTDeviceOnEDT);
- }
- }
-
- /** Overridden to cause OpenGL rendering to be performed during
- repaint cycles. Subclasses which override this method must call
- super.paint() in their paint() method in order to function
- properly.
- */
- @Override
- public void paint(final Graphics g) {
- if( Beans.isDesignTime() ) {
- // Make GLCanvas behave better in NetBeans GUI builder
- g.setColor(Color.BLACK);
- g.fillRect(0, 0, getWidth(), getHeight());
- final FontMetrics fm = g.getFontMetrics();
- String name = getName();
- if (name == null) {
- name = getClass().getName();
- final int idx = name.lastIndexOf('.');
- if (idx >= 0) {
- name = name.substring(idx + 1);
- }
- }
- final Rectangle2D bounds = fm.getStringBounds(name, g);
- g.setColor(Color.WHITE);
- g.drawString(name,
- (int) ((getWidth() - bounds.getWidth()) / 2),
- (int) ((getHeight() + bounds.getHeight()) / 2));
- } else if( !this.helper.isAnimatorAnimatingOnOtherThread() ) {
- display();
- }
- }
-
- /** Overridden to track when this component is added to a container.
- Subclasses which override this method must call
- super.addNotify() in their addNotify() method in order to
- function properly.
-
- Overrides:
-
addNotify
in class java.awt.Component
*/
- @SuppressWarnings("deprecation")
- @Override
- public void addNotify() {
- final RecursiveLock _lock = lock;
- _lock.lock();
- try {
- final boolean isBeansDesignTime = Beans.isDesignTime();
-
- if(DEBUG) {
- System.err.println(getThreadName()+": Info: addNotify - start, bounds: "+this.getBounds()+", isBeansDesignTime "+isBeansDesignTime);
- // Thread.dumpStack();
- }
-
- if( isBeansDesignTime ) {
- super.addNotify();
- } else {
- /**
- * 'super.addNotify()' determines the GraphicsConfiguration,
- * while calling this class's overridden 'getGraphicsConfiguration()' method
- * after which it creates the native peer.
- * Hence we have to set the 'awtConfig' before since it's GraphicsConfiguration
- * is being used in getGraphicsConfiguration().
- * This code order also allows recreation, ie re-adding the GLCanvas.
- */
-
- // before native peer is valid: X11
- disableBackgroundErase();
-
- final GraphicsDevice awtDevice;
- if(null==awtDeviceReq) {
- // Query AWT GraphicsDevice from parent tree, default
- final GraphicsConfiguration gc = super.getGraphicsConfiguration();
- if(null==gc) {
- throw new GLException("Error: NULL AWT GraphicsConfiguration");
- }
- awtDevice = gc.getDevice();
- } else {
- // Use one time user AWT GraphicsDevice request
- awtDevice = awtDeviceReq;
- awtDeviceReq = null;
- }
- final AWTGraphicsConfiguration awtConfig = chooseGraphicsConfiguration(capsReqUser, capsReqUser, chooser, awtDevice);
- if(null==awtConfig) {
- throw new GLException("Error: NULL AWTGraphicsConfiguration");
- }
- setAWTGraphicsConfiguration(awtConfig);
-
- // issues getGraphicsConfiguration() and creates the native peer
- super.addNotify();
-
- // after native peer is valid: Windows
- disableBackgroundErase();
-
- createJAWTDrawableAndContext();
-
- // init drawable by paint/display makes the init sequence more equal
- // for all launch flavors (applet/javaws/..)
- // validateGLDrawable();
- }
- awtWindowClosingProtocol.addClosingListener();
-
- if(DEBUG) {
- System.err.println(getThreadName()+": Info: addNotify - end");
- }
- } finally {
- _lock.unlock();
- }
- }
-
- @Override
- public final boolean setSurfaceScale(final float[] pixelScale) {
- System.arraycopy(pixelScale, 0, reqPixelScale, 0, 2);
- if( isRealized() && isShowing ) {
- Threading.invoke(true, setSurfaceScaleOnEDTAction, getTreeLock());
- return true;
- } else {
- return false;
- }
- }
- private final Runnable setSurfaceScaleOnEDTAction = new Runnable() {
- @Override
- public void run() {
- final RecursiveLock _lock = lock;
- _lock.lock();
- try {
- if( null != drawable && drawable.isRealized() ) {
- if( setSurfaceScaleImpl(jawtWindow) ) {
- reshapeImpl(getWidth(), getHeight());
- if( !helper.isAnimatorAnimatingOnOtherThread() ) {
- helper.invokeGL(drawable, context, displayAction, initAction); // display
- }
- }
- }
- } finally {
- _lock.unlock();
- }
- } };
- private final boolean setSurfaceScaleImpl(final ScalableSurface ns) {
- if( ns.setSurfaceScale(reqPixelScale) ) {
- ns.getCurrentSurfaceScale(hasPixelScale);
- return true;
- } else {
- return false;
- }
- }
-
- private final boolean updatePixelScale() {
- if( jawtWindow.hasPixelScaleChanged() ) {
- jawtWindow.getMaximumSurfaceScale(maxPixelScale);
- jawtWindow.getMinimumSurfaceScale(minPixelScale);
- return setSurfaceScaleImpl(jawtWindow);
- } else {
- return false;
- }
- }
-
- @Override
- public final float[] getRequestedSurfaceScale(final float[] result) {
- System.arraycopy(reqPixelScale, 0, result, 0, 2);
- return result;
- }
-
- @Override
- public final float[] getCurrentSurfaceScale(final float[] result) {
- System.arraycopy(hasPixelScale, 0, result, 0, 2);
- return result;
- }
-
- @Override
- public float[] getMinimumSurfaceScale(final float[] result) {
- System.arraycopy(minPixelScale, 0, result, 0, 2);
- return result;
- }
-
- @Override
- public float[] getMaximumSurfaceScale(final float[] result) {
- System.arraycopy(maxPixelScale, 0, result, 0, 2);
- return result;
- }
-
- private void createJAWTDrawableAndContext() {
- if ( !Beans.isDesignTime() ) {
- jawtWindow = (JAWTWindow) NativeWindowFactory.getNativeWindow(this, awtConfig);
- jawtWindow.setShallUseOffscreenLayer(shallUseOffscreenLayer);
- jawtWindow.lockSurface();
- try {
- jawtWindow.setSurfaceScale(reqPixelScale);
- drawable = (GLDrawableImpl) GLDrawableFactory.getFactory(capsReqUser.getGLProfile()).createGLDrawable(jawtWindow);
- createContextImpl(drawable);
- jawtWindow.getCurrentSurfaceScale(hasPixelScale);
- jawtWindow.getMinimumSurfaceScale(minPixelScale);
- jawtWindow.getMaximumSurfaceScale(maxPixelScale);
- } finally {
- jawtWindow.unlockSurface();
- }
- }
- }
- private boolean createContextImpl(final GLDrawable drawable) {
- final GLContext[] shareWith = { null };
- if( !helper.isSharedGLContextPending(shareWith) ) {
- context = (GLContextImpl) drawable.createContext(shareWith[0]);
- context.setContextCreationFlags(additionalCtxCreationFlags);
- if(DEBUG) {
- System.err.println(getThreadName()+": Context created: has shared "+(null != shareWith[0]));
- }
- return true;
- } else {
- if(DEBUG) {
- System.err.println(getThreadName()+": Context !created: pending share");
- }
- return false;
- }
- }
-
- private boolean validateGLDrawable() {
- if( Beans.isDesignTime() || !isDisplayable() ) {
- return false; // early out!
- }
- final GLDrawable _drawable = drawable;
- if ( null != _drawable ) {
- boolean res = _drawable.isRealized();
- if( !res ) {
- // re-try drawable creation
- if( 0 >= _drawable.getSurfaceWidth() || 0 >= _drawable.getSurfaceHeight() ) {
- return false; // early out!
- }
- setRealized(true);
- res = _drawable.isRealized();
- if(DEBUG) {
- System.err.println(getThreadName()+": Realized Drawable: isRealized "+res+", "+_drawable.toString());
- // Thread.dumpStack();
- }
- }
- if( res && null == context ) {
- // re-try context creation
- res = createContextImpl(_drawable); // pending creation.
- }
- return res;
- }
- return false;
- }
-
- private void setAWTGraphicsConfiguration(final AWTGraphicsConfiguration config) {
- // Cache awtConfig
- awtConfig = config;
- if( null != jawtWindow ) {
- // Notify JAWTWindow ..
- jawtWindow.setAWTGraphicsConfiguration(config);
- }
- }
-
- /** Overridden to track when this component is removed from a
- container. Subclasses which override this method must call
- super.removeNotify() in their removeNotify() method in order to
- function properly.
- User shall not call this method outside of EDT, read the AWT/Swing specs
- about this.
- Overrides:
- removeNotify
in class java.awt.Component
*/
- @SuppressWarnings("deprecation")
- @Override
- public void removeNotify() {
- if(DEBUG) {
- System.err.println(getThreadName()+": Info: removeNotify - start");
- // Thread.dumpStack();
- }
-
- awtWindowClosingProtocol.removeClosingListener();
-
- if( Beans.isDesignTime() ) {
- super.removeNotify();
- } else {
- try {
- destroyImpl( true );
- } finally {
- super.removeNotify();
- }
- }
- if(DEBUG) {
- System.err.println(getThreadName()+": Info: removeNotify - end");
- }
- }
-
- /** Overridden to cause {@link GLDrawableHelper#reshape} to be
- called on all registered {@link GLEventListener}s. Subclasses
- which override this method must call super.reshape() in
- their reshape() method in order to function properly.
-
- Overrides:
-
reshape
in class java.awt.Component
*/
- @SuppressWarnings("deprecation")
- @Override
- public void reshape(final int x, final int y, final int width, final int height) {
- synchronized (getTreeLock()) { // super.reshape(..) claims tree lock, so we do extend it's lock over reshape
- super.reshape(x, y, width, height);
- reshapeImpl(width, height);
- }
- }
- private void reshapeImpl(final int width, final int height) {
- final int scaledWidth = SurfaceScaleUtils.scale(width, hasPixelScale[0]);
- final int scaledHeight = SurfaceScaleUtils.scale(height, hasPixelScale[1]);
-
- if(DEBUG) {
- final NativeSurface ns = getNativeSurface();
- final long nsH = null != ns ? ns.getSurfaceHandle() : 0;
- System.err.println(getThreadName()+": GLCanvas.reshape.0 "+this.getName()+" resize"+(printActive?"WithinPrint":"")+
- " [ this "+getWidth()+"x"+getHeight()+", pixelScale "+getPixelScaleStr()+
- "] -> "+(printActive?"[skipped] ":"") + width+"x"+height+" * "+getPixelScaleStr()+" -> "+scaledWidth+"x"+scaledHeight+
- " - surfaceHandle 0x"+Long.toHexString(nsH));
- // Thread.dumpStack();
- }
- if( validateGLDrawable() && !printActive ) {
- final GLDrawableImpl _drawable = drawable;
- if( ! _drawable.getChosenGLCapabilities().isOnscreen() ) {
- final RecursiveLock _lock = lock;
- _lock.lock();
- try {
- final GLDrawableImpl _drawableNew = GLDrawableHelper.resizeOffscreenDrawable(_drawable, context, scaledWidth, scaledHeight);
- if(_drawable != _drawableNew) {
- // write back
- drawable = _drawableNew;
- }
- } finally {
- _lock.unlock();
- }
- }
- sendReshape = true; // async if display() doesn't get called below, but avoiding deadlock
- }
- }
-
- /**
- * Overridden from Canvas to prevent the AWT's clearing of the
- * canvas from interfering with the OpenGL rendering.
- */
- @Override
- public void update(final Graphics g) {
- paint(g);
- }
-
- private volatile boolean printActive = false;
- private GLAnimatorControl printAnimator = null;
- private GLAutoDrawable printGLAD = null;
- private AWTTilePainter printAWTTiles = null;
-
- @Override
- public void setupPrint(final double scaleMatX, final double scaleMatY, final int numSamples, final int tileWidth, final int tileHeight) {
- printActive = true;
- final int componentCount = isOpaque() ? 3 : 4;
- final TileRenderer printRenderer = new TileRenderer();
- printAWTTiles = new AWTTilePainter(printRenderer, componentCount, scaleMatX, scaleMatY, numSamples, tileWidth, tileHeight, DEBUG);
- AWTEDTExecutor.singleton.invoke(getTreeLock(), true /* allowOnNonEDT */, true /* wait */, setupPrintOnEDT);
- }
- private final Runnable setupPrintOnEDT = new Runnable() {
- @Override
- public void run() {
- final RecursiveLock _lock = lock;
- _lock.lock();
- try {
- if( !validateGLDrawable() ) {
- if(DEBUG) {
- System.err.println(getThreadName()+": Info: GLCanvas setupPrint - skipped GL render, drawable not valid yet");
- }
- printActive = false;
- return; // not yet available ..
- }
- if( !isVisible() ) {
- if(DEBUG) {
- System.err.println(getThreadName()+": Info: GLCanvas setupPrint - skipped GL render, canvas not visible");
- }
- printActive = false;
- return; // not yet available ..
- }
- sendReshape = false; // clear reshape flag
- printAnimator = helper.getAnimator();
- if( null != printAnimator ) {
- printAnimator.remove(GLCanvas.this);
- }
- printGLAD = GLCanvas.this; // _not_ default, shall be replaced by offscreen GLAD
- final GLCapabilitiesImmutable gladCaps = getChosenGLCapabilities();
- final int printNumSamples = printAWTTiles.getNumSamples(gladCaps);
- GLDrawable printDrawable = printGLAD.getDelegatedDrawable();
- final boolean reqNewGLADSamples = printNumSamples != gladCaps.getNumSamples();
- final boolean reqNewGLADSize = printAWTTiles.customTileWidth != -1 && printAWTTiles.customTileWidth != printDrawable.getSurfaceWidth() ||
- printAWTTiles.customTileHeight != -1 && printAWTTiles.customTileHeight != printDrawable.getSurfaceHeight();
- final boolean reqNewGLADOnscrn = gladCaps.isOnscreen();
-
- final GLCapabilities newGLADCaps = (GLCapabilities)gladCaps.cloneMutable();
- newGLADCaps.setDoubleBuffered(false);
- newGLADCaps.setOnscreen(false);
- if( printNumSamples != newGLADCaps.getNumSamples() ) {
- newGLADCaps.setSampleBuffers(0 < printNumSamples);
- newGLADCaps.setNumSamples(printNumSamples);
- }
- final boolean reqNewGLADSafe = GLDrawableUtil.isSwapGLContextSafe(getRequestedGLCapabilities(), gladCaps, newGLADCaps);
-
- final boolean reqNewGLAD = ( reqNewGLADOnscrn || reqNewGLADSamples || reqNewGLADSize ) && reqNewGLADSafe;
-
- if( DEBUG ) {
- System.err.println("AWT print.setup: reqNewGLAD "+reqNewGLAD+"[ onscreen "+reqNewGLADOnscrn+", samples "+reqNewGLADSamples+", size "+reqNewGLADSize+", safe "+reqNewGLADSafe+"], "+
- ", drawableSize "+printDrawable.getSurfaceWidth()+"x"+printDrawable.getSurfaceHeight()+
- ", customTileSize "+printAWTTiles.customTileWidth+"x"+printAWTTiles.customTileHeight+
- ", scaleMat "+printAWTTiles.scaleMatX+" x "+printAWTTiles.scaleMatY+
- ", numSamples "+printAWTTiles.customNumSamples+" -> "+printNumSamples+", printAnimator "+printAnimator);
- }
- if( reqNewGLAD ) {
- final GLDrawableFactory factory = GLDrawableFactory.getFactory(newGLADCaps.getGLProfile());
- GLOffscreenAutoDrawable offGLAD = null;
- try {
- offGLAD = factory.createOffscreenAutoDrawable(null, newGLADCaps, null,
- printAWTTiles.customTileWidth != -1 ? printAWTTiles.customTileWidth : DEFAULT_PRINT_TILE_SIZE,
- printAWTTiles.customTileHeight != -1 ? printAWTTiles.customTileHeight : DEFAULT_PRINT_TILE_SIZE);
- } catch (final GLException gle) {
- if( DEBUG ) {
- System.err.println("Caught: "+gle.getMessage());
- gle.printStackTrace();
- }
- }
- if( null != offGLAD ) {
- printGLAD = offGLAD;
- GLDrawableUtil.swapGLContextAndAllGLEventListener(GLCanvas.this, printGLAD);
- printDrawable = printGLAD.getDelegatedDrawable();
- }
- }
- printAWTTiles.setGLOrientation(printGLAD.isGLOriented(), printGLAD.isGLOriented());
- printAWTTiles.renderer.setTileSize(printDrawable.getSurfaceWidth(), printDrawable.getSurfaceHeight(), 0);
- printAWTTiles.renderer.attachAutoDrawable(printGLAD);
- if( DEBUG ) {
- System.err.println("AWT print.setup "+printAWTTiles);
- System.err.println("AWT print.setup AA "+printNumSamples+", "+newGLADCaps);
- System.err.println("AWT print.setup printGLAD: "+printGLAD.getSurfaceWidth()+"x"+printGLAD.getSurfaceHeight()+", "+printGLAD);
- System.err.println("AWT print.setup printDraw: "+printDrawable.getSurfaceWidth()+"x"+printDrawable.getSurfaceHeight()+", "+printDrawable);
- }
- } finally {
- _lock.unlock();
- }
- }
- };
-
- @Override
- public void releasePrint() {
- if( !printActive || null == printGLAD ) {
- throw new IllegalStateException("setupPrint() not called");
- }
- sendReshape = false; // clear reshape flag
- AWTEDTExecutor.singleton.invoke(getTreeLock(), true /* allowOnNonEDT */, true /* wait */, releasePrintOnEDT);
- }
- private final Runnable releasePrintOnEDT = new Runnable() {
- @Override
- public void run() {
- final RecursiveLock _lock = lock;
- _lock.lock();
- try {
- if( DEBUG ) {
- System.err.println("AWT print.release "+printAWTTiles);
- }
- printAWTTiles.dispose();
- printAWTTiles= null;
- if( printGLAD != GLCanvas.this ) {
- GLDrawableUtil.swapGLContextAndAllGLEventListener(printGLAD, GLCanvas.this);
- printGLAD.destroy();
- }
- printGLAD = null;
- if( null != printAnimator ) {
- printAnimator.add(GLCanvas.this);
- printAnimator = null;
- }
- sendReshape = true; // trigger reshape, i.e. gl-viewport and -listener - this component might got resized!
- printActive = false;
- display();
- } finally {
- _lock.unlock();
- }
- }
- };
-
- @Override
- public void print(final Graphics graphics) {
- if( !printActive || null == printGLAD ) {
- throw new IllegalStateException("setupPrint() not called");
- }
- if(DEBUG && !EventQueue.isDispatchThread()) {
- System.err.println(getThreadName()+": Warning: GLCanvas print - not called from AWT-EDT");
- // we cannot dispatch print on AWT-EDT due to printing internal locking ..
- }
- sendReshape = false; // clear reshape flag
-
- final Graphics2D g2d = (Graphics2D)graphics;
- try {
- printAWTTiles.setupGraphics2DAndClipBounds(g2d, getWidth(), getHeight());
- final TileRenderer tileRenderer = printAWTTiles.renderer;
- if( DEBUG ) {
- System.err.println("AWT print.0: "+tileRenderer);
- }
- if( !tileRenderer.eot() ) {
- try {
- do {
- if( printGLAD != GLCanvas.this ) {
- tileRenderer.display();
- } else {
- Threading.invoke(true, displayOnEDTAction, getTreeLock());
- }
- } while ( !tileRenderer.eot() );
- if( DEBUG ) {
- System.err.println("AWT print.1: "+printAWTTiles);
- }
- } finally {
- tileRenderer.reset();
- printAWTTiles.resetGraphics2D();
- }
- }
- } catch (final NoninvertibleTransformException nte) {
- System.err.println("Caught: Inversion failed of: "+g2d.getTransform());
- nte.printStackTrace();
- }
- if( DEBUG ) {
- System.err.println("AWT print.X: "+printAWTTiles);
- }
- }
-
- @Override
- public void addGLEventListener(final GLEventListener listener) {
- helper.addGLEventListener(listener);
- }
-
- @Override
- public void addGLEventListener(final int index, final GLEventListener listener) throws IndexOutOfBoundsException {
- helper.addGLEventListener(index, listener);
- }
-
- @Override
- public int getGLEventListenerCount() {
- return helper.getGLEventListenerCount();
- }
-
- @Override
- public GLEventListener getGLEventListener(final int index) throws IndexOutOfBoundsException {
- return helper.getGLEventListener(index);
- }
-
- @Override
- public boolean areAllGLEventListenerInitialized() {
- return helper.areAllGLEventListenerInitialized();
- }
-
- @Override
- public boolean getGLEventListenerInitState(final GLEventListener listener) {
- return helper.getGLEventListenerInitState(listener);
- }
-
- @Override
- public void setGLEventListenerInitState(final GLEventListener listener, final boolean initialized) {
- helper.setGLEventListenerInitState(listener, initialized);
- }
-
- @Override
- public GLEventListener disposeGLEventListener(final GLEventListener listener, final boolean remove) {
- final DisposeGLEventListenerAction r = new DisposeGLEventListenerAction(listener, remove);
- Threading.invoke(true, r, getTreeLock());
- return r.listener;
- }
-
- @Override
- public GLEventListener removeGLEventListener(final GLEventListener listener) {
- return helper.removeGLEventListener(listener);
- }
-
- @Override
- public void setAnimator(final GLAnimatorControl animatorControl) {
- helper.setAnimator(animatorControl);
- }
-
- @Override
- public GLAnimatorControl getAnimator() {
- return helper.getAnimator();
- }
-
- @Override
- public final Thread setExclusiveContextThread(final Thread t) throws GLException {
- return helper.setExclusiveContextThread(t, context);
- }
-
- @Override
- public final Thread getExclusiveContextThread() {
- return helper.getExclusiveContextThread();
- }
-
- @Override
- public boolean invoke(final boolean wait, final GLRunnable glRunnable) throws IllegalStateException {
- return helper.invoke(this, wait, glRunnable);
- }
-
- @Override
- public boolean invoke(final boolean wait, final List glRunnables) throws IllegalStateException {
- return helper.invoke(this, wait, glRunnables);
- }
-
- @Override
- public void flushGLRunnables() {
- helper.flushGLRunnables();
- }
-
- @Override
- public GLContext setContext(final GLContext newCtx, final boolean destroyPrevCtx) {
- final RecursiveLock _lock = lock;
- _lock.lock();
- try {
- final GLContext oldCtx = context;
- GLDrawableHelper.switchContext(drawable, oldCtx, destroyPrevCtx, newCtx, additionalCtxCreationFlags);
- context=(GLContextImpl)newCtx;
- return oldCtx;
- } finally {
- _lock.unlock();
- }
- }
-
- @Override
- public final GLDrawable getDelegatedDrawable() {
- return drawable;
- }
-
- @Override
- public GLContext getContext() {
- return context;
- }
-
- @Override
- public GL getGL() {
- if( Beans.isDesignTime() ) {
- return null;
- }
- final GLContext _context = context;
- return (_context == null) ? null : _context.getGL();
- }
-
- @Override
- public GL setGL(final GL gl) {
- final GLContext _context = context;
- if (_context != null) {
- _context.setGL(gl);
- return gl;
- }
- return null;
- }
-
-
- @Override
- public void setAutoSwapBufferMode(final boolean onOrOff) {
- helper.setAutoSwapBufferMode(onOrOff);
- }
-
- @Override
- public boolean getAutoSwapBufferMode() {
- return helper.getAutoSwapBufferMode();
- }
-
- @Override
- public void swapBuffers() {
- Threading.invoke(true, swapBuffersOnEDTAction, getTreeLock());
- }
-
- @Override
- public void setContextCreationFlags(final int flags) {
- additionalCtxCreationFlags = flags;
- final GLContext _context = context;
- if(null != _context) {
- _context.setContextCreationFlags(additionalCtxCreationFlags);
- }
- }
-
- @Override
- public int getContextCreationFlags() {
- return additionalCtxCreationFlags;
- }
-
- @Override
- public GLProfile getGLProfile() {
- return capsReqUser.getGLProfile();
- }
-
- @Override
- public GLCapabilitiesImmutable getChosenGLCapabilities() {
- if( Beans.isDesignTime() ) {
- return capsReqUser;
- } else if( null == awtConfig ) {
- throw new GLException("No AWTGraphicsConfiguration: "+this);
- }
- return (GLCapabilitiesImmutable)awtConfig.getChosenCapabilities();
- }
-
- @Override
- public GLCapabilitiesImmutable getRequestedGLCapabilities() {
- if( null == awtConfig ) {
- return capsReqUser;
- }
- return (GLCapabilitiesImmutable)awtConfig.getRequestedCapabilities();
- }
-
- @Override
- public int getSurfaceWidth() {
- return SurfaceScaleUtils.scale(getWidth(), hasPixelScale[0]);
- }
-
- @Override
- public int getSurfaceHeight() {
- return SurfaceScaleUtils.scale(getHeight(), hasPixelScale[1]);
- }
-
- @Override
- public boolean isGLOriented() {
- final GLDrawable _drawable = drawable;
- return null != _drawable ? _drawable.isGLOriented() : true;
- }
-
- @Override
- public NativeSurface getNativeSurface() {
- final GLDrawable _drawable = drawable;
- return (null != _drawable) ? _drawable.getNativeSurface() : null;
- }
-
- @Override
- public long getHandle() {
- final GLDrawable _drawable = drawable;
- return (null != _drawable) ? _drawable.getHandle() : 0;
- }
-
- @Override
- public GLDrawableFactory getFactory() {
- final GLDrawable _drawable = drawable;
- return (null != _drawable) ? _drawable.getFactory() : null;
- }
-
- @Override
- public String toString() {
- final GLDrawable _drawable = drawable;
- final int dw = (null!=_drawable) ? _drawable.getSurfaceWidth() : -1;
- final int dh = (null!=_drawable) ? _drawable.getSurfaceHeight() : -1;
-
- return "AWT-GLCanvas[Realized "+isRealized()+
- ",\n\t"+((null!=_drawable)?_drawable.getClass().getName():"null-drawable")+
- ",\n\tFactory "+getFactory()+
- ",\n\thandle 0x"+Long.toHexString(getHandle())+
- ",\n\tDrawable size "+dw+"x"+dh+" surface["+getSurfaceWidth()+"x"+getSurfaceHeight()+"]"+
- ",\n\tAWT[pos "+getX()+"/"+getY()+", size "+getWidth()+"x"+getHeight()+
- ",\n\tvisible "+isVisible()+", displayable "+isDisplayable()+", showing "+isShowing+
- ",\n\t"+awtConfig+"]]";
- }
-
- //----------------------------------------------------------------------
- // Internals only below this point
- //
-
- private final String getPixelScaleStr() { return "["+hasPixelScale[0]+", "+hasPixelScale[1]+"]"; }
-
- private final Runnable destroyOnEDTAction = new Runnable() {
- @Override
- public void run() {
- final RecursiveLock _lock = lock;
- _lock.lock();
- try {
- final GLAnimatorControl animator = getAnimator();
-
- if(DEBUG) {
- System.err.println(getThreadName()+": Info: destroyOnEDTAction() - START, hasContext " +
- (null!=context) + ", hasDrawable " + (null!=drawable)+", "+animator);
- // Thread.dumpStack();
- }
-
- final boolean animatorPaused;
- if(null!=animator) {
- // can't remove us from animator for recreational addNotify()
- animatorPaused = animator.pause();
- } else {
- animatorPaused = false;
- }
-
- GLException exceptionOnDisposeGL = null;
-
- // OLS will be detached by disposeGL's context destruction below
- if( null != context ) {
- if( context.isCreated() ) {
- try {
- helper.disposeGL(GLCanvas.this, context, true);
- if(DEBUG) {
- System.err.println(getThreadName()+": destroyOnEDTAction() - post ctx: "+context);
- }
- } catch (final GLException gle) {
- exceptionOnDisposeGL = gle;
- }
- }
- context = null;
- }
-
- Throwable exceptionOnUnrealize = null;
- if( null != drawable ) {
- try {
- drawable.setRealized(false);
- if(DEBUG) {
- System.err.println(getThreadName()+": destroyOnEDTAction() - post drawable: "+drawable);
- }
- } catch( final Throwable re ) {
- exceptionOnUnrealize = re;
- }
- drawable = null;
- }
-
- if(animatorPaused) {
- animator.resume();
- }
-
- // throw exception in order of occurrence ..
- if( null != exceptionOnDisposeGL ) {
- throw exceptionOnDisposeGL;
- }
- if( null != exceptionOnUnrealize ) {
- throw GLException.newGLException(exceptionOnUnrealize);
- }
-
- if(DEBUG) {
- System.err.println(getThreadName()+": dispose() - END, animator "+animator);
- }
-
- } finally {
- _lock.unlock();
- }
- }
- };
-
- /**
- * Disposes the JAWTWindow and AbstractGraphicsDevice within EDT,
- * since resources created (X11: Display), must be destroyed in the same thread, where they have been created.
- *
- * The drawable and context handle are null'ed as well, assuming {@link #destroy()} has been called already.
- *
- *
- * @see #chooseGraphicsConfiguration(com.jogamp.opengl.GLCapabilitiesImmutable, com.jogamp.opengl.GLCapabilitiesImmutable, com.jogamp.opengl.GLCapabilitiesChooser, java.awt.GraphicsDevice)
- */
- private final Runnable disposeJAWTWindowAndAWTDeviceOnEDT = new Runnable() {
- @Override
- public void run() {
- context=null;
- drawable=null;
-
- if( null != jawtWindow ) {
- jawtWindow.destroy();
- if(DEBUG) {
- System.err.println(getThreadName()+": GLCanvas.disposeJAWTWindowAndAWTDeviceOnEDT(): post JAWTWindow: "+jawtWindow);
- }
- jawtWindow=null;
- }
- hasPixelScale[0] = ScalableSurface.IDENTITY_PIXELSCALE;
- hasPixelScale[1] = ScalableSurface.IDENTITY_PIXELSCALE;
- minPixelScale[0] = ScalableSurface.IDENTITY_PIXELSCALE;
- minPixelScale[1] = ScalableSurface.IDENTITY_PIXELSCALE;
- maxPixelScale[0] = ScalableSurface.IDENTITY_PIXELSCALE;
- maxPixelScale[1] = ScalableSurface.IDENTITY_PIXELSCALE;
-
- if(null != awtConfig) {
- final AbstractGraphicsConfiguration aconfig = awtConfig.getNativeGraphicsConfiguration();
- final AbstractGraphicsDevice adevice = aconfig.getScreen().getDevice();
- final String adeviceMsg;
- if(DEBUG) {
- adeviceMsg = adevice.toString();
- } else {
- adeviceMsg = null;
- }
- final boolean closed = adevice.close();
- if(DEBUG) {
- System.err.println(getThreadName()+": GLCanvas.disposeJAWTWindowAndAWTDeviceOnEDT(): post GraphicsDevice: "+adeviceMsg+", result: "+closed);
- }
- }
- awtConfig = null;
- }
- };
-
- private final Runnable initAction = new Runnable() {
- @Override
- public void run() {
- helper.init(GLCanvas.this, !sendReshape);
- }
- };
-
- private final Runnable displayAction = new Runnable() {
- @Override
- public void run() {
- if (sendReshape) {
- if(DEBUG) {
- System.err.println(getThreadName()+": Reshape: "+getSurfaceWidth()+"x"+getSurfaceHeight());
- }
- // Note: we ignore the given x and y within the parent component
- // since we are drawing directly into this heavyweight component.
- helper.reshape(GLCanvas.this, 0, 0, getSurfaceWidth(), getSurfaceHeight());
- sendReshape = false;
- }
-
- helper.display(GLCanvas.this);
- }
- };
-
- private final Runnable displayOnEDTAction = new Runnable() {
- @Override
- public void run() {
- final RecursiveLock _lock = lock;
- _lock.lock();
- try {
- if( null != drawable && drawable.isRealized() ) {
- if( GLCanvas.this.updatePixelScale() ) {
- GLCanvas.this.reshapeImpl(getWidth(), getHeight());
- }
- helper.invokeGL(drawable, context, displayAction, initAction);
- }
- } finally {
- _lock.unlock();
- }
- }
- };
-
- private final Runnable swapBuffersOnEDTAction = new Runnable() {
- @Override
- public void run() {
- final RecursiveLock _lock = lock;
- _lock.lock();
- try {
- if( null != drawable && drawable.isRealized() ) {
- drawable.swapBuffers();
- }
- } finally {
- _lock.unlock();
- }
- }
- };
-
- private class DisposeGLEventListenerAction implements Runnable {
- GLEventListener listener;
- private final boolean remove;
- private DisposeGLEventListenerAction(final GLEventListener listener, final boolean remove) {
- this.listener = listener;
- this.remove = remove;
- }
-
- @Override
- public void run() {
- final RecursiveLock _lock = lock;
- _lock.lock();
- try {
- listener = helper.disposeGLEventListener(GLCanvas.this, drawable, context, listener, remove);
- } finally {
- _lock.unlock();
- }
- }
- };
-
- // Disables the AWT's erasing of this Canvas's background on Windows
- // in Java SE 6. This internal API is not available in previous
- // releases, but the system property
- // -Dsun.awt.noerasebackground=true can be specified to get similar
- // results globally in previous releases.
- // private static boolean disableBackgroundEraseInitialized;
- // private static Method disableBackgroundEraseMethod;
- private void disableBackgroundErase() {
- // if (!disableBackgroundEraseInitialized) {
- // try {
- // AccessController.doPrivileged(new PrivilegedAction() {
- // @Override
- // public Object run() {
- // try {
- // Class> clazz = getToolkit().getClass();
- // while (clazz != null && disableBackgroundEraseMethod == null) {
- // try {
- // disableBackgroundEraseMethod =
- // clazz.getDeclaredMethod("disableBackgroundErase",
- // new Class[] { Canvas.class });
- // disableBackgroundEraseMethod.setAccessible(true);
- // } catch (final Exception e) {
- // clazz = clazz.getSuperclass();
- // }
- // }
- // } catch (final Exception e) {
- // }
- // return null;
- // }
- // });
- // } catch (final Exception e) {
- // }
- // disableBackgroundEraseInitialized = true;
- // if(DEBUG) {
- // System.err.println(getThreadName()+": GLCanvas: TK disableBackgroundErase method found: "+
- // (null!=disableBackgroundEraseMethod));
- // }
- // }
- // if (disableBackgroundEraseMethod != null) {
- // Throwable t=null;
- // try {
- // disableBackgroundEraseMethod.invoke(getToolkit(), new Object[] { this });
- // } catch (final Exception e) {
- // t = e;
- // }
- // if(DEBUG) {
- // System.err.println(getThreadName()+": GLCanvas: TK disableBackgroundErase error: "+t);
- // }
- // }
- }
-
- /**
- * Issues the GraphicsConfigurationFactory's choosing facility within EDT,
- * since resources created (X11: Display), must be destroyed in the same thread, where they have been created.
- *
- * @param capsChosen
- * @param capsRequested
- * @param chooser
- * @param device
- * @return the chosen AWTGraphicsConfiguration
- *
- * @see #disposeJAWTWindowAndAWTDeviceOnEDT
- */
- private AWTGraphicsConfiguration chooseGraphicsConfiguration(final GLCapabilitiesImmutable capsChosen,
- final GLCapabilitiesImmutable capsRequested,
- final GLCapabilitiesChooser chooser,
- final GraphicsDevice device) {
- // Make GLCanvas behave better in NetBeans GUI builder
- if( Beans.isDesignTime() ) {
- return null;
- }
- if( null == device ) {
- throw new GLException("Error: NULL AWT GraphicsDevice");
- }
- final AbstractGraphicsScreen aScreen = AWTGraphicsScreen.createScreenDevice(device, AbstractGraphicsDevice.DEFAULT_UNIT);
- AWTGraphicsConfiguration config = null;
-
- if( EventQueue.isDispatchThread() || Thread.holdsLock(getTreeLock()) ) {
- config = (AWTGraphicsConfiguration)
- GraphicsConfigurationFactory.getFactory(AWTGraphicsDevice.class, GLCapabilitiesImmutable.class).chooseGraphicsConfiguration(capsChosen,
- capsRequested,
- chooser, aScreen, VisualIDHolder.VID_UNDEFINED);
- } else {
- try {
- final ArrayList bucket = new ArrayList(1);
- EventQueue.invokeAndWait(new Runnable() {
- @Override
- public void run() {
- final AWTGraphicsConfiguration c = (AWTGraphicsConfiguration)
- GraphicsConfigurationFactory.getFactory(AWTGraphicsDevice.class, GLCapabilitiesImmutable.class).chooseGraphicsConfiguration(capsChosen,
- capsRequested,
- chooser, aScreen, VisualIDHolder.VID_UNDEFINED);
- bucket.add(c);
- }
- });
- config = ( bucket.size() > 0 ) ? bucket.get(0) : null ;
- } catch (final InvocationTargetException e) {
- throw new GLException(e.getTargetException());
- } catch (final InterruptedException e) {
- throw new GLException(e);
- }
- }
-
- if ( null == config ) {
- throw new GLException("Error: Couldn't fetch AWTGraphicsConfiguration");
- }
-
- return config;
- }
-
- protected static String getThreadName() { return Thread.currentThread().getName(); }
-
- /**
- * A most simple JOGL AWT test entry
- */
- public static void main(final String args[]) {
- System.err.println(VersionUtil.getPlatformInfo());
- System.err.println(GlueGenVersion.getInstance());
- // System.err.println(NativeWindowVersion.getInstance());
- System.err.println(JoglVersion.getInstance());
-
- System.err.println(JoglVersion.getDefaultOpenGLInfo(null, null, true).toString());
-
- final GLCapabilitiesImmutable caps = new GLCapabilities( GLProfile.getDefault(GLProfile.getDefaultDevice()) );
- final Frame frame = new Frame("JOGL AWT Test");
-
- final GLCanvas glCanvas = new GLCanvas(caps);
- frame.add(glCanvas);
- frame.setSize(128, 128);
-
- glCanvas.addGLEventListener(new GLEventListener() {
- @Override
- public void init(final GLAutoDrawable drawable) {
- final GL gl = drawable.getGL();
- System.err.println(JoglVersion.getGLInfo(gl, null));
- }
- @Override
- public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) { }
- @Override
- public void display(final GLAutoDrawable drawable) { }
- @Override
- public void dispose(final GLAutoDrawable drawable) { }
- });
-
- try {
- javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
- @Override
- public void run() {
- frame.setVisible(true);
- }});
- } catch (final Throwable t) {
- t.printStackTrace();
- }
- glCanvas.display();
- try {
- javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
- @Override
- public void run() {
- frame.dispose();
- }});
- } catch (final Throwable t) {
- t.printStackTrace();
- }
- }
-
-}
diff --git a/lib-external/jogl-gluegen/patch/MacOSXCGLContext.java b/lib-external/jogl-gluegen/patch/MacOSXCGLContext.java
deleted file mode 100644
index 624579b6b4..0000000000
--- a/lib-external/jogl-gluegen/patch/MacOSXCGLContext.java
+++ /dev/null
@@ -1,1288 +0,0 @@
-/*
- * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
- * Copyright (c) 2010 JogAmp Community. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * - Redistribution of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistribution in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * Neither the name of Sun Microsystems, Inc. or the names of
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * This software is provided "AS IS," without a warranty of any kind. ALL
- * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
- * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
- * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
- * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
- * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
- * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
- * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
- * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
- * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
- * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
- * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
- *
- * You acknowledge that this software is not designed or intended for use
- * in the design, construction, operation or maintenance of any nuclear
- * facility.
- *
- * Sun gratefully acknowledges that this software was originally authored
- * and developed by Kenneth Bradley Russell and Christopher John Kline.
- */
-
-package jogamp.opengl.macosx.cgl;
-
-import java.nio.IntBuffer;
-import java.util.Map;
-
-import com.jogamp.nativewindow.AbstractGraphicsConfiguration;
-import com.jogamp.nativewindow.AbstractGraphicsDevice;
-import com.jogamp.nativewindow.NativeSurface;
-import com.jogamp.nativewindow.NativeWindowFactory;
-import com.jogamp.nativewindow.OffscreenLayerSurface;
-import com.jogamp.nativewindow.ProxySurface;
-import com.jogamp.opengl.GL;
-import com.jogamp.opengl.GL2ES2;
-import com.jogamp.opengl.GL3ES3;
-import com.jogamp.opengl.GLCapabilities;
-import com.jogamp.opengl.GLCapabilitiesImmutable;
-import com.jogamp.opengl.GLContext;
-import com.jogamp.opengl.GLException;
-import com.jogamp.opengl.GLProfile;
-import com.jogamp.opengl.GLUniformData;
-import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
-
-import jogamp.nativewindow.macosx.OSXUtil;
-import jogamp.opengl.GLContextImpl;
-import jogamp.opengl.GLDrawableImpl;
-import jogamp.opengl.GLDynamicLookupHelper;
-import jogamp.opengl.GLFBODrawableImpl;
-import jogamp.opengl.GLGraphicsConfigurationUtil;
-import jogamp.opengl.macosx.cgl.MacOSXCGLDrawable.GLBackendType;
-
-import com.jogamp.common.nio.Buffers;
-import com.jogamp.common.nio.PointerBuffer;
-import com.jogamp.common.os.Platform;
-import com.jogamp.common.util.VersionNumber;
-import com.jogamp.common.util.locks.RecursiveLock;
-import com.jogamp.gluegen.runtime.ProcAddressTable;
-import com.jogamp.gluegen.runtime.opengl.GLProcAddressResolver;
-import com.jogamp.opengl.GLRendererQuirks;
-import com.jogamp.opengl.util.PMVMatrix;
-import com.jogamp.opengl.util.glsl.ShaderCode;
-import com.jogamp.opengl.util.glsl.ShaderProgram;
-
-public class MacOSXCGLContext extends GLContextImpl
-{
- // Abstract interface for implementation of this context (either
- // NSOpenGL-based or CGL-based)
- protected interface GLBackendImpl {
- boolean isNSContext();
- /** Indicating CALayer, i.e. onscreen rendering using offscreen layer. */
- boolean isUsingCALayer();
- long create(long share, int ctp, int major, int minor);
- boolean destroy(long ctx);
- void associateDrawable(boolean bound);
- boolean copyImpl(long src, int mask);
- boolean makeCurrent(long ctx);
- boolean release(long ctx);
- boolean detachPBuffer();
- boolean setSwapInterval(int interval);
- boolean swapBuffers();
- }
-
- /* package */ static final boolean isTigerOrLater;
- /* package */ static final boolean isLionOrLater;
- /* package */ static final boolean isMavericksOrLater;
-
- static {
- final VersionNumber osvn = Platform.getOSVersionNumber();
- isTigerOrLater = osvn.compareTo(Platform.OSXVersion.Tiger) >= 0;
- isLionOrLater = osvn.compareTo(Platform.OSXVersion.Lion) >= 0;
- isMavericksOrLater = osvn.compareTo(Platform.OSXVersion.Mavericks) >= 0;
- }
-
- static boolean isGLProfileSupported(final int ctp, final int major, final int minor) {
- if( 0 != ( CTX_PROFILE_ES & ctp ) ) {
- return false;
- }
- final boolean ctBwdCompat = 0 != ( CTX_PROFILE_COMPAT & ctp ) ;
- final boolean ctCore = 0 != ( CTX_PROFILE_CORE & ctp ) ;
-
- // We exclude 3.0, since we would map it's core to GL2. Hence we force mapping 2.1 to GL2
- if( 3 < major || 3 == major && 1 <= minor ) {
- if(ctBwdCompat || !ctCore) {
- // No compatibility profile on OS X
- // Only core is supported
- return false;
- }
- if(!isLionOrLater) {
- // no GL Profile >= GL3 core on pre lion
- return false;
- }
- if(3 < major && !isMavericksOrLater) {
- // no GL Profile >= GL4 core on pre mavericks
- return false;
- }
- // [3.1..3.x] -> GL3
- // [4.0..4.x] -> GL4
- return true;
- } else if( major < 3 ) {
- // < 3.0 -> GL2
- return true;
- }
- return false; // 3.0 && > 3.2
- }
- static int GLProfile2CGLOGLProfileValue(final AbstractGraphicsDevice device, final int ctp, final int major, final int minor) {
- if(!MacOSXCGLContext.isGLProfileSupported(ctp, major, minor)) {
- throw new GLException("OpenGL profile not supported: "+getGLVersion(major, minor, ctp, "@GLProfile2CGLOGLProfileVersion"));
- }
- final boolean ctCore = 0 != ( CTX_PROFILE_CORE & ctp ) ;
-
- if( major == 4 && ctCore ) {
- if( GLRendererQuirks.existStickyDeviceQuirk(device, GLRendererQuirks.GL4NeedsGL3Request) ) {
- // Thread safe GLRendererQuirks sticky access, since we are only interested of the result _after_ GL version mapping,
- // i.e. after single threaded initialization!
- return CGL.kCGLOGLPVersion_GL3_Core;
- } else {
- return CGL.kCGLOGLPVersion_GL4_Core;
- }
- } else if( major == 3 && minor >= 1 && ctCore ) {
- return CGL.kCGLOGLPVersion_GL3_Core;
- } else {
- return CGL.kCGLOGLPVersion_Legacy;
- }
- }
-
- private static final String shaderBasename = "texture01_xxx";
-
- private static ShaderProgram createCALayerShader(final GL3ES3 gl) {
- // Create & Link the shader program
- final ShaderProgram sp = new ShaderProgram();
- final ShaderCode vp = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, MacOSXCGLContext.class,
- "../../shader", "../../shader/bin", shaderBasename, true);
- final ShaderCode fp = ShaderCode.create(gl, GL2ES2.GL_FRAGMENT_SHADER, MacOSXCGLContext.class,
- "../../shader", "../../shader/bin", shaderBasename, true);
- vp.defaultShaderCustomization(gl, true, true);
- fp.defaultShaderCustomization(gl, true, true);
- sp.add(vp);
- sp.add(fp);
- if(!sp.link(gl, System.err)) {
- throw new GLException("Couldn't link program: "+sp);
- }
- sp.useProgram(gl, true);
-
- // setup mgl_PMVMatrix
- final PMVMatrix pmvMatrix = new PMVMatrix();
- pmvMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
- pmvMatrix.glLoadIdentity();
- pmvMatrix.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
- pmvMatrix.glLoadIdentity();
- final GLUniformData pmvMatrixUniform = new GLUniformData("mgl_PMVMatrix", 4, 4, pmvMatrix.glGetPMvMatrixf()); // P, Mv
- pmvMatrixUniform.setLocation(gl, sp.program());
- gl.glUniform(pmvMatrixUniform);
-
- sp.useProgram(gl, false);
- return sp;
- }
-
-
- private boolean haveSetOpenGLMode = false;
- private GLBackendType openGLMode = GLBackendType.NSOPENGL;
-
- // Implementation object (either NSOpenGL-based or CGL-based)
- protected GLBackendImpl impl;
-
- private CGLExt _cglExt;
- // Table that holds the addresses of the native C-language entry points for
- // CGL extension functions.
- private CGLExtProcAddressTable cglExtProcAddressTable;
-
- private long updateHandle = 0;
- private int lastWidth, lastHeight;
-
- protected MacOSXCGLContext(final GLDrawableImpl drawable,
- final GLContext shareWith) {
- super(drawable, shareWith);
- initOpenGLImpl(getOpenGLMode());
- }
-
- @Override
- protected void resetStates(final boolean isInit) {
- // no inner state _cglExt = null;
- cglExtProcAddressTable = null;
- super.resetStates(isInit);
- }
-
- @Override
- public Object getPlatformGLExtensions() {
- return getCGLExt();
- }
-
- protected boolean isNSContext() {
- return (null != impl) ? impl.isNSContext() : this.openGLMode == GLBackendType.NSOPENGL;
- }
-
- public CGLExt getCGLExt() {
- if (_cglExt == null) {
- _cglExt = new CGLExtImpl(this);
- }
- return _cglExt;
- }
-
- @Override
- public final ProcAddressTable getPlatformExtProcAddressTable() {
- return getCGLExtProcAddressTable();
- }
-
- public final CGLExtProcAddressTable getCGLExtProcAddressTable() {
- return cglExtProcAddressTable;
- }
-
- @Override
- protected Map getFunctionNameMap() { return null; }
-
- @Override
- protected Map getExtensionNameMap() { return null; }
-
- @Override
- protected long createContextARBImpl(final long share, final boolean direct, final int ctp, final int major, final int minor) {
- if(!isGLProfileSupported(ctp, major, minor)) {
- if(DEBUG) {
- System.err.println(getThreadName() + ": createContextARBImpl: Not supported "+getGLVersion(major, minor, ctp, "@creation on OSX "+Platform.getOSVersionNumber()));
- }
- return 0;
- }
-
- // Will throw exception upon error
- long ctx = impl.create(share, ctp, major, minor);
- if(0 != ctx) {
- if (!impl.makeCurrent(ctx)) {
- if(DEBUG) {
- System.err.println(getThreadName() + ": createContextARB couldn't make current "+getGLVersion(major, minor, ctp, "@creation"));
- }
- impl.release(ctx);
- impl.destroy(ctx);
- ctx = 0;
- } else if(DEBUG) {
- System.err.println(getThreadName() + ": createContextARBImpl: OK "+getGLVersion(major, minor, ctp, "@creation")+", share "+share+", direct "+direct+" on OSX "+Platform.getOSVersionNumber());
- }
- } else if(DEBUG) {
- System.err.println(getThreadName() + ": createContextARBImpl: NO "+getGLVersion(major, minor, ctp, "@creation on OSX "+Platform.getOSVersionNumber()));
- }
- return ctx;
- }
-
- @Override
- protected void destroyContextARBImpl(final long _context) {
- impl.release(_context);
- impl.destroy(_context);
- }
-
- @Override
- public final boolean isGLReadDrawableAvailable() {
- return false;
- }
-
- @Override
- protected boolean createImpl(final long shareWithHandle) throws GLException {
- final MacOSXCGLGraphicsConfiguration config = (MacOSXCGLGraphicsConfiguration) drawable.getNativeSurface().getGraphicsConfiguration();
- final AbstractGraphicsDevice device = config.getScreen().getDevice();
- final GLCapabilitiesImmutable glCaps = (GLCapabilitiesImmutable) config.getChosenCapabilities();
- final GLProfile glp = glCaps.getGLProfile();
- final boolean createContextARBAvailable = isCreateContextARBAvail(device);
- if(DEBUG) {
- System.err.println(getThreadName() + ": MacOSXCGLContext.createImpl: START "+glCaps+", share "+toHexString(shareWithHandle));
- System.err.println(getThreadName() + ": Use ARB[avail["+getCreateContextARBAvailStr(device)+
- "] -> "+createContextARBAvailable+"]]");
- }
- if( glp.isGLES() ||
- ( glp.isGL3() && !isLionOrLater ) || ( glp.isGL4() && !isMavericksOrLater ) ) {
- throw new GLException("OpenGL profile not supported on MacOSX "+Platform.getOSVersionNumber()+": "+glp);
- }
- if( 0 != shareWithHandle && GLBackendType.NSOPENGL != getOpenGLMode() ) {
- throw new GLException("Context sharing only supported in mode "+GLBackendType.NSOPENGL+": "+this);
- }
- contextHandle = createContextARB(shareWithHandle, true);
- return 0 != contextHandle;
- }
-
- @Override
- protected void makeCurrentImpl() throws GLException {
- /** FIXME: won't work w/ special drawables (like FBO) - check for CGL mode regressions!
- *
- if (getOpenGLMode() != ((MacOSXCGLDrawable)drawable).getOpenGLMode()) {
- setOpenGLMode(((MacOSXCGLDrawable)drawable).getOpenGLMode());
- } */
- if ( !impl.makeCurrent(contextHandle) ) {
- throw new GLException("Error making Context current: "+this);
- }
- drawableUpdatedNotify();
- }
-
- @Override
- protected void releaseImpl() throws GLException {
- if (!impl.release(contextHandle)) {
- throw new GLException("Error releasing OpenGL Context: "+this);
- }
- }
-
- @Override
- protected void destroyImpl() throws GLException {
- releaseUpdateHandle();
- if(!impl.destroy(contextHandle)) {
- throw new GLException("Error destroying OpenGL Context: "+this);
- }
- }
-
- private final long getUpdateHandle() {
- if( 0 == updateHandle ) {
- lastWidth = -1;
- lastHeight = -1;
- if( isCreated() && drawable.getChosenGLCapabilities().isOnscreen() && isNSContext() ) {
- final boolean incompleteView;
- final NativeSurface surface = drawable.getNativeSurface();
- if( surface instanceof ProxySurface ) {
- incompleteView = ((ProxySurface)surface).containsUpstreamOptionBits( ProxySurface.OPT_UPSTREAM_WINDOW_INVISIBLE );
- } else {
- incompleteView = false;
- }
- if(!incompleteView) {
- updateHandle = CGL.updateContextRegister(contextHandle, drawable.getHandle());
- if(0 == updateHandle) {
- throw new InternalError("XXX2");
- }
- }
- }
- }
- return updateHandle;
- }
-
- private final void releaseUpdateHandle() {
- if ( 0 != updateHandle ) {
- CGL.updateContextUnregister(updateHandle);
- updateHandle = 0;
- }
- }
-
- @Override
- protected void drawableUpdatedNotify() throws GLException {
- if( drawable.getChosenGLCapabilities().isOnscreen() ) {
- final long _updateHandle = getUpdateHandle();
- final int w = drawable.getSurfaceWidth();
- final int h = drawable.getSurfaceHeight();
- final boolean updateContext = ( 0!=_updateHandle && CGL.updateContextNeedsUpdate(_updateHandle) ) ||
- w != lastWidth || h != lastHeight;
- if(updateContext) {
- lastWidth = w;
- lastHeight = h;
- if (contextHandle == 0) {
- throw new GLException("Context not created");
- }
- CGL.updateContext(contextHandle);
- }
- }
- }
-
- @Override
- protected void associateDrawable(final boolean bound) {
- // context stuff depends on drawable stuff
- if(bound) {
- super.associateDrawable(true); // 1) init drawable stuff
- impl.associateDrawable(true); // 2) init context stuff
- getUpdateHandle();
- } else {
- releaseUpdateHandle();
- impl.associateDrawable(false); // 1) free context stuff
- super.associateDrawable(false); // 2) free drawable stuff
- }
- }
-
- /* pp */ void detachPBuffer() {
- impl.detachPBuffer();
- }
-
-
- @Override
- protected void copyImpl(final GLContext source, final int mask) throws GLException {
- if( isNSContext() != ((MacOSXCGLContext)source).isNSContext() ) {
- throw new GLException("Source/Destination OpenGL Context type mismatch: source "+source+", dest: "+this);
- }
- if(!impl.copyImpl(source.getHandle(), mask)) {
- throw new GLException("Error copying OpenGL Context: source "+source+", dest: "+this);
- }
- }
-
- protected void swapBuffers() {
- // single-buffer is already filtered out @ GLDrawableImpl#swapBuffers()
- if(!impl.swapBuffers()) {
- throw new GLException("Error swapping buffers: "+this);
- }
- }
-
- @Override
- protected final Integer setSwapIntervalImpl2(final int interval) {
- if( !impl.isUsingCALayer() && !drawable.getChosenGLCapabilities().isOnscreen() ) {
- return null;
- }
- final int useInterval;
- if( 0 > interval ) {
- useInterval = Math.abs(interval);
- } else {
- useInterval = interval;
- }
- if( impl.setSwapInterval(useInterval) ) {
- return Integer.valueOf(useInterval);
- }
- return null;
- }
-
- /**
- * {@inheritDoc}
- *
- * Ignoring {@code contextFQN}, using {@code MacOSX}-{@link AbstractGraphicsDevice#getUniqueID()}.
- *
- */
- @Override
- protected final void updateGLXProcAddressTable(final String contextFQN, final GLDynamicLookupHelper dlh) {
- if( null == dlh ) {
- throw new GLException("No GLDynamicLookupHelper for "+this);
- }
- final AbstractGraphicsConfiguration aconfig = drawable.getNativeSurface().getGraphicsConfiguration();
- final AbstractGraphicsDevice adevice = aconfig.getScreen().getDevice();
- final String key = "MacOSX-"+adevice.getUniqueID();
- if (DEBUG) {
- System.err.println(getThreadName() + ": Initializing CGL extension address table: "+key);
- }
- ProcAddressTable table = null;
- synchronized(mappedContextTypeObjectLock) {
- table = mappedGLXProcAddress.get( key );
- }
- if(null != table) {
- cglExtProcAddressTable = (CGLExtProcAddressTable) table;
- if(DEBUG) {
- System.err.println(getThreadName() + ": GLContext CGL ProcAddressTable reusing key("+key+") -> "+toHexString(table.hashCode()));
- }
- } else {
- cglExtProcAddressTable = new CGLExtProcAddressTable(new GLProcAddressResolver());
- resetProcAddressTable(getCGLExtProcAddressTable(), dlh);
- synchronized(mappedContextTypeObjectLock) {
- mappedGLXProcAddress.put(key, getCGLExtProcAddressTable());
- if(DEBUG) {
- System.err.println(getThreadName() + ": GLContext CGL ProcAddressTable mapping key("+key+") -> "+toHexString(getCGLExtProcAddressTable().hashCode()));
- }
- }
- }
- }
-
- @Override
- protected final StringBuilder getPlatformExtensionsStringImpl() {
- return new StringBuilder();
- }
-
- // Support for "mode switching" as described in MacOSXCGLDrawable
- public void setOpenGLMode(final GLBackendType mode) {
- if (mode == openGLMode) {
- return;
- }
- if (haveSetOpenGLMode) {
- throw new GLException("Can't switch between using NSOpenGLPixelBuffer and CGLPBufferObj more than once");
- }
- destroyImpl();
- ((MacOSXCGLDrawable)drawable).setOpenGLMode(mode);
- if (DEBUG) {
- System.err.println("MacOSXCGLContext: Switching context mode " + openGLMode + " -> " + mode);
- }
- initOpenGLImpl(mode);
- openGLMode = mode;
- haveSetOpenGLMode = true;
- }
- public final GLBackendType getOpenGLMode() { return openGLMode; }
-
- protected void initOpenGLImpl(final GLBackendType backend) {
- switch (backend) {
- case NSOPENGL:
- impl = new NSOpenGLImpl();
- break;
- case CGL:
- impl = new CGLImpl();
- break;
- default:
- throw new InternalError("Illegal implementation mode " + backend);
- }
- }
-
- @Override
- public String toString() {
- final StringBuilder sb = new StringBuilder();
- sb.append(getClass().getSimpleName());
- sb.append(" [");
- super.append(sb);
- sb.append(", mode ");
- sb.append(openGLMode);
- sb.append("] ");
- return sb.toString();
- }
-
- // NSOpenGLContext-based implementation
- class NSOpenGLImpl implements GLBackendImpl {
- private OffscreenLayerSurface backingLayerHost = null;
- /** lifecycle: [create - destroy] */
- private long pixelFormat = 0;
- /** microSec - defaults to 1/60s */
- private int screenVSyncTimeout = 16666;
- /** microSec - for nsOpenGLLayer mode - defaults to 1/60s + 1ms */
- private volatile int vsyncTimeout = 16666 + 1000;
- private int lastWidth=0, lastHeight=0; // allowing to detect size change
- private boolean needsSetContextPBuffer = false;
- private ShaderProgram gl3ShaderProgram = null;
-
- @Override
- public boolean isNSContext() { return true; }
-
- @Override
- public boolean isUsingCALayer() { return null != backingLayerHost; }
-
- /** Only returns a valid NSView. If !NSView, return null and mark either isPBuffer, isFBO or isSurfaceless. */
- private long getNSViewHandle(final boolean[] isPBuffer, final boolean[] isFBO, final boolean[] isSurfaceless) {
- final long nsViewHandle;
- if(drawable instanceof GLFBODrawableImpl) {
- nsViewHandle = 0;
- isPBuffer[0] = false;
- isFBO[0] = true;
- isSurfaceless[0] = false;
- if(DEBUG) {
- System.err.println("NS viewHandle.1: GLFBODrawableImpl drawable: isFBO "+isFBO[0]+", isPBuffer "+isPBuffer[0]+", isSurfaceless "+isSurfaceless[0]+", "+drawable.getClass().getName()+",\n\t"+drawable);
- }
- } else {
- final long drawableHandle = drawable.getHandle();
- final boolean isNSView = OSXUtil.isNSView(drawableHandle);
- final boolean isNSWindow = OSXUtil.isNSWindow(drawableHandle);
- isPBuffer[0] = CGL.isNSOpenGLPixelBuffer(drawableHandle);
- isFBO[0] = false;
- isSurfaceless[0] = false;
-
- if( isNSView ) {
- nsViewHandle = drawableHandle;
- } else if( isNSWindow ) {
- nsViewHandle = OSXUtil.GetNSView(drawableHandle);
- } else if( isPBuffer[0] ) {
- nsViewHandle = 0;
- } else if( isSurfaceless() ) {
- isSurfaceless[0] = true;
- nsViewHandle = 0;
- } else {
- throw new GLException("Drawable's handle neither NSView, NSWindow nor PBuffer: drawableHandle "+toHexString(drawableHandle)+", isNSView "+isNSView+", isNSWindow "+isNSWindow+", isFBO "+isFBO[0]+", isPBuffer "+isPBuffer[0]+", "+drawable.getClass().getName()+",\n\t"+drawable);
- }
- if(DEBUG) {
- System.err.println("NS viewHandle.2: drawableHandle "+toHexString(drawableHandle)+" -> nsViewHandle "+toHexString(nsViewHandle)+": isNSView "+isNSView+", isNSWindow "+isNSWindow+", isFBO "+isFBO[0]+", isPBuffer "+isPBuffer[0]+", isSurfaceless "+isSurfaceless[0]+", "+drawable.getClass().getName()+",\n\t"+drawable);
- }
- }
- needsSetContextPBuffer = isPBuffer[0];
- return nsViewHandle;
- }
-
- @Override
- public long create(final long share, final int ctp, final int major, final int minor) {
- long ctx = 0;
- final NativeSurface surface = drawable.getNativeSurface();
- final MacOSXCGLGraphicsConfiguration config = (MacOSXCGLGraphicsConfiguration) surface.getGraphicsConfiguration();
- final GLCapabilitiesImmutable chosenCaps = (GLCapabilitiesImmutable) config.getChosenCapabilities();
- final long nsViewHandle;
- final boolean isPBuffer;
- final boolean isFBO;
- final boolean isSurfaceless;
- {
- final boolean[] _isPBuffer = { false };
- final boolean[] _isFBO = { false };
- final boolean[] _isSurfaceless = { false };
- nsViewHandle = getNSViewHandle(_isPBuffer, _isFBO, _isSurfaceless);
- isPBuffer = _isPBuffer[0];
- isFBO = _isFBO[0];
- isSurfaceless = _isSurfaceless[0];
- }
- final OffscreenLayerSurface backingLayerHost = NativeWindowFactory.getOffscreenLayerSurface(surface, true);
-
- boolean incompleteView = null != backingLayerHost;
- if( !incompleteView && surface instanceof ProxySurface ) {
- incompleteView = ((ProxySurface)surface).containsUpstreamOptionBits( ProxySurface.OPT_UPSTREAM_WINDOW_INVISIBLE );
- }
- {
- final GLCapabilitiesImmutable targetCaps;
- if( isFBO ) {
- // Use minimum GLCapabilities for the target surface w/ same profile
- targetCaps = new GLCapabilities( chosenCaps.getGLProfile() );
- } else {
- targetCaps = chosenCaps;
- }
- pixelFormat = MacOSXCGLGraphicsConfiguration.GLCapabilities2NSPixelFormat(config.getScreen().getDevice(), targetCaps, ctp, major, minor);
- }
- if (pixelFormat == 0) {
- if(DEBUG) {
- System.err.println("Unable to allocate pixel format with requested GLCapabilities: "+chosenCaps);
- }
- return 0;
- }
- final GLCapabilitiesImmutable fixedCaps;
- if( isFBO ) {
- // pixelformat of target doesn't affect caps w/ FBO
- fixedCaps = chosenCaps;
- } else {
- final GLCapabilities _fixedCaps = MacOSXCGLGraphicsConfiguration.NSPixelFormat2GLCapabilities(chosenCaps.getGLProfile(), pixelFormat);
- if( !_fixedCaps.isPBuffer() && isPBuffer ) {
- throw new InternalError("handle is PBuffer, fixedCaps not: "+drawable);
- }
- // determine on-/offscreen caps, since pformat is ambiguous
- _fixedCaps.setPBuffer( isPBuffer ); // exclusive
- _fixedCaps.setBitmap( false ); // n/a in our OSX impl.
- _fixedCaps.setOnscreen( !isFBO && !isPBuffer && !isSurfaceless );
- fixedCaps = GLGraphicsConfigurationUtil.fixOpaqueGLCapabilities(_fixedCaps, chosenCaps.isBackgroundOpaque());
- }
- final int sRefreshRate = OSXUtil.GetScreenRefreshRate(drawable.getNativeSurface().getGraphicsConfiguration().getScreen().getIndex());
- if( 0 < sRefreshRate ) {
- screenVSyncTimeout = 1000000 / sRefreshRate;
- }
- if(DEBUG) {
- System.err.println("NS create OSX>=lion "+isLionOrLater+", OSX>=mavericks "+isMavericksOrLater);
- System.err.println("NS create incompleteView: "+incompleteView);
- System.err.println("NS create backingLayerHost: "+backingLayerHost);
- System.err.println("NS create share: "+share);
- System.err.println("NS create drawable type: "+drawable.getClass().getName());
- System.err.println("NS create drawable handle: isPBuffer "+isPBuffer+", isFBO "+isFBO+", isSurfaceless "+isSurfaceless);
- System.err.println("NS create pixelFormat: "+toHexString(pixelFormat));
- System.err.println("NS create chosenCaps: "+chosenCaps);
- System.err.println("NS create fixedCaps: "+fixedCaps);
- System.err.println("NS create drawable native-handle: "+toHexString(drawable.getHandle()));
- System.err.println("NS create drawable NSView-handle: "+toHexString(nsViewHandle));
- System.err.println("NS create screen refresh-rate: "+sRefreshRate+" hz, "+screenVSyncTimeout+" micros");
- // Thread.dumpStack();
- }
- config.setChosenCapabilities(fixedCaps);
-
- final IntBuffer viewNotReady = Buffers.newDirectIntBuffer(1);
- // Try to allocate a context with this
- ctx = CGL.createContext(share, nsViewHandle, incompleteView,
- pixelFormat, chosenCaps.isBackgroundOpaque(), viewNotReady);
- if (0 == ctx) {
- if(DEBUG) {
- System.err.println("NS create failed: viewNotReady: "+ (1 == viewNotReady.get(0)));
- }
- return 0;
- }
-
- if (chosenCaps.isOnscreen() && !chosenCaps.isBackgroundOpaque()) {
- // Set the context opacity
- CGL.setContextOpacity(ctx, 0);
- }
- return ctx;
- }
-
- @Override
- public boolean destroy(final long ctx) {
- if(0!=pixelFormat) {
- CGL.deletePixelFormat(pixelFormat);
- pixelFormat = 0;
- }
- return CGL.deleteContext(ctx, true);
- }
-
- /**
- * NSOpenGLLayer creation and it's attachment is performed on the main-thread w/o [infinite] blocking.
- *
- * Since NSOpenGLLayer creation requires this context for it's shared context creation,
- * this method attempts to acquire the surface and context lock with {@link #screenVSyncTimeout}/2 maximum wait time.
- * If the surface and context lock could not be acquired, this runnable is being re-queued for later execution.
- *
- *
- * Hence this method blocks the main-thread only for a short period of time.
- *
- */
- class AttachGLLayerCmd implements Runnable {
- final OffscreenLayerSurface ols;
- final long ctx;
- final int shaderProgram;
- final long pfmt;
- final long pbuffer;
- final int texID;
- final boolean isOpaque;
- final int texWidth;
- final int texHeight;
- final int winWidth;
- final int winHeight;
- /** Synchronized by instance's monitor */
- long nsOpenGLLayer;
- /** Synchronized by instance's monitor */
- boolean valid;
-
- AttachGLLayerCmd(final OffscreenLayerSurface ols, final long ctx, final int shaderProgram, final long pfmt, final long pbuffer, final int texID,
- final boolean isOpaque, final int texWidth, final int texHeight, final int winWidth, final int winHeight) {
- this.ols = ols;
- this.ctx = ctx;
- this.shaderProgram = shaderProgram;
- this.pfmt = pfmt;
- this.pbuffer = pbuffer;
- this.texID = texID;
- this.isOpaque = isOpaque;
- this.texWidth = texWidth;
- this.texHeight = texHeight;
- this.winWidth = winWidth;
- this.winHeight = winHeight;
- this.valid = false;
- this.nsOpenGLLayer = 0;
- }
-
- public final String contentToString() {
- return "valid "+valid+", size tex["+texWidth+"x"+texHeight+"], win["+winWidth+"x"+winHeight+"], ctx "+toHexString(ctx)+", opaque "+isOpaque+", texID "+texID+", pbuffer "+toHexString(pbuffer)+", nsOpenGLLayer "+toHexString(nsOpenGLLayer);
- }
-
- @Override
- public final String toString() {
- return "AttachGLLayerCmd["+contentToString()+"]";
- }
-
- @Override
- public void run() {
- synchronized(this) {
- if( !valid ) {
- try {
- final int maxwait = screenVSyncTimeout/2000; // TO 1/2 of current screen-vsync in [ms]
- final RecursiveLock surfaceLock = ols.getLock();
- if( surfaceLock.tryLock( maxwait ) ) {
- try {
- if( MacOSXCGLContext.this.lock.tryLock( maxwait ) ) {
- try {
- nsOpenGLLayer = CGL.createNSOpenGLLayer(ctx, shaderProgram, pfmt, pbuffer, texID, isOpaque,
- texWidth, texHeight, winWidth, winHeight);
- ols.attachSurfaceLayer(nsOpenGLLayer);
- final int currentInterval = MacOSXCGLContext.this.getSwapInterval();
- final int interval = 0 <= currentInterval ? currentInterval : 1;
- setSwapIntervalImpl(nsOpenGLLayer, interval); // enabled per default in layered surface
- valid = true;
- if (DEBUG) {
- System.err.println("NSOpenGLLayer.Attach: OK, layer "+toHexString(nsOpenGLLayer)+" w/ pbuffer "+toHexString(pbuffer)+", texID "+texID+", texSize "+lastWidth+"x"+lastHeight+", drawableHandle "+toHexString(drawable.getHandle())+" - "+getThreadName());
- }
- } finally {
- MacOSXCGLContext.this.lock.unlock();
- }
- }
- } finally {
- surfaceLock.unlock();
- }
- }
- } catch (final InterruptedException e) {
- e.printStackTrace();
- }
- if( !valid ) {
- // could not acquire lock, re-queue
- if (DEBUG) {
- System.err.println("NSOpenGLLayer.Attach: Re-Queue, drawableHandle "+toHexString(drawable.getHandle())+" - "+getThreadName());
- }
- OSXUtil.RunLater(true /* onMain */, this, 1);
- }
- }
- }
- }
- }
- AttachGLLayerCmd attachGLLayerCmd = null;
-
- class DetachGLLayerCmd implements Runnable {
- final AttachGLLayerCmd cmd;
-
- DetachGLLayerCmd(final AttachGLLayerCmd cmd) {
- this.cmd = cmd;
- }
-
- @Override
- public final String toString() {
- return "DetachGLLayerCmd["+cmd.contentToString()+"]";
- }
-
- @Override
- public void run() {
- synchronized( cmd ) {
- if( cmd.valid ) {
- // still having a valid OLS attached to surface (parent OLS could have been removed)
- try {
- final OffscreenLayerSurface ols = cmd.ols;
- final long l = ols.getAttachedSurfaceLayer();
- if( 0 != l ) {
- ols.detachSurfaceLayer();
- }
- } catch(final Throwable t) {
- System.err.println("Caught exception on thread "+getThreadName());
- t.printStackTrace();
- }
- CGL.releaseNSOpenGLLayer(cmd.nsOpenGLLayer);
- if(DEBUG) {
- System.err.println("NSOpenGLLayer.Detach: OK, layer "+toHexString(cmd.nsOpenGLLayer)+" - "+getThreadName());
- }
- cmd.nsOpenGLLayer = 0;
- cmd.valid = false;
- } else if(DEBUG) {
- System.err.println("NSOpenGLLayer.Detach: Skipped "+toHexString(cmd.nsOpenGLLayer)+" - "+getThreadName());
- }
- }
- }
- }
-
- @Override
- public void associateDrawable(final boolean bound) {
- backingLayerHost = NativeWindowFactory.getOffscreenLayerSurface(drawable.getNativeSurface(), true);
-
- if(DEBUG) {
- System.err.println("MaxOSXCGLContext.NSOpenGLImpl.associateDrawable: "+bound+", ctx "+toHexString(contextHandle)+
- ", hasBackingLayerHost "+(null!=backingLayerHost)+", attachGLLayerCmd "+attachGLLayerCmd);
- // Thread.dumpStack();
- }
-
- if( bound ) {
- if( null != backingLayerHost ) {
- final GLCapabilitiesImmutable chosenCaps;
- final long ctx;
- final int texID;
- final long pbufferHandle;
- final int gl3ShaderProgramName;
-
- //
- // handled layered surface
- //
- chosenCaps = drawable.getChosenGLCapabilities();
- ctx = MacOSXCGLContext.this.getHandle();
- final long drawableHandle = drawable.getHandle();
- if(drawable instanceof GLFBODrawableImpl) {
- final GLFBODrawableImpl fbod = (GLFBODrawableImpl)drawable;
- texID = fbod.getColorbuffer(GL.GL_FRONT).getName();
- pbufferHandle = 0;
- fbod.setSwapBufferContext(new GLFBODrawableImpl.SwapBufferContext() {
- @Override
- public void swapBuffers(final boolean doubleBuffered) {
- MacOSXCGLContext.NSOpenGLImpl.this.swapBuffers();
- } } ) ;
- } else if( CGL.isNSOpenGLPixelBuffer(drawableHandle) ) {
- texID = 0;
- pbufferHandle = drawableHandle;
- if(0 != drawableHandle) { // complete 'validatePBufferConfig(..)' procedure
- CGL.setContextPBuffer(ctx, pbufferHandle);
- needsSetContextPBuffer = false;
- }
- } else {
- throw new GLException("BackingLayerHost w/ unknown handle (!FBO, !PBuffer): "+drawable);
- }
- lastWidth = drawable.getSurfaceWidth();
- lastHeight = drawable.getSurfaceHeight();
- if(0>=lastWidth || 0>=lastHeight || !drawable.isRealized()) {
- throw new GLException("Drawable not realized yet or invalid texture size, texSize "+lastWidth+"x"+lastHeight+", "+drawable);
- }
- if( MacOSXCGLContext.this.isGL3core() ) {
- if( null == gl3ShaderProgram) {
- gl3ShaderProgram = createCALayerShader(MacOSXCGLContext.this.gl.getGL3ES3());
- }
- gl3ShaderProgramName = gl3ShaderProgram.program();
- } else {
- gl3ShaderProgramName = 0;
- }
-
- // All CALayer lifecycle ops are deferred on main-thread
- final int[] winSize = drawable.getNativeSurface().convertToWindowUnits(new int[]{ lastWidth, lastHeight });
- attachGLLayerCmd = new AttachGLLayerCmd(
- backingLayerHost, ctx, gl3ShaderProgramName, pixelFormat, pbufferHandle, texID,
- chosenCaps.isBackgroundOpaque(), lastWidth, lastHeight, winSize[0], winSize[1] );
- if(DEBUG) {
- System.err.println("MaxOSXCGLContext.NSOpenGLImpl.associateDrawable(true): "+attachGLLayerCmd);
- }
- OSXUtil.RunOnMainThread(false, false /* kickNSApp */, attachGLLayerCmd);
- } else { // -> null == backingLayerHost
- lastWidth = drawable.getSurfaceWidth();
- lastHeight = drawable.getSurfaceHeight();
- final boolean[] isPBuffer = { false };
- final boolean[] isFBO = { false };
- final boolean[] isSurfaceless = { false };
- CGL.setContextView(contextHandle, getNSViewHandle(isPBuffer, isFBO, isSurfaceless));
- }
- } else { // -> !bound
- if( null != backingLayerHost ) {
- final AttachGLLayerCmd cmd = attachGLLayerCmd;
- attachGLLayerCmd = null;
- if( null == cmd ) {
- throw new GLException("Null attachGLLayerCmd: "+drawable);
- }
- if( 0 != cmd.pbuffer ) {
- CGL.setContextPBuffer(contextHandle, 0);
- }
- synchronized(cmd) {
- if( !cmd.valid ) {
- cmd.valid = true; // skip pending creation
- } else {
- // All CALayer lifecycle ops are deferred on main-thread
- final DetachGLLayerCmd dCmd = new DetachGLLayerCmd(cmd);
- if(DEBUG) {
- System.err.println("MaxOSXCGLContext.NSOpenGLImpl.associateDrawable(false): "+dCmd);
- }
- // OSXUtil.RunOnMainThread(false, true /* kickNSApp */, dCmd);
- OSXUtil.RunOnMainThread(false, false /* kickNSApp */, dCmd);
- if( null != gl3ShaderProgram ) {
- gl3ShaderProgram.destroy(MacOSXCGLContext.this.gl.getGL3());
- gl3ShaderProgram = null;
- }
- }
- }
- }
- CGL.clearDrawable(contextHandle);
- backingLayerHost = null;
- }
- }
-
- private final void validatePBufferConfig(final long ctx) {
- final long drawableHandle = drawable.getHandle();
- if( needsSetContextPBuffer && 0 != drawableHandle && CGL.isNSOpenGLPixelBuffer(drawableHandle) ) {
- // Must associate the pbuffer with our newly-created context
- needsSetContextPBuffer = false;
- CGL.setContextPBuffer(ctx, drawableHandle);
- if(DEBUG) {
- System.err.println("NS.validateDrawableConfig bind pbuffer "+toHexString(drawableHandle)+" -> ctx "+toHexString(ctx));
- }
- }
- }
-
- /** Returns true if size has been updated, otherwise false (same size). */
- private final boolean validateDrawableSizeConfig(final long ctx) {
- final int width = drawable.getSurfaceWidth();
- final int height = drawable.getSurfaceHeight();
- if( lastWidth != width || lastHeight != height ) {
- lastWidth = drawable.getSurfaceWidth();
- lastHeight = drawable.getSurfaceHeight();
- if(DEBUG) {
- System.err.println("NS.validateDrawableConfig size changed");
- }
- return true;
- }
- return false;
- }
-
- @Override
- public boolean copyImpl(final long src, final int mask) {
- CGL.copyContext(contextHandle, src, mask);
- return true;
- }
-
- @Override
- public boolean makeCurrent(final long ctx) {
- final long cglCtx = CGL.getCGLContext(ctx);
- if(0 == cglCtx) {
- throw new InternalError("Null CGLContext for: "+this);
- }
- final int err = CGL.CGLLockContext(cglCtx);
- if(CGL.kCGLNoError == err) {
- validatePBufferConfig(ctx); // required to handle pbuffer change ASAP
- return CGL.makeCurrentContext(ctx);
- } else if(DEBUG) {
- System.err.println("NSGL: Could not lock context: err 0x"+Integer.toHexString(err)+": "+this);
- }
- return false;
- }
-
- @Override
- public boolean release(final long ctx) {
- try {
- if( hasRendererQuirk(GLRendererQuirks.GLFlushBeforeRelease) && null != MacOSXCGLContext.this.getGLProcAddressTable() ) {
- gl.glFlush();
- }
- } catch (final GLException gle) {
- if(DEBUG) {
- System.err.println("MacOSXCGLContext.NSOpenGLImpl.release: INFO: glFlush() caught exception:");
- gle.printStackTrace();
- }
- }
- final boolean res = CGL.clearCurrentContext(ctx);
- final long cglCtx = CGL.getCGLContext(ctx);
- if(0 == cglCtx) {
- throw new InternalError("Null CGLContext for: "+this);
- }
- final int err = CGL.CGLUnlockContext(cglCtx);
- if(DEBUG && CGL.kCGLNoError != err) {
- System.err.println("CGL: Could not unlock context: err 0x"+Integer.toHexString(err)+": "+this);
- }
- return res && CGL.kCGLNoError == err;
- }
-
- @Override
- public boolean detachPBuffer() {
- needsSetContextPBuffer = true;
- // CGL.setContextPBuffer(contextHandle, 0); // doesn't work, i.e. not taking nil
- return true;
- }
-
- @Override
- public boolean setSwapInterval(final int interval) {
- final AttachGLLayerCmd cmd = attachGLLayerCmd;
- if(null != cmd) {
- synchronized(cmd) {
- if( cmd.valid && 0 != cmd.nsOpenGLLayer) {
- setSwapIntervalImpl(cmd.nsOpenGLLayer, interval);
- return true;
- }
- }
- }
- setSwapIntervalImpl(0, interval);
- return true;
- }
-
- private void setSwapIntervalImpl(final long l, final int interval) {
- if( 0 != l ) {
- CGL.setNSOpenGLLayerSwapInterval(l, interval);
- if( 0 < interval ) {
- vsyncTimeout = interval * screenVSyncTimeout + 1000; // +1ms
- } else {
- vsyncTimeout = 1 * screenVSyncTimeout + 1000; // +1ms
- }
- if(DEBUG) { System.err.println("NS setSwapInterval: "+interval+" -> "+vsyncTimeout+" micros"); }
- }
- if(DEBUG) { System.err.println("CGL setSwapInterval: "+interval); }
- CGL.setSwapInterval(contextHandle, interval);
- }
-
- private int skipSync=0;
- /** TODO: Remove after discussion
- private boolean perfIterReset = false;
- private int perfIter = 0;
- private long waitGLS = 0;
- private long finishGLS = 0;
- private long frameXS = 0;
- private long lastFrameStart = 0;
- */
-
- @Override
- public boolean swapBuffers() {
- final AttachGLLayerCmd cmd = attachGLLayerCmd;
- if(null != cmd) {
- synchronized(cmd) {
- if( cmd.valid && 0 != cmd.nsOpenGLLayer) {
- if( validateDrawableSizeConfig(contextHandle) ) {
- // skip wait-for-vsync for a few frames if size has changed,
- // allowing to update the texture IDs ASAP.
- skipSync = 10;
- }
-
- final boolean res;
- final int texID;
- final boolean valid;
- final boolean isFBO = drawable instanceof GLFBODrawableImpl;
- if( isFBO ){
- texID = ((GLFBODrawableImpl)drawable).getColorbuffer(GL.GL_FRONT).getName();
- valid = 0 != texID;
- } else {
- texID = 0;
- valid = 0 != drawable.getHandle();
- }
- if(valid) {
- res = CGL.flushBuffer(contextHandle);
- if(res) {
- if(0 == skipSync) {
- /** TODO: Remove after discussion
- perfIter++;
- if( !perfIterReset && 100 == perfIter ) {
- perfIterReset = true;
- perfIter = 1;
- waitGLS = 0;
- finishGLS = 0;
- frameXS = 0;
- }
- final long lastFramePeriod0 = TimeUnit.NANOSECONDS.toMicros(System.nanoTime()) - lastFrameStart;
- gl.glFinish(); // Require to finish previous GL rendering to give CALayer proper result
- final long lastFramePeriod1 = TimeUnit.NANOSECONDS.toMicros(System.nanoTime()) - lastFrameStart;
-
- // If v-sync is disabled, frames will be drawn as quickly as possible w/o delay,
- // while still synchronizing w/ CALayer.
- // If v-sync is enabled wait until next swap interval (v-sync).
- CGL.waitUntilNSOpenGLLayerIsReady(cmd.nsOpenGLLayer, vsyncTimeout);
- final long lastFramePeriodX = TimeUnit.NANOSECONDS.toMicros(System.nanoTime()) - lastFrameStart;
-
- final long finishGL = lastFramePeriod1 - lastFramePeriod0;
- final long waitGL = lastFramePeriodX - lastFramePeriod1;
- finishGLS += finishGL;
- waitGLS += waitGL;
- frameXS += lastFramePeriodX;
-
- System.err.println("XXX["+perfIter+"] TO "+vsyncTimeout/1000+" ms, "+
- "lFrame0 "+lastFramePeriod0/1000+" ms, "+
- "lFrameX "+lastFramePeriodX/1000+" / "+frameXS/1000+" ~"+(frameXS/perfIter)/1000.0+" ms, "+
- "finishGL "+finishGL/1000+" / "+finishGLS/1000+" ~"+(finishGLS/perfIter)/1000.0+" ms, "+
- "waitGL "+waitGL/1000+" / "+waitGLS/1000+" ~"+(waitGLS/perfIter)/1000.0+" ms");
- */
- //
- // Required(?) to finish previous GL rendering to give CALayer proper result,
- // i.e. synchronize both threads each w/ their GLContext sharing same resources.
- //
- // FIXME: IMHO this synchronization should be implicitly performed via 'CGL.flushBuffer(contextHandle)' above,
- // in case this will be determined a driver bug - use a QUIRK entry in GLRendererQuirks!
- gl.glFinish();
-
- // If v-sync is disabled, frames will be drawn as quickly as possible w/o delay,
- // while still synchronizing w/ CALayer.
- // If v-sync is enabled wait until next swap interval (v-sync).
- CGL.waitUntilNSOpenGLLayerIsReady(cmd.nsOpenGLLayer, vsyncTimeout);
- } else {
- skipSync--;
- }
- if(isFBO) {
- // trigger CALayer to update incl. possible surface change (texture)
- CGL.setNSOpenGLLayerNeedsDisplayFBO(cmd.nsOpenGLLayer, texID);
- } else {
- // trigger CALayer to update incl. possible surface change (new pbuffer handle)
- CGL.setNSOpenGLLayerNeedsDisplayPBuffer(cmd.nsOpenGLLayer, drawable.getHandle());
- }
- // lastFrameStart = TimeUnit.NANOSECONDS.toMicros(System.nanoTime());
- }
- } else {
- res = true;
- }
- return res;
- }
- }
- }
- return CGL.flushBuffer(contextHandle);
- }
-
- }
-
- class CGLImpl implements GLBackendImpl {
- @Override
- public boolean isNSContext() { return false; }
-
- @Override
- public boolean isUsingCALayer() { return false; }
-
- @Override
- public long create(final long share, final int ctp, final int major, final int minor) {
- long ctx = 0;
- final MacOSXCGLGraphicsConfiguration config = (MacOSXCGLGraphicsConfiguration) drawable.getNativeSurface().getGraphicsConfiguration();
- final GLCapabilitiesImmutable chosenCaps = (GLCapabilitiesImmutable)config.getChosenCapabilities();
- final long pixelFormat = MacOSXCGLGraphicsConfiguration.GLCapabilities2CGLPixelFormat(config.getScreen().getDevice(),
- chosenCaps, ctp, major, minor);
- if (pixelFormat == 0) {
- throw new GLException("Unable to allocate pixel format with requested GLCapabilities");
- }
- try {
- // Create new context
- final PointerBuffer ctxPB = PointerBuffer.allocateDirect(1);
- if (DEBUG) {
- System.err.println("Share context for CGL-based pbuffer context is " + toHexString(share));
- }
- int res = CGL.CGLCreateContext(pixelFormat, share, ctxPB);
- if (res != CGL.kCGLNoError) {
- throw new GLException("Error code " + res + " while creating context");
- }
- ctx = ctxPB.get(0);
-
- if (0 != ctx) {
- GLCapabilities fixedCaps = MacOSXCGLGraphicsConfiguration.CGLPixelFormat2GLCapabilities(pixelFormat);
- fixedCaps = GLGraphicsConfigurationUtil.fixOpaqueGLCapabilities(fixedCaps, chosenCaps.isBackgroundOpaque());
- { // determine on-/offscreen caps, since pformat is ambiguous
- fixedCaps.setFBO( false ); // n/a for CGLImpl
- fixedCaps.setPBuffer( fixedCaps.isPBuffer() && !chosenCaps.isOnscreen() );
- fixedCaps.setBitmap( false ); // n/a in our OSX impl.
- fixedCaps.setOnscreen( !fixedCaps.isPBuffer() );
- }
- config.setChosenCapabilities(fixedCaps);
- if(DEBUG) {
- System.err.println("CGL create fixedCaps: "+fixedCaps);
- }
- if(fixedCaps.isPBuffer()) {
- // Must now associate the pbuffer with our newly-created context
- res = CGL.CGLSetPBuffer(ctx, drawable.getHandle(), 0, 0, 0);
- if (res != CGL.kCGLNoError) {
- throw new GLException("Error code " + res + " while attaching context to pbuffer");
- }
- }
- }
- } finally {
- CGL.CGLDestroyPixelFormat(pixelFormat);
- }
- return ctx;
- }
-
- @Override
- public boolean destroy(final long ctx) {
- return CGL.CGLDestroyContext(ctx) == CGL.kCGLNoError;
- }
-
- @Override
- public void associateDrawable(final boolean bound) {
- }
-
- @Override
- public boolean copyImpl(final long src, final int mask) {
- CGL.CGLCopyContext(src, contextHandle, mask);
- return true;
- }
-
- @Override
- public boolean makeCurrent(final long ctx) {
- int err = CGL.CGLLockContext(ctx);
- if(CGL.kCGLNoError == err) {
- err = CGL.CGLSetCurrentContext(ctx);
- if(CGL.kCGLNoError == err) {
- return true;
- } else if(DEBUG) {
- System.err.println("CGL: Could not make context current: err 0x"+Integer.toHexString(err)+": "+this);
- }
- } else if(DEBUG) {
- System.err.println("CGL: Could not lock context: err 0x"+Integer.toHexString(err)+": "+this);
- }
- return false;
- }
-
- @Override
- public boolean release(final long ctx) {
- try {
- if( hasRendererQuirk(GLRendererQuirks.GLFlushBeforeRelease) && null != MacOSXCGLContext.this.getGLProcAddressTable() ) {
- gl.glFlush();
- }
- } catch (final GLException gle) {
- if(DEBUG) {
- System.err.println("MacOSXCGLContext.CGLImpl.release: INFO: glFlush() caught exception:");
- gle.printStackTrace();
- }
- }
- final int err = CGL.CGLSetCurrentContext(0);
- if(DEBUG && CGL.kCGLNoError != err) {
- System.err.println("CGL: Could not release current context: err 0x"+Integer.toHexString(err)+": "+this);
- }
- final int err2 = CGL.CGLUnlockContext(ctx);
- if(DEBUG && CGL.kCGLNoError != err2) {
- System.err.println("CGL: Could not unlock context: err 0x"+Integer.toHexString(err2)+": "+this);
- }
- return CGL.kCGLNoError == err && CGL.kCGLNoError == err2;
- }
-
- @Override
- public boolean detachPBuffer() {
- /* Doesn't work, i.e. not taking NULL
- final int res = CGL.CGLSetPBuffer(contextHandle, 0, 0, 0, 0);
- if (res != CGL.kCGLNoError) {
- throw new GLException("Error code " + res + " while detaching context from pbuffer");
- } */
- return true;
- }
-
- @Override
- public boolean setSwapInterval(final int interval) {
- final IntBuffer lval = Buffers.newDirectIntBuffer(1);
- lval.put(0, interval);
- CGL.CGLSetParameter(contextHandle, CGL.kCGLCPSwapInterval, lval);
- return true;
- }
- @Override
- public boolean swapBuffers() {
- return CGL.kCGLNoError == CGL.CGLFlushDrawable(contextHandle);
- }
- }
-}
diff --git a/lib-external/jogl-gluegen/patch/MacOSXJAWTWindow.java b/lib-external/jogl-gluegen/patch/MacOSXJAWTWindow.java
deleted file mode 100644
index ece4310d1e..0000000000
--- a/lib-external/jogl-gluegen/patch/MacOSXJAWTWindow.java
+++ /dev/null
@@ -1,448 +0,0 @@
-/*
- * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
- * Copyright (c) 2010 JogAmp Community. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * - Redistribution of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistribution in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * Neither the name of Sun Microsystems, Inc. or the names of
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * This software is provided "AS IS," without a warranty of any kind. ALL
- * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
- * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
- * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
- * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
- * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
- * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
- * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
- * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
- * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
- * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
- * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
- *
- * You acknowledge that this software is not designed or intended for use
- * in the design, construction, operation or maintenance of any nuclear
- * facility.
- *
- * Sun gratefully acknowledges that this software was originally authored
- * and developed by Kenneth Bradley Russell and Christopher John Kline.
- */
-
-package jogamp.nativewindow.jawt.macosx;
-
-import java.awt.Component;
-import java.awt.GraphicsConfiguration;
-import java.nio.Buffer;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-
-import com.jogamp.nativewindow.AbstractGraphicsConfiguration;
-import com.jogamp.nativewindow.Capabilities;
-import com.jogamp.nativewindow.NativeSurface;
-import com.jogamp.nativewindow.NativeWindowException;
-import com.jogamp.nativewindow.MutableSurface;
-import com.jogamp.nativewindow.util.Point;
-
-import com.jogamp.common.util.PropertyAccess;
-import com.jogamp.nativewindow.awt.JAWTWindow;
-
-import jogamp.nativewindow.Debug;
-import jogamp.nativewindow.awt.AWTMisc;
-import jogamp.nativewindow.jawt.JAWT;
-import jogamp.nativewindow.jawt.JAWTFactory;
-import jogamp.nativewindow.jawt.JAWTUtil;
-import jogamp.nativewindow.jawt.JAWT_DrawingSurface;
-import jogamp.nativewindow.jawt.JAWT_DrawingSurfaceInfo;
-import jogamp.nativewindow.jawt.macosx.JAWT_MacOSXDrawingSurfaceInfo;
-import jogamp.nativewindow.macosx.OSXUtil;
-
-public class MacOSXJAWTWindow extends JAWTWindow implements MutableSurface {
- /** May lead to deadlock, due to AWT pos comparison .. don't enable for Applets! */
- private static final boolean DEBUG_CALAYER_POS_CRITICAL;
-
- static {
- Debug.initSingleton();
- DEBUG_CALAYER_POS_CRITICAL = PropertyAccess.isPropertyDefined("nativewindow.debug.JAWT.OSXCALayerPos", true /* jnlpAlias */);
- }
-
- public MacOSXJAWTWindow(final Object comp, final AbstractGraphicsConfiguration config) {
- super(comp, config);
- if(DEBUG) {
- dumpInfo();
- }
- }
-
- @Override
- protected void invalidateNative() {
- if(DEBUG) {
- System.err.println("MacOSXJAWTWindow.invalidateNative(): osh-enabled "+isOffscreenLayerSurfaceEnabled()+
- ", osd-set "+offscreenSurfaceDrawableSet+
- ", osd "+toHexString(offscreenSurfaceDrawable)+
- ", osl "+toHexString(getAttachedSurfaceLayer())+
- ", rsl "+toHexString(rootSurfaceLayer)+
- ", wh "+toHexString(windowHandle)+" - "+Thread.currentThread().getName());
- }
- offscreenSurfaceDrawable=0;
- offscreenSurfaceDrawableSet=false;
- if( isOffscreenLayerSurfaceEnabled() ) {
- if(0 != windowHandle) {
- OSXUtil.DestroyNSWindow(windowHandle);
- }
- // OSXUtil.RunOnMainThread(false, true /* kickNSApp */, new Runnable() {
- OSXUtil.RunOnMainThread(false, false /* kickNSApp */, new Runnable() {
- @Override
- public void run() {
- if( 0 != jawtSurfaceLayersHandle) {
- // null rootSurfaceLayer OK
- UnsetJAWTRootSurfaceLayer0(jawtSurfaceLayersHandle, rootSurfaceLayer);
- }
- jawtSurfaceLayersHandle = 0;
- if( 0 != rootSurfaceLayer ) {
- OSXUtil.DestroyCALayer(rootSurfaceLayer);
- rootSurfaceLayer = 0;
- }
- }
- });
- }
- windowHandle=0;
- }
-
- @Override
- public boolean setSurfaceScale(final float[] pixelScale) {
- super.setSurfaceScale(pixelScale);
- if( 0 != getWindowHandle() && setReqPixelScale() ) { // locked at least once _and_ updated pixel-scale
- if( 0 != getAttachedSurfaceLayer() ) {
- OSXUtil.RunOnMainThread(false, false, new Runnable() {
- @Override
- public void run() {
- final long osl = getAttachedSurfaceLayer();
- if( 0 != osl ) {
- OSXUtil.SetCALayerPixelScale(rootSurfaceLayer, osl, getPixelScaleX());
- }
- }
- });
- }
- return true;
- } else {
- return false;
- }
- }
-
- @Override
- protected void attachSurfaceLayerImpl(final long layerHandle) {
- OSXUtil.RunOnMainThread(false, false /* kickNSApp */, new Runnable() {
- @Override
- public void run() {
- // AWT position is top-left w/ insets, where CALayer position is bottom/left from root CALayer w/o insets.
- // Determine p0: components location on screen w/o insets.
- // CALayer position will be determined in native code.
- // See detailed description in {@link JAWTUtil#JAWT_OSX_CALAYER_QUIRK_LAYOUT}
- final Point p0 = new Point();
- final Component outterComp = AWTMisc.getLocationOnScreenNonBlocking(p0, component, DEBUG);
- final java.awt.Insets outterInsets = AWTMisc.getInsets(outterComp, true);
- final Point p1 = (Point)p0.cloneMutable();
- p1.translate(-outterComp.getX(), -outterComp.getY());
- if( null != outterInsets ) {
- p1.translate(-outterInsets.left, -outterInsets.top);
- }
-
- if( DEBUG_CALAYER_POS_CRITICAL ) {
- final java.awt.Point pA0 = component.getLocationOnScreen();
- final Point pA1 = new Point(pA0.x, pA0.y);
- pA1.translate(-outterComp.getX(), -outterComp.getY());
- if( null != outterInsets ) {
- pA1.translate(-outterInsets.left, -outterInsets.top);
- }
- System.err.println("JAWTWindow.attachSurfaceLayerImpl: "+toHexString(layerHandle) + ", [ins "+outterInsets+"], pA "+pA0+" -> "+pA1+
- ", p0 "+p0+" -> "+p1+", bounds "+bounds);
- } else if( DEBUG ) {
- System.err.println("JAWTWindow.attachSurfaceLayerImpl: "+toHexString(layerHandle) + ", [ins "+outterInsets+"], p0 "+p0+" -> "+p1+", bounds "+bounds);
- }
- // HiDPI: uniform pixel scale
- OSXUtil.AddCASublayer(rootSurfaceLayer, layerHandle, p1.getX(), p1.getY(), getWidth(), getHeight(), getPixelScaleX(), JAWTUtil.getOSXCALayerQuirks());
- } } );
- }
-
- @Override
- protected void layoutSurfaceLayerImpl(final long layerHandle, final boolean visible) {
- final int caLayerQuirks = JAWTUtil.getOSXCALayerQuirks();
- // AWT position is top-left w/ insets, where CALayer position is bottom/left from root CALayer w/o insets.
- // Determine p0: components location on screen w/o insets.
- // CALayer position will be determined in native code.
- // See detailed description in {@link JAWTUtil#JAWT_OSX_CALAYER_QUIRK_LAYOUT}
- final Point p0 = new Point();
- final Component outterComp = AWTMisc.getLocationOnScreenNonBlocking(p0, component, DEBUG);
- final java.awt.Insets outterInsets = AWTMisc.getInsets(outterComp, true);
- final Point p1 = (Point)p0.cloneMutable();
- p1.translate(-outterComp.getX(), -outterComp.getY());
- if( null != outterInsets ) {
- p1.translate(-outterInsets.left, -outterInsets.top);
- }
-
- if( DEBUG_CALAYER_POS_CRITICAL ) {
- final java.awt.Point pA0 = component.getLocationOnScreen();
- final Point pA1 = new Point(pA0.x, pA0.y);
- pA1.translate(-outterComp.getX(), -outterComp.getY());
- if( null != outterInsets ) {
- pA1.translate(-outterInsets.left, -outterInsets.top);
- }
- System.err.println("JAWTWindow.layoutSurfaceLayerImpl: "+toHexString(layerHandle) + ", quirks "+caLayerQuirks+", visible "+visible+
- ", [ins "+outterInsets+"], pA "+pA0+" -> "+pA1+
- ", p0 "+p0+" -> "+p1+", bounds "+bounds);
- } else if( DEBUG ) {
- System.err.println("JAWTWindow.layoutSurfaceLayerImpl: "+toHexString(layerHandle) + ", quirks "+caLayerQuirks+", visible "+visible+
- ", [ins "+outterInsets+"], p0 "+p0+" -> "+p1+", bounds "+bounds);
- }
- OSXUtil.FixCALayerLayout(rootSurfaceLayer, layerHandle, visible, p1.getX(), p1.getY(), getWidth(), getHeight(), caLayerQuirks);
- }
-
- @Override
- protected void detachSurfaceLayerImpl(final long layerHandle, final Runnable detachNotify) {
- OSXUtil.RunOnMainThread(false, true /* kickNSApp */, new Runnable() {
- @Override
- public void run() {
- detachNotify.run();
- OSXUtil.RemoveCASublayer(rootSurfaceLayer, layerHandle);
- } });
- }
-
- @Override
- public final long getWindowHandle() {
- return windowHandle;
- }
-
- @Override
- public final long getSurfaceHandle() {
- return offscreenSurfaceDrawableSet ? offscreenSurfaceDrawable : drawable /* super.getSurfaceHandle() */ ;
- }
-
- @Override
- public void setSurfaceHandle(final long surfaceHandle) {
- if( !isOffscreenLayerSurfaceEnabled() ) {
- throw new java.lang.UnsupportedOperationException("Not using CALAYER");
- }
- if(DEBUG) {
- System.err.println("MacOSXJAWTWindow.setSurfaceHandle(): "+toHexString(surfaceHandle));
- }
- this.offscreenSurfaceDrawable = surfaceHandle;
- this.offscreenSurfaceDrawableSet = true;
- }
-
- @Override
- protected JAWT fetchJAWTImpl() throws NativeWindowException {
- // use offscreen if supported and [ applet or requested ]
- return JAWTUtil.getJAWT(getShallUseOffscreenLayer() || isApplet());
- }
-
- @Override
- protected int lockSurfaceImpl(final GraphicsConfiguration gc) throws NativeWindowException {
- int ret = NativeSurface.LOCK_SURFACE_NOT_READY;
- ds = getJAWT().GetDrawingSurface(component);
- if (ds == null) {
- // Widget not yet realized
- unlockSurfaceImpl();
- return NativeSurface.LOCK_SURFACE_NOT_READY;
- }
- final int res = ds.Lock();
- dsLocked = ( 0 == ( res & JAWTFactory.JAWT_LOCK_ERROR ) ) ;
- if (!dsLocked) {
- unlockSurfaceImpl();
- throw new NativeWindowException("Unable to lock surface");
- }
- // See whether the surface changed and if so destroy the old
- // OpenGL context so it will be recreated (NOTE: removeNotify
- // should handle this case, but it may be possible that race
- // conditions can cause this code to be triggered -- should test
- // more)
- if ((res & JAWTFactory.JAWT_LOCK_SURFACE_CHANGED) != 0) {
- ret = NativeSurface.LOCK_SURFACE_CHANGED;
- }
- if (firstLock) {
- AccessController.doPrivileged(new PrivilegedAction() {
- @Override
- public Object run() {
- dsi = ds.GetDrawingSurfaceInfo();
- return null;
- }
- });
- } else {
- dsi = ds.GetDrawingSurfaceInfo();
- }
- if (dsi == null) {
- unlockSurfaceImpl();
- return NativeSurface.LOCK_SURFACE_NOT_READY;
- }
- updateLockedData(dsi.getBounds(), gc);
- if (DEBUG && firstLock ) {
- dumpInfo();
- }
- firstLock = false;
- if( !isOffscreenLayerSurfaceEnabled() ) {
- macosxdsi = (JAWT_MacOSXDrawingSurfaceInfo) dsi.platformInfo(getJAWT());
- if (macosxdsi == null) {
- unlockSurfaceImpl();
- return NativeSurface.LOCK_SURFACE_NOT_READY;
- }
- drawable = macosxdsi.getCocoaViewRef();
-
- if (drawable == 0) {
- unlockSurfaceImpl();
- return NativeSurface.LOCK_SURFACE_NOT_READY;
- } else {
- windowHandle = OSXUtil.GetNSWindow(drawable);
- ret = NativeSurface.LOCK_SUCCESS;
- }
- } else {
- /**
- * Only create a fake invisible NSWindow for the drawable handle
- * to please frameworks requiring such (eg. NEWT).
- *
- * The actual surface/ca-layer shall be created/attached
- * by the upper framework (JOGL) since they require more information.
- */
- String errMsg = null;
- if(0 == drawable) {
- windowHandle = OSXUtil.CreateNSWindow(0, 0, 64, 64);
- if(0 == windowHandle) {
- errMsg = "Unable to create dummy NSWindow (layered case)";
- } else {
- drawable = OSXUtil.GetNSView(windowHandle);
- if(0 == drawable) {
- errMsg = "Null NSView of NSWindow "+toHexString(windowHandle);
- }
- }
- if(null == errMsg) {
- // Fix caps reflecting offscreen! (no GL available here ..)
- final Capabilities caps = (Capabilities) getGraphicsConfiguration().getChosenCapabilities().cloneMutable();
- caps.setOnscreen(false);
- setChosenCapabilities(caps);
- }
- }
- if(null == errMsg) {
- jawtSurfaceLayersHandle = GetJAWTSurfaceLayersHandle0(dsi.getBuffer());
- OSXUtil.RunOnMainThread(false, false, new Runnable() {
- @Override
- public void run() {
- String errMsg = null;
- if(0 == rootSurfaceLayer && 0 != jawtSurfaceLayersHandle) {
- rootSurfaceLayer = OSXUtil.CreateCALayer(bounds.getWidth(), bounds.getHeight(), getPixelScaleX()); // HiDPI: uniform pixel scale
- if(0 == rootSurfaceLayer) {
- errMsg = "Could not create root CALayer";
- } else {
- try {
- SetJAWTRootSurfaceLayer0(jawtSurfaceLayersHandle, rootSurfaceLayer);
- } catch(final Exception e) {
- errMsg = "Could not set JAWT rootSurfaceLayerHandle "+toHexString(rootSurfaceLayer)+", cause: "+e.getMessage();
- }
- }
- if(null != errMsg) {
- if(0 != rootSurfaceLayer) {
- OSXUtil.DestroyCALayer(rootSurfaceLayer);
- rootSurfaceLayer = 0;
- }
- throw new NativeWindowException(errMsg+": "+MacOSXJAWTWindow.this);
- }
- }
- } } );
- }
- if(null != errMsg) {
- if(0 != windowHandle) {
- OSXUtil.DestroyNSWindow(windowHandle);
- windowHandle = 0;
- }
- drawable = 0;
- unlockSurfaceImpl();
- throw new NativeWindowException(errMsg+": "+this);
- }
- ret = NativeSurface.LOCK_SUCCESS;
- }
-
- return ret;
- }
-
- @Override
- protected void unlockSurfaceImpl() throws NativeWindowException {
- if(null!=ds) {
- if (null!=dsi) {
- ds.FreeDrawingSurfaceInfo(dsi);
- }
- if (dsLocked) {
- ds.Unlock();
- }
- getJAWT().FreeDrawingSurface(ds);
- }
- ds = null;
- dsi = null;
- }
-
- private void dumpInfo() {
- System.err.println("MaxOSXJAWTWindow: 0x"+Integer.toHexString(this.hashCode())+" - thread: "+Thread.currentThread().getName());
- dumpJAWTInfo();
- }
-
- /**
- * {@inheritDoc}
- *
- * On OS X locking the surface at this point (ie after creation and for location validation)
- * is 'tricky' since the JVM traverses through many threads and crashes at:
- * lockSurfaceImpl() {
- * ..
- * ds = getJAWT().GetDrawingSurface(component);
- * due to a SIGSEGV.
- *
- * Hence we have some threading / sync issues with the native JAWT implementation.
- *
- */
- @Override
- public Point getLocationOnScreen(Point storage) {
- if( null == storage ) {
- storage = new Point();
- }
- AWTMisc.getLocationOnScreenNonBlocking(storage, component, DEBUG);
- return storage;
- }
- @Override
- protected Point getLocationOnScreenNativeImpl(final int x0, final int y0) { return null; }
-
-
- private static native long GetJAWTSurfaceLayersHandle0(Buffer jawtDrawingSurfaceInfoBuffer);
-
- /**
- * Set the given root CALayer in the JAWT surface
- */
- private static native void SetJAWTRootSurfaceLayer0(long jawtSurfaceLayersHandle, long caLayer);
-
- /**
- * Unset the given root CALayer in the JAWT surface, passing the NIO DrawingSurfaceInfo buffer
- */
- private static native void UnsetJAWTRootSurfaceLayer0(long jawtSurfaceLayersHandle, long caLayer);
-
- // Variables for lockSurface/unlockSurface
- private JAWT_DrawingSurface ds;
- private boolean dsLocked;
- private JAWT_DrawingSurfaceInfo dsi;
- private long jawtSurfaceLayersHandle;
-
- private JAWT_MacOSXDrawingSurfaceInfo macosxdsi;
-
- private volatile long rootSurfaceLayer = 0; // attached to the JAWT_SurfaceLayer
-
- private long windowHandle = 0;
- private long offscreenSurfaceDrawable = 0;
- private boolean offscreenSurfaceDrawableSet = false;
-
- // Workaround for instance of 4796548
- private boolean firstLock = true;
-
-}
-
diff --git a/lib-external/jogl-gluegen/win-copy-jogl.cmd b/lib-external/jogl-gluegen/win-copy-jogl.cmd
index a02b87af3a..91a0bff02e 100644
--- a/lib-external/jogl-gluegen/win-copy-jogl.cmd
+++ b/lib-external/jogl-gluegen/win-copy-jogl.cmd
@@ -1,8 +1,9 @@
REM Run in a MinGW-W64 Window
copy gluegen\build\gluegen-rt-natives-windows-amd64.jar ..\..
-copy gluegen\build\gluegen-rt.jar ..\..
-copy jogl\build\jar\jogl-all.jar ..\..
+REM Other artifacts are copied by the Linux build.
+REM copy gluegen\build\gluegen-rt.jar ..\..
+REM copy jogl\build\jar\jogl-all.jar ..\..
copy jogl\build\jar\jogl-all-natives-windows-amd64.jar ..\..
diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml
index fe059c4759..c4c6e5f242 100644
--- a/nbproject/build-impl.xml
+++ b/nbproject/build-impl.xml
@@ -119,7 +119,43 @@ is divided into following sections:
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must set platform.home
+ Must set platform.bootcp
+ Must set platform.java
+ Must set platform.javac
+
+ The J2SE Platform is not correctly set up.
+ Your active platform is: ${platform.active}, but the corresponding property "platforms.${platform.active}.home" is not found in the project's properties files.
+ Either open the project in the IDE and setup the Platform with the same name or add it manually.
+ For example like this:
+ ant -Duser.properties.file=<path_to_property_file> jar (where you put the property "platforms.${platform.active}.home" in a .properties file)
+ or ant -Dplatforms.${platform.active}.home=<path_to_JDK_home> jar (where no properties file is used)
+
@@ -254,20 +290,6 @@ is divided into following sections:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -355,7 +377,7 @@ is divided into following sections:
-
+
@@ -406,7 +428,7 @@ is divided into following sections:
-
+
@@ -448,7 +470,7 @@ is divided into following sections:
-
+
@@ -527,7 +549,7 @@ is divided into following sections:
-
+
@@ -555,7 +577,7 @@ is divided into following sections:
-
+
@@ -631,7 +653,7 @@ is divided into following sections:
-
+
@@ -862,6 +884,9 @@ is divided into following sections:
+
+
+
@@ -911,7 +936,7 @@ is divided into following sections:
-
+
@@ -945,7 +970,7 @@ is divided into following sections:
-
+
@@ -977,7 +1002,7 @@ is divided into following sections:
-
+
@@ -1197,7 +1222,7 @@ is divided into following sections:
To run this application from the command line without Ant, try:
- java -jar "${dist.jar.resolved}"
+ ${platform.java} -jar "${dist.jar.resolved}"
@@ -1299,8 +1324,8 @@ is divided into following sections:
-
-
+
+
@@ -1493,16 +1518,19 @@ is divided into following sections:
+
+
+
-
+
-
+
-
+
diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties
index f1211eae1a..b9f018bb30 100644
--- a/nbproject/genfiles.properties
+++ b/nbproject/genfiles.properties
@@ -1,8 +1,8 @@
-build.xml.data.CRC32=6106e3d1
+build.xml.data.CRC32=ed839dc9
build.xml.script.CRC32=b2ee8dee
build.xml.stylesheet.CRC32=f85dc8f2@1.92.0.48
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
-nbproject/build-impl.xml.data.CRC32=6106e3d1
-nbproject/build-impl.xml.script.CRC32=a1ae9b7f
+nbproject/build-impl.xml.data.CRC32=ed839dc9
+nbproject/build-impl.xml.script.CRC32=e40c9476
nbproject/build-impl.xml.stylesheet.CRC32=3a2fa800@1.92.0.48
diff --git a/nbproject/project.properties b/nbproject/project.properties
index 61a4ae2b29..1adab5d73f 100644
--- a/nbproject/project.properties
+++ b/nbproject/project.properties
@@ -56,8 +56,8 @@ javac.modulepath=
javac.processormodulepath=
javac.processorpath=\
${javac.classpath}
-javac.source=12
-javac.target=12
+javac.source=11
+javac.target=11
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}
@@ -104,7 +104,7 @@ manifest.custom.permissions=
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false
-platform.active=default_platform
+platform.active=JDK_11
run.classpath=\
${javac.classpath}:\
${build.classes.dir}
diff --git a/nbproject/project.xml b/nbproject/project.xml
index e27d90a9ba..cba6c32199 100644
--- a/nbproject/project.xml
+++ b/nbproject/project.xml
@@ -4,6 +4,7 @@
WorldWindJava
+