diff options
Diffstat (limited to 'src/jogl/classes')
7 files changed, 90 insertions, 51 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/swt/GLCanvas.java b/src/jogl/classes/com/jogamp/opengl/swt/GLCanvas.java index ea794cc78..755a7c392 100644 --- a/src/jogl/classes/com/jogamp/opengl/swt/GLCanvas.java +++ b/src/jogl/classes/com/jogamp/opengl/swt/GLCanvas.java @@ -27,6 +27,8 @@ */ package com.jogamp.opengl.swt; +import java.util.List; + import javax.media.nativewindow.AbstractGraphicsDevice; import javax.media.nativewindow.NativeSurface; import javax.media.nativewindow.ProxySurface; @@ -545,15 +547,15 @@ public class GLCanvas extends Canvas implements GLAutoDrawable { } @Override - public boolean invoke(final boolean wait, final GLRunnable run) { - return helper.invoke(this, wait, run); + public boolean invoke(final boolean wait, final GLRunnable runnable) { + return helper.invoke(this, wait, runnable); } @Override - public void enqueue(GLRunnable glRunnable) { - helper.enqueue(glRunnable); + public boolean invoke(final boolean wait, final List<GLRunnable> runnables) { + return helper.invoke(this, wait, runnables); } - + @Override public void setAnimator(final GLAnimatorControl arg0) throws GLException { helper.setAnimator(arg0); diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLDrawableUtil.java b/src/jogl/classes/com/jogamp/opengl/util/GLDrawableUtil.java index 08eaf0494..cc81e4820 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/GLDrawableUtil.java +++ b/src/jogl/classes/com/jogamp/opengl/util/GLDrawableUtil.java @@ -27,6 +27,9 @@ */ package com.jogamp.opengl.util; +import java.util.ArrayList; +import java.util.List; + import javax.media.opengl.GLAnimatorControl; import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.GLContext; @@ -80,7 +83,7 @@ public class GLDrawableUtil { dest.addGLEventListener(listener); if(preserveInitState && initialized) { dest.setGLEventListenerInitState(listener, true); - dest.enqueue(new ReshapeGLEventListener(listener)); + dest.invoke(false, new ReshapeGLEventListener(listener)); } // else .. !init state is default } @@ -118,6 +121,8 @@ public class GLDrawableUtil { * @param b */ public static final void swapGLContextAndAllGLEventListener(GLAutoDrawable a, GLAutoDrawable b) { + final List<GLRunnable> aGLCmds = new ArrayList<GLRunnable>(); + final List<GLRunnable> bGLCmds = new ArrayList<GLRunnable>(); final GLAnimatorControl aAnim = a.getAnimator(); final GLAnimatorControl bAnim = b.getAnimator(); final boolean aIsPaused = isAnimatorAnimatingOnOtherThread(aAnim) && aAnim.pause(); @@ -146,32 +151,30 @@ public class GLDrawableUtil { // // trigger glFinish to sync GL ctx // - a.enqueue(glFinish); - b.enqueue(glFinish); - a.display(); - b.display(); + a.invoke(true, glFinish); + b.invoke(true, glFinish); // // switch context and // trigger GL-Viewport reset and reshape of all initialized GLEventListeners // b.setContext( a.setContext( b.getContext() ) ); - a.enqueue(setViewport); - b.enqueue(setViewport); + aGLCmds.add(setViewport); + bGLCmds.add(setViewport); for(int i=0; i<aSz; i++) { if( aInit[i] ) { - b.enqueue(new ReshapeGLEventListener(aGLE[i])); + bGLCmds.add(new ReshapeGLEventListener(aGLE[i])); } } for(int i=0; i<bSz; i++) { if( bInit[i] ) { - a.enqueue(new ReshapeGLEventListener(bGLE[i])); + aGLCmds.add(new ReshapeGLEventListener(bGLE[i])); } } - a.enqueue(glFinish); - b.enqueue(glFinish); - a.display(); - b.display(); + aGLCmds.add(glFinish); + bGLCmds.add(glFinish); + a.invoke(true, aGLCmds); + b.invoke(true, bGLCmds); // add all cached GLEventListener to their destination and fix their init-state for(int i=0; i<bSz; i++) { @@ -248,10 +251,8 @@ public class GLDrawableUtil { } dest.setContext( src.setContext( dest.getContext() ) ); - src.enqueue(setViewport); - dest.enqueue(setViewport); - src.display(); - dest.display(); + src.invoke(true, setViewport); + dest.invoke(true, setViewport); if(aIsPaused) { aAnim.resume(); } if(bIsPaused) { bAnim.resume(); } diff --git a/src/jogl/classes/javax/media/opengl/GLAutoDrawable.java b/src/jogl/classes/javax/media/opengl/GLAutoDrawable.java index fc569b13d..0f487f463 100644 --- a/src/jogl/classes/javax/media/opengl/GLAutoDrawable.java +++ b/src/jogl/classes/javax/media/opengl/GLAutoDrawable.java @@ -40,6 +40,8 @@ package javax.media.opengl; +import java.util.List; + import jogamp.opengl.Debug; /** A higher-level abstraction than {@link GLDrawable} which supplies @@ -379,30 +381,16 @@ public interface GLAutoDrawable extends GLDrawable { * @see #enqueue(GLRunnable) */ public boolean invoke(boolean wait, GLRunnable glRunnable); - + /** - * Enqueues a one-shot {@link GLRunnable}, - * which will be executed within the next {@link #display()} call - * after all registered {@link GLEventListener}s - * {@link GLEventListener#display(GLAutoDrawable) display(GLAutoDrawable)} - * methods has been called. - * <p> - * Unlike the {@link #invoke(boolean, GLRunnable)}, this method only enqueues the {@link GLRunnable} - * w/o taking care of it's execution. Hence either a performing {@link GLAnimatorControl animator} - * or explicit user call shall trigger {@link #display()} to ensure it's execution. - * </p> - * <p> - * Method return immediately w/o waiting or blocking - * </p> - * - * @param glRunnable the {@link GLRunnable} to execute within the next {@link #display()} call - * - * @see #invoke(boolean, GLRunnable) - * @see #display() - * @see GLRunnable + * Extends {@link #invoke(boolean, GLRunnable)} functionality + * allowing to inject a list of {@link GLRunnable}s. + * @param wait if <code>true</code> block until execution of the last <code>glRunnable</code> is finished, otherwise return immediately w/o waiting + * @param glRunnables the {@link GLRunnable}s to execute within {@link #display()} + * @return <code>true</code> if the {@link GLRunnable}s has been processed or queued, otherwise <code>false</code>. */ - public void enqueue(GLRunnable glRunnable); - + public boolean invoke(boolean wait, List<GLRunnable> glRunnables); + /** Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext. If a window is attached to it's implementation, it shall be closed. diff --git a/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java b/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java index 5b5f800a4..1d8666e6a 100644 --- a/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java +++ b/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java @@ -57,6 +57,7 @@ import java.awt.geom.Rectangle2D; import java.awt.EventQueue; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; +import java.util.List; import javax.media.nativewindow.AbstractGraphicsConfiguration; import javax.media.nativewindow.OffscreenLayerOption; @@ -746,8 +747,8 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing } @Override - public void enqueue(GLRunnable glRunnable) { - helper.enqueue(glRunnable); + public boolean invoke(final boolean wait, final List<GLRunnable> glRunnables) { + return helper.invoke(this, wait, glRunnables); } @Override diff --git a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java index 08d70211b..58b1baa65 100644 --- a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java +++ b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java @@ -54,6 +54,7 @@ import java.awt.image.DataBufferInt; import java.beans.Beans; import java.nio.ByteBuffer; import java.nio.IntBuffer; +import java.util.List; import javax.media.nativewindow.AbstractGraphicsDevice; import javax.media.nativewindow.NativeSurface; @@ -483,8 +484,8 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing } @Override - public void enqueue(GLRunnable glRunnable) { - helper.enqueue(glRunnable); + public boolean invoke(final boolean wait, final List<GLRunnable> glRunnables) { + return helper.invoke(this, wait, glRunnables); } @Override diff --git a/src/jogl/classes/jogamp/opengl/GLAutoDrawableBase.java b/src/jogl/classes/jogamp/opengl/GLAutoDrawableBase.java index 09a754279..7bcd37ecd 100644 --- a/src/jogl/classes/jogamp/opengl/GLAutoDrawableBase.java +++ b/src/jogl/classes/jogamp/opengl/GLAutoDrawableBase.java @@ -29,6 +29,7 @@ package jogamp.opengl; import java.io.PrintStream; +import java.util.List; import javax.media.nativewindow.AbstractGraphicsDevice; import javax.media.nativewindow.NativeSurface; @@ -412,8 +413,8 @@ public abstract class GLAutoDrawableBase implements GLAutoDrawable, FPSCounter { } @Override - public final void enqueue(GLRunnable glRunnable) { - helper.enqueue(glRunnable); + public boolean invoke(final boolean wait, final List<GLRunnable> glRunnables) { + return helper.invoke(this, wait, glRunnables); } @Override diff --git a/src/jogl/classes/jogamp/opengl/GLDrawableHelper.java b/src/jogl/classes/jogamp/opengl/GLDrawableHelper.java index d891ae810..be63c9278 100644 --- a/src/jogl/classes/jogamp/opengl/GLDrawableHelper.java +++ b/src/jogl/classes/jogamp/opengl/GLDrawableHelper.java @@ -41,6 +41,7 @@ package jogamp.opengl; import java.util.ArrayList; +import java.util.List; import java.util.HashSet; import javax.media.nativewindow.NativeSurface; @@ -691,9 +692,9 @@ public class GLDrawableHelper { return false; } - Throwable throwable = null; GLRunnableTask rTask = null; Object rTaskLock = new Object(); + Throwable throwable = null; synchronized(rTaskLock) { final boolean deferred; synchronized(glRunnablesLock) { @@ -724,6 +725,50 @@ public class GLDrawableHelper { } return true; } + + public final boolean invoke(GLAutoDrawable drawable, boolean wait, List<GLRunnable> newGLRunnables) { + if( null == newGLRunnables || newGLRunnables.size() == 0 || null == drawable || + wait && ( !drawable.isRealized() || null==drawable.getContext() ) ) { + return false; + } + + final int count = newGLRunnables.size(); + GLRunnableTask rTask = null; + Object rTaskLock = new Object(); + Throwable throwable = null; + synchronized(rTaskLock) { + final boolean deferred; + synchronized(glRunnablesLock) { + deferred = isAnimatorAnimatingOnOtherThread(); + if(!deferred) { + wait = false; // don't wait if exec immediatly + } + for(int i=0; i<count-1; i++) { + glRunnables.add( new GLRunnableTask(newGLRunnables.get(i), null, false) ); + } + rTask = new GLRunnableTask(newGLRunnables.get(count-1), + wait ? rTaskLock : null, + wait /* catch Exceptions if waiting for result */); + glRunnables.add(rTask); + } + if( !deferred ) { + drawable.display(); + } else if( wait ) { + try { + rTaskLock.wait(); // free lock, allow execution of rTask + } catch (InterruptedException ie) { + throwable = ie; + } + if(null==throwable) { + throwable = rTask.getThrowable(); + } + if(null!=throwable) { + throw new RuntimeException(throwable); + } + } + } + return true; + } public final void enqueue(GLRunnable glRunnable) { if( null == glRunnable) { |