From 78b4918b207e16b967e8335fb8ec1b31c706c507 Mon Sep 17 00:00:00 2001
From: Sven Gothel
- Since the {@link GLContext} {@link GLContext#makeCurrent makeCurrent}
- implementation is synchronized, i.e. blocks if the context
- is current on another thread, the internal
- {@link GLContext} for the GLAutoDrawable can be used for the event
- based rendering mechanism and by end users directly.
-
- The implementation shall initialize itself as soon as possible,
- which is only possible after the attached {@link com.jogamp.nativewindow.NativeSurface NativeSurface} becomes visible and and is realized.GLAutoDrawable Initialization
-
- The following initialization sequence should be implemented:
-
-
- Note: The last to {@link GLEventListener} actions shall be also performed, when {@link #addGLEventListener(GLEventListener) adding}
- a new one to an already initialized {@link GLAutoDrawable}.
-
- Another implementation detail is the {@link GLDrawable} reconfiguration. One use case is where a window is being
- dragged to another screen with a different pixel configuration, ie {@link GLCapabilities}. The implementation
- shall be able to detect such cases in conjunction with the associated {@link com.jogamp.nativewindow.NativeSurface NativeSurface}.
- For example, AWT's {@link java.awt.Canvas} 's {@link java.awt.Canvas#getGraphicsConfiguration getGraphicsConfiguration()}
- is capable to determine a display device change. This is demonstrated within {@link com.jogamp.opengl.awt.GLCanvas}'s
- and NEWT's AWTCanvas
{@link com.jogamp.opengl.awt.GLCanvas#getGraphicsConfiguration getGraphicsConfiguration()}
- specialization. Another demonstration is NEWT's {@link com.jogamp.nativewindow.NativeWindow NativeWindow}
- implementation on the Windows platform, which utilizes the native platform's MonitorFromWindow(HWND) function.
- All OpenGL resources shall be regenerated, while the drawable's {@link GLCapabilities} has
- to be chosen again. The following protocol shall be satisfied.
-
- Avoiding breakage with older applications and because of the situation
- mentioned above, the boolean
system property jogl.screenchange.action
will control the
- screen change action as follows:
-
- -Djogl.screenchange.action=false Disable the {@link GLDrawable} reconfiguration (the default) - -Djogl.screenchange.action=true Enable the {@link GLDrawable} reconfiguration -- -
this
instance.
- */
- public GLDrawable getDelegatedDrawable();
-
- /**
- * Returns the context associated with this drawable. The returned
- * context will be synchronized.
- * Don't rely on it's identity, the context may change.
- */
- public GLContext getContext();
-
- /**
- * Associate the new context, newtCtx
, to this auto-drawable.
- * - * Remarks: - *
destroyPrevCtx
is true
,
- * otherwise it will be disassociated from this auto-drawable
- * via {@link GLContext#setGLDrawable(GLDrawable, boolean) setGLDrawable(null, true);} including {@link GL#glFinish() glFinish()}.null
for dis-association.
- * @param destroyPrevCtx if true
, destroy the previous context if exists
- * @return the previous GLContext, maybe null
- *
- * @see GLContext#setGLDrawable(GLDrawable, boolean)
- * @see GLContext#setGLReadDrawable(GLDrawable)
- * @see jogamp.opengl.GLDrawableHelper#switchContext(GLDrawable, GLContext, boolean, GLContext, int)
- */
- public GLContext setContext(GLContext newCtx, boolean destroyPrevCtx);
-
- /**
- * Adds the given {@link GLEventListener listener} to the end of this drawable queue.
- * The {@link GLEventListener listeners} are notified of events in the order of the queue.
- * - * The newly added listener's {@link GLEventListener#init(GLAutoDrawable) init(..)} - * method will be called once before any other of it's callback methods. - * See {@link #getGLEventListenerInitState(GLEventListener)} for details. - *
- * @param listener The GLEventListener object to be inserted - */ - public void addGLEventListener(GLEventListener listener); - - /** - * Adds the given {@link GLEventListener listener} at the given index of this drawable queue. - * The {@link GLEventListener listeners} are notified of events in the order of the queue. - *- * The newly added listener's {@link GLEventListener#init(GLAutoDrawable) init(..)} - * method will be called once before any other of it's callback methods. - * See {@link #getGLEventListenerInitState(GLEventListener)} for details. - *
- * @param index Position where the listener will be inserted. - * Should be within (0 <= index && index <= size()). - * An index value of -1 is interpreted as the end of the list, size(). - * @param listener The GLEventListener object to be inserted - * @throws IndexOutOfBoundsException If the index is not within (0 <= index && index <= size()), or -1 - */ - public void addGLEventListener(int index, GLEventListener listener) throws IndexOutOfBoundsException; - - /** - * Returns the number of {@link GLEventListener} of this drawable queue. - * @return The number of GLEventListener objects of this drawable queue. - */ - public int getGLEventListenerCount(); - - /** - * Returns true if all added {@link GLEventListener} are initialized, otherwise false. - * @since 2.2 - */ - boolean areAllGLEventListenerInitialized(); - - /** - * Returns the {@link GLEventListener} at the given index of this drawable queue. - * @param index Position of the listener to be returned. - * Should be within (0 <= index && index < size()). - * An index value of -1 is interpreted as last listener, size()-1. - * @return The GLEventListener object at the given index. - * @throws IndexOutOfBoundsException If the index is not within (0 <= index && index < size()), or -1 - */ - public GLEventListener getGLEventListener(int index) throws IndexOutOfBoundsException; - - /** - * Retrieves whether the given {@link GLEventListener listener} is initialized or not. - *- * After {@link #addGLEventListener(GLEventListener) adding} a {@link GLEventListener} it is - * marked uninitialized and added to a list of to be initialized {@link GLEventListener}. - * If such uninitialized {@link GLEventListener}'s handler methods (reshape, display) - * are about to be invoked, it's {@link GLEventListener#init(GLAutoDrawable) init(..)} method is invoked first. - * Afterwards the {@link GLEventListener} is marked initialized - * and removed from the list of to be initialized {@link GLEventListener}. - *
- *
- * This methods returns the {@link GLEventListener} initialized state,
- * i.e. returns false
if it is included in the list of to be initialized {@link GLEventListener},
- * otherwise true
.
- *
- * This methods allows manually setting the {@link GLEventListener} initialized state, - * i.e. adding it to, or removing it from the list of to be initialized {@link GLEventListener}. - * See {@link #getGLEventListenerInitState(GLEventListener)} for details. - *
- *- * Warning: This method does not validate whether the given {@link GLEventListener listener's} - * is member of this drawable queue, i.e. {@link #addGLEventListener(GLEventListener) added}. - *
- *- * This method is only exposed to allow users full control over the {@link GLEventListener}'s state - * and is usually not recommended to change. - *
- *- * One use case is moving a {@link GLContext} and their initialized {@link GLEventListener} - * from one {@link GLAutoDrawable} to another, - * where a subsequent {@link GLEventListener#init(GLAutoDrawable) init(..)} call after adding it - * to the new owner is neither required nor desired. - * See {@link com.jogamp.opengl.util.GLDrawableUtil#swapGLContextAndAllGLEventListener(GLAutoDrawable, GLAutoDrawable) swapGLContextAndAllGLEventListener(..)}. - *
- * @param listener the GLEventListener object to perform a state change. - * @param initialized iftrue
, mark the listener initialized, otherwise uninitialized.
- */
- public void setGLEventListenerInitState(GLEventListener listener, boolean initialized);
-
- /**
- * Disposes the given {@link GLEventListener listener} via {@link GLEventListener#dispose(GLAutoDrawable) dispose(..)}
- * if it has been initialized and added to this queue.
- *
- * If remove
is true
, the {@link GLEventListener} is removed from this drawable queue before disposal,
- * otherwise marked uninitialized.
- *
- * If an {@link GLAnimatorControl} is being attached and the current thread is different - * than {@link GLAnimatorControl#getThread() the animator's thread}, it is paused during the operation. - *
- *- * Note that this is an expensive operation, since {@link GLEventListener#dispose(GLAutoDrawable) dispose(..)} - * is decorated by {@link GLContext#makeCurrent()} and {@link GLContext#release()}. - *
- *- * Use {@link #removeGLEventListener(GLEventListener) removeGLEventListener(listener)} instead - * if you just want to remove the {@link GLEventListener listener} and don't care about the disposal of the it's (OpenGL) resources. - *
- *- * Also note that this is done from within a particular drawable's - * {@link GLEventListener} handler (reshape, display, etc.), that it is not - * guaranteed that all other listeners will be evaluated properly - * during this update cycle. - *
- * @param listener The GLEventListener object to be disposed and removed ifremove
is true
- * @param remove pass true
to have the listener
removed from this drawable queue, otherwise pass false
- * @return the disposed and/or removed GLEventListener, or null if no action was performed, i.e. listener was not added
- */
- public GLEventListener disposeGLEventListener(GLEventListener listener, boolean remove);
-
- /**
- * Removes the given {@link GLEventListener listener} from this drawable queue.
- * - * This is an inexpensive operation, since the removed listener's - * {@link GLEventListener#dispose(GLAutoDrawable) dispose(..)} method will not be called. - *
- *- * Use {@link #disposeGLEventListener(GLEventListener, boolean) disposeGLEventListener(listener, true)} - * instead to ensure disposal of the {@link GLEventListener listener}'s (OpenGL) resources. - *
- *- * Note that if this is done from within a particular drawable's - * {@link GLEventListener} handler (reshape, display, etc.), that it is not - * guaranteed that all other listeners will be evaluated properly - * during this update cycle. - *
- * @param listener The GLEventListener object to be removed - * @return the removed GLEventListener, or null if listener was not added - */ - public GLEventListener removeGLEventListener(GLEventListener listener); - - /** - * Registers the usage of an animator, an {@link com.jogamp.opengl.GLAnimatorControl} implementation. - * The animator will be queried whether it's animating, ie periodically issuing {@link #display()} calls or not. - *
- * This method shall be called by an animator implementation only,
- * e.g. {@link com.jogamp.opengl.util.Animator#add(com.jogamp.opengl.GLAutoDrawable)}, passing it's control implementation,
- * and {@link com.jogamp.opengl.util.Animator#remove(com.jogamp.opengl.GLAutoDrawable)}, passing null
.
- *
- * Impacts {@link #display()} and {@link #invoke(boolean, GLRunnable)} semantics.
null
reference indicates no animator is using
- * this GLAutoDrawable
,GLAutoDrawable
.
- *
- * @throws GLException if an animator is already registered.
- * @see #display()
- * @see #invoke(boolean, GLRunnable)
- * @see com.jogamp.opengl.GLAnimatorControl
- */
- public abstract void setAnimator(GLAnimatorControl animatorControl) throws GLException;
-
- /**
- * @return the registered {@link com.jogamp.opengl.GLAnimatorControl} implementation, using this GLAutoDrawable
.
- *
- * @see #setAnimator(com.jogamp.opengl.GLAnimatorControl)
- * @see com.jogamp.opengl.GLAnimatorControl
- */
- public GLAnimatorControl getAnimator();
-
- /**
- * Dedicates this instance's {@link GLContext} to the given thread.setExclusiveContextThread(null)
has been called.
- *
- * Default non-exclusive behavior is requested via setExclusiveContextThread(null)
,
- * which will cause the next call of {@link #display()} on the exclusive thread to
- * release the {@link GLContext}. Only after it's async release, {@link #getExclusiveContextThread()}
- * will return null
.
- *
- * To release a previous made exclusive thread, a user issues setExclusiveContextThread(null)
- * and may poll {@link #getExclusiveContextThread()} until it returns null
,
- * while the exclusive thread is still running.
- *
- * Note: Setting a new exclusive thread without properly releasing a previous one - * will throw an GLException. - *
- *- * Note: Utilizing this feature w/ AWT could lead to an AWT-EDT deadlock, depending on the AWT implementation. - * Hence it is advised not to use it with native AWT GLAutoDrawable like GLCanvas. - *
- *- * One scenario could be to dedicate the context to the {@link GLAnimatorControl#getThread() animator thread} - * and spare redundant context switches, see {@link com.jogamp.opengl.util.AnimatorBase#setExclusiveContext(boolean)}. - *
- * @param t the exclusive thread to claim the context, ornull
for default operation.
- * @return previous exclusive context thread
- * @throws GLException If an exclusive thread is still active but a new one is attempted to be set
- * @see com.jogamp.opengl.util.AnimatorBase#setExclusiveContext(boolean)
- */
- public Thread setExclusiveContextThread(Thread t) throws GLException;
-
- /**
- * @see #setExclusiveContextThread(Thread)
- */
- public Thread getExclusiveContextThread();
-
- /**
- * 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 have been called.
- *
- * If no {@link GLAnimatorControl} is animating (default),
- * or if the current thread is the animator thread,
- * a {@link #display()} call is issued after enqueue the GLRunnable
,
- * hence the {@link GLRunnable} will be executed right away.
- *
- * If an {@link GLAnimatorControl animator} is running,
- * no explicit {@link #display()} call is issued, allowing the {@link GLAnimatorControl animator} to perform at due time.
- *
- * If wait
is true
the call blocks until the glRunnable
- * has been executed by the {@link GLAnimatorControl animator}, otherwise the method returns immediately.
- *
- * If wait
is true
and
- * {@link #isRealized()} returns false
or {@link #getContext()} returns null
,
- * the call is ignored and returns false
.
- * This helps avoiding deadlocking the caller.
- *
- * The internal queue of {@link GLRunnable}'s is being flushed with {@link #destroy()} - * where all blocked callers are being notified. - *
- *
- * To avoid a deadlock situation which causes an {@link IllegalStateException} one should
- * avoid issuing {@link #invoke(boolean, GLRunnable) invoke} while this GLAutoDrawable is being locked.
- * Detected deadlock situations throwing an {@link IllegalStateException} are:
- *
true
block until execution of glRunnable
is finished, otherwise return immediately w/o waiting
- * @param glRunnable the {@link GLRunnable} to execute within {@link #display()}
- * @return true
if the {@link GLRunnable} has been processed or queued, otherwise false
.
- * @throws IllegalStateException in case of a detected deadlock situation ahead, see above.
- *
- * @see #setAnimator(GLAnimatorControl)
- * @see #display()
- * @see GLRunnable
- * @see #invoke(boolean, List)
- * @see #flushGLRunnables()
- */
- public boolean invoke(boolean wait, GLRunnable glRunnable) throws IllegalStateException ;
-
- /**
- * Extends {@link #invoke(boolean, GLRunnable)} functionality
- * allowing to inject a list of {@link GLRunnable}s.
- * @param wait if true
block until execution of the last glRunnable
is finished, otherwise return immediately w/o waiting
- * @param glRunnables the {@link GLRunnable}s to execute within {@link #display()}
- * @return true
if the {@link GLRunnable}s has been processed or queued, otherwise false
.
- * @throws IllegalStateException in case of a detected deadlock situation ahead, see {@link #invoke(boolean, GLRunnable)}.
- * @see #invoke(boolean, GLRunnable)
- * @see #flushGLRunnables()
- */
- public boolean invoke(boolean wait, List- * The executor which might have been blocked until notified - * will be unblocked and all tasks removed from the queue. - *
- * @see #invoke(boolean, GLRunnable) - * @since 2.2 - */ - public void flushGLRunnables(); - - /** Destroys all resources associated with this GLAutoDrawable, - inclusive the GLContext. - If a window is attached to it's implementation, it shall be closed. - Causes disposing of all OpenGL resources - by calling {@link GLEventListener#dispose dispose(..)} for all - registered {@link GLEventListener}s. Called automatically by the - window system toolkit upon receiving a destroy notification. This - routine may be called manually. */ - public void destroy(); - - /** - *- * Causes OpenGL rendering to be performed for this GLAutoDrawable - * in the following order: - *
- * May be called periodically by a running {@link com.jogamp.opengl.GLAnimatorControl} implementation,
- * which must register itself with {@link #setAnimator(com.jogamp.opengl.GLAnimatorControl)}.
- * Called automatically by the window system toolkit upon receiving a repaint() request,
- * except an {@link com.jogamp.opengl.GLAnimatorControl} implementation {@link com.jogamp.opengl.GLAnimatorControl#isAnimating()}.
- * This routine may also 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(com.jogamp.opengl.GLAnimatorControl) - */ - public void display(); - - /** Enables or disables automatic buffer swapping for this drawable. - By default this property is set to true; when true, after all - GLEventListeners have been called for a display() event, the - front and back buffers are swapped, displaying the results of - the render. When disabled, the user is responsible for calling - {@link #swapBuffers(..)} manually. */ - public void setAutoSwapBufferMode(boolean enable); - - /** Indicates whether automatic buffer swapping is enabled for this - drawable. See {@link #setAutoSwapBufferMode}. */ - public boolean getAutoSwapBufferMode(); - - /** - * @param flags Additional context creation flags. - * - * @see GLContext#setContextCreationFlags(int) - * @see GLContext#enableGLDebugMessage(boolean) - */ - public void setContextCreationFlags(int flags); - - /** - * @return Additional context creation flags - */ - public int getContextCreationFlags(); - - /** - * {@inheritDoc} - *- * This GLAutoDrawable implementation holds it's own GLContext reference, - * thus created a GLContext using this methods won't replace it implicitly. - * To replace or set this GLAutoDrawable's GLContext you need to call {@link #setContext(GLContext, boolean)}. - *
- *- * The GLAutoDrawable implementation shall also set the - * context creation flags as customized w/ {@link #setContextCreationFlags(int)}. - *
- */ - @Override - public GLContext createContext(GLContext shareWith); - - /** Returns the {@link GL} pipeline object this GLAutoDrawable uses. - If this method is called outside of the {@link - GLEventListener}'s callback methods (init, display, etc.) it may - return null. Users should not rely on the identity of the - returned GL object; for example, users should not maintain a - hash table with the GL object as the key. Additionally, the GL - object should not be cached in client code, but should be - re-fetched from the GLAutoDrawable at the beginning of each call - to init, display, etc. */ - public GL getGL(); - - /** Sets the {@link GL} pipeline object this GLAutoDrawable uses. - This should only be called from within the GLEventListener's - callback methods, and usually only from within the init() - method, in order to install a composable pipeline. See the JOGL - demos for examples. - @return the set GL pipeline or null if not successful */ - public GL setGL(GL gl); - - /** - * Method may return the upstream UI toolkit object - * holding this {@link GLAutoDrawable} instance, if exist. - *- * Currently known Java UI toolkits and it's known return types are: - * - *
Toolkit | GLAutoDrawable Implementation | ~ | Return Type of getUpstreamWidget() | - *
NEWT | {@link com.jogamp.newt.opengl.GLWindow} | has a | {@link com.jogamp.newt.Window} | - *
SWT | {@link com.jogamp.opengl.swt.GLCanvas} | is a | {@link org.eclipse.swt.widgets.Canvas} | - *
AWT | {@link com.jogamp.opengl.awt.GLCanvas} | is a | {@link java.awt.Canvas} | - *
AWT | {@link com.jogamp.opengl.awt.GLJPanel} | is a | {@link javax.swing.JPanel} | - *
- * This method may also return null
if no UI toolkit is being used,
- * as common for offscreen rendering.
- *
- * See GLAutoDrawable Locking. - *
- * @since 2.2 - */ - public RecursiveLock getUpstreamLock(); - - /** - * Indicates whether the current thread is capable of - * performing OpenGL-related work. - *- * Implementation utilizes this knowledge to determine - * whether {@link #display()} performs the OpenGL commands on the current thread directly - * or spawns them on the dedicated OpenGL thread. - *
- * @since 2.2 - */ - public boolean isThreadGLCapable(); - -} -- cgit v1.2.3