From 969e427642d3b9be376cefaada9febd489b7b3d7 Mon Sep 17 00:00:00 2001
From: Sven Gothel
+ * Indicates whether a running animator thread is periodically issuing {@link #display()} calls or not.
+ * This method shall be called by an animator implementation only,
+ * Impacts {@link #display()} and {@link #invoke(boolean, GLRunnable)} semantics.
- * Warning: We cannot verify if the caller runs in the same thread
- * as the display caller, hence we cannot avoid a deadlock
- * in such case. You have to know what you are doing,
- * ie call this only in a I/O event listener, or such.
+ *
+ * e.g. {@link com.jogamp.opengl.util.Animator#start()}, passing the animator thread,
+ * and {@link com.jogamp.opengl.util.Animator#start()}, passing null
.
+ *
+ *
+ * @param animator null
reference indicates no running animator thread
+ * issues {@link #display()} calls on this GLAutoDrawable
,
+ * a valid reference indicates a running animator thread
+ * periodically issuing {@link #display()} calls.
+ *
+ * @throws GLException if a running animator thread is already registered and you try to register a different one without unregistering the previous one.
+ * @see #display()
+ * @see #invoke(boolean, GLRunnable)
+ */
+ public void setAnimator(Thread animator) throws GLException;
+
+ /**
+ * @return the value of the registered animator thread
+ *
+ * @see #setAnimator(Thread)
+ */
+ public Thread getAnimator();
+
/**
- * Enqueues the one-shot {@link javax.media.opengl.GLRunnable} into the queue,
- * which will be executed at the next {@link #display()} call.
*
+ * If {@link #setAnimator(Thread)} has not registered no running animator thread, the default,
+ * or if the current thread is the animator thread,
+ * a {@link #display()} call has to be issued after enqueueing the GLRunnable
.
+ * No extra synchronization must be performed in case wait
is true, since it is executed in the current thread.
+ * If {@link #setAnimator(Thread)} has registered a valid animator thread,
+ * no call of {@link #display()} must be issued, since the animator thread performs it.
+ * If wait
is true, the implementation must wait until the GLRunnable
is excecuted.
Causes OpenGL rendering to be performed for this GLAutoDrawable - in the following order: -
- Called automatically by the - window system toolkit upon receiving a repaint() request.
-- This routine may be called manually for better control over the - rendering process. It is legal to call another GLAutoDrawable's - display method from within the {@link GLEventListener#display - display(..)} callback.
-- In case of a new generated OpenGL context, - the implementation shall call {@link GLEventListener#init init(..)} for all - registered {@link GLEventListener}s before making the - actual {@link GLEventListener#display display(..)} calls, - in case this has not been done yet.
*/ + /** + *+ * Causes OpenGL rendering to be performed for this GLAutoDrawable + * in the following order: + *
+ * Called automatically by the + * window system toolkit upon receiving a repaint() request, + * except a running animator thread is registered with {@link #setAnimator(Thread)}.
+ * Maybe called periodically by a running animator thread,
+ * which must register itself with {@link #setAnimator(Thread)}.
+ * This routine may be called manually for better control over the + * rendering process. It is legal to call another GLAutoDrawable's + * display method from within the {@link GLEventListener#display + * display(..)} callback.
+ *+ * In case of a new generated OpenGL context, + * the implementation shall call {@link GLEventListener#init init(..)} for all + * registered {@link GLEventListener}s before making the + * actual {@link GLEventListener#display display(..)} calls, + * in case this has not been done yet.
+ * + * @see #setAnimator(Thread) + */ public void display(); /** Enables or disables automatic buffer swapping for this drawable. diff --git a/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java b/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java index 2dafd691a..f150b2507 100644 --- a/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java +++ b/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java @@ -378,7 +378,9 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable { return; } - display(); + if( null == getAnimator() ) { + display(); + } } /** Overridden to track when this component is added to a container. @@ -492,8 +494,16 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable { drawableHelper.removeGLEventListener(listener); } + public void setAnimator(Thread animator) { + drawableHelper.setAnimator(animator); + } + + public Thread getAnimator() { + return drawableHelper.getAnimator(); + } + public void invoke(boolean wait, GLRunnable glRunnable) { - drawableHelper.invoke(wait, glRunnable); + drawableHelper.invoke(this, wait, glRunnable); } public void setContext(GLContext ctx) { @@ -640,10 +650,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable { if (sendReshape) { // Note: we ignore the given x and y within the parent component // since we are drawing directly into this heavyweight component. - int width = getWidth(); - int height = getHeight(); - getGL().glViewport(0, 0, width, height); - drawableHelper.reshape(GLCanvas.this, 0, 0, width, height); + drawableHelper.reshape(GLCanvas.this, 0, 0, getWidth(), getHeight()); sendReshape = false; } diff --git a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java index 73962e979..d0d97fe31 100644 --- a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java +++ b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java @@ -380,8 +380,16 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable { drawableHelper.removeGLEventListener(listener); } + public void setAnimator(Thread animator) { + drawableHelper.setAnimator(animator); + } + + public Thread getAnimator() { + return drawableHelper.getAnimator(); + } + public void invoke(boolean wait, GLRunnable glRunnable) { - drawableHelper.invoke(wait, glRunnable); + drawableHelper.invoke(this, wait, glRunnable); } public GLContext createContext(GLContext shareWith) { @@ -585,9 +593,8 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable { } if (sendReshape) { if (DEBUG||VERBOSE) { - System.err.println("display: glViewport(" + viewportX + "," + viewportY + " " + panelWidth + "x" + panelHeight + ")"); + System.err.println("display: reshape(" + viewportX + "," + viewportY + " " + panelWidth + "x" + panelHeight + ")"); } - getGL().getGL2().glViewport(viewportX, viewportY, panelWidth, panelHeight); drawableHelper.reshape(GLJPanel.this, viewportX, viewportY, panelWidth, panelHeight); sendReshape = false; } -- cgit v1.2.3